from inspect import getdoc
from joy.joy import run
+from joy.library import HELP_TEMPLATE
from joy.parser import Symbol
from joy.utils.stack import stack_to_string
from joy.utils.types import type_check
def do_opendoc(self, name):
if is_numerical(name):
- print('The number', name)
+ doc = 'The number ' + str(name)
else:
try:
word = self.dictionary[name]
except KeyError:
- print(repr(name), '???')
+ doc = 'Unknown: ' + repr(name)
else:
- print(getdoc(word))
+ doc = getdoc(word)
+ print(HELP_TEMPLATE % (name, doc, name))
self.print_stack()
def pop(self):
)
+HELP_TEMPLATE = '''\
+
+==== Help on %s ====
+
+%s
+
+---- end (%s)
+'''
+
+
_SYM_NUMS = lambda c=count(): next(c)
_COMB_NUMS = lambda c=count(): next(c)
'''Accepts a quoted symbol on the top of the stack and prints its docs.'''
((symbol, _), stack) = S
word = dictionary[symbol]
- print(getdoc(word))
+ print(HELP_TEMPLATE % (symbol, getdoc(word), symbol))
return stack, expression, dictionary