},
"outputs": [],
"source": [
- "define('gsra == 1 swap [over / + 2 /] cons [dup] swoncat make_generator')"
+ "define('gsra 1 swap [over / + 2 /] cons [dup] swoncat make_generator')"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "define('_within_P == [first - abs] dip <=')"
+ "define('_within_P [first - abs] dip <=')"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "define('_within_B == roll< popop first')"
+ "define('_within_B roll< popop first')"
]
},
{
"\n",
"1. Discard a.\n",
"2. Use `x` combinator to generate next term from `G`.\n",
- "3. Run `within` with `i` (it is a `primrec` function.)\n",
+ "3. Run `within` with `i` (it is a \"tail-recursive\" function.)\n",
"\n",
"Pretty straightforward:\n",
"\n",
"metadata": {},
"outputs": [],
"source": [
- "define('_within_R == [popd x] dip')"
+ "define('_within_R [popd x] dip')"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "define('within == x 0.000000001 [_within_P] [_within_B] [_within_R] primrec')\n",
- "define('sqrt == gsra within')"
+ "define('within x 0.000000001 [_within_P] [_within_B] [_within_R] tailrec')\n",
+ "define('sqrt gsra within')"
]
},
{
"language_info": {
"codemirror_mode": {
"name": "ipython",
- "version": 2
+ "version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.12"
+ "pygments_lexer": "ipython3",
+ "version": "3.8.3"
}
},
"nbformat": 4,
def J(text, stack=S, dictionary=D):
- print stack_to_string(run(text, stack, dictionary)[0])
+ print(stack_to_string(run(text, stack, dictionary)[0]))
def V(text, stack=S, dictionary=D):
except:
exc = format_exc()
tp.print_()
- print '-' * 73
- print exc
+ print('-' * 73)
+ print(exc)
else:
tp.print_()
'''
from __future__ import print_function
from builtins import input
-from traceback import print_exc, format_exc
+from traceback import print_exc
from .parser import text_to_expression, ParseError, Symbol
from .utils.stack import stack_to_string
try:
stack, _, dictionary = run(text, stack, dictionary)
except:
- exc = format_exc() # Capture the exception.
- print(exc) # Print the original exception.
+ print_exc()
except:
print_exc()
print()
'''
Pretty printing support, e.g.::
- Joy? 23 18 * 99 +
- . 23 18 mul 99 add
- 23 . 18 mul 99 add
- 23 18 . mul 99 add
- 414 . 99 add
- 414 99 . add
- 513 .
+ Joy? [23 18 * 99 +] trace
+ • 23 18 mul 99 add
+ 23 • 18 mul 99 add
+ 23 18 • mul 99 add
+ 414 • 99 add
+ 414 99 • add
+ 513 •
513 <-top
joy?
-On each line the stack is printed with the top to the right, then a ``.`` to
-represent the current locus of processing, then the pending expression to the
-left.
-
+On each line the stack is printed with the top to the left, then a
+bullet symbol,``•``, to represent the current locus of processing, then
+the pending expression to the right.
'''
# (Kinda clunky and hacky. This should be swapped out in favor of much
# smarter stuff.)
n = len(stack)
if n > max_stack_length:
max_stack_length = n
- lines.append((n, '%s . %s' % (stack, expression)))
- return [ # Prefix spaces to line up '.'s.
+ lines.append((n, '%s • %s' % (stack, expression)))
+ return [ # Prefix spaces to line up '•'s.
(' ' * (max_stack_length - length) + line)
for length, line in lines
]