Minor cleanup.

This commit is contained in:
Simon Forman 2020-05-20 15:34:30 -07:00
parent f9ac667cc5
commit ba0c24c39b
4 changed files with 27 additions and 29 deletions

View File

@ -92,7 +92,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"define('gsra == 1 swap [over / + 2 /] cons [dup] swoncat make_generator')" "define('gsra 1 swap [over / + 2 /] cons [dup] swoncat make_generator')"
] ]
}, },
{ {
@ -182,7 +182,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"define('_within_P == [first - abs] dip <=')" "define('_within_P [first - abs] dip <=')"
] ]
}, },
{ {
@ -203,7 +203,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"define('_within_B == roll< popop first')" "define('_within_B roll< popop first')"
] ]
}, },
{ {
@ -216,7 +216,7 @@
"\n", "\n",
"1. Discard a.\n", "1. Discard a.\n",
"2. Use `x` combinator to generate next term from `G`.\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", "\n",
"Pretty straightforward:\n", "Pretty straightforward:\n",
"\n", "\n",
@ -236,7 +236,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"define('_within_R == [popd x] dip')" "define('_within_R [popd x] dip')"
] ]
}, },
{ {
@ -257,8 +257,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"define('within == x 0.000000001 [_within_P] [_within_B] [_within_R] primrec')\n", "define('within x 0.000000001 [_within_P] [_within_B] [_within_R] tailrec')\n",
"define('sqrt == gsra within')" "define('sqrt gsra within')"
] ]
}, },
{ {
@ -367,14 +367,14 @@
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.12" "version": "3.8.3"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -29,7 +29,7 @@ S = ()
def J(text, stack=S, dictionary=D): 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): def V(text, stack=S, dictionary=D):
@ -39,8 +39,8 @@ def V(text, stack=S, dictionary=D):
except: except:
exc = format_exc() exc = format_exc()
tp.print_() tp.print_()
print '-' * 73 print('-' * 73)
print exc print(exc)
else: else:
tp.print_() tp.print_()

View File

@ -25,7 +25,7 @@ match the behaviour of the original version(s) written in C.
''' '''
from __future__ import print_function from __future__ import print_function
from builtins import input 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 .parser import text_to_expression, ParseError, Symbol
from .utils.stack import stack_to_string from .utils.stack import stack_to_string
@ -103,8 +103,7 @@ def repl(stack=(), dictionary=None):
try: try:
stack, _, dictionary = run(text, stack, dictionary) stack, _, dictionary = run(text, stack, dictionary)
except: except:
exc = format_exc() # Capture the exception. print_exc()
print(exc) # Print the original exception.
except: except:
print_exc() print_exc()
print() print()

View File

@ -20,22 +20,21 @@
''' '''
Pretty printing support, e.g.:: Pretty printing support, e.g.::
Joy? 23 18 * 99 + Joy? [23 18 * 99 +] trace
. 23 18 mul 99 add 23 18 mul 99 add
23 . 18 mul 99 add 23 18 mul 99 add
23 18 . mul 99 add 23 18 mul 99 add
414 . 99 add 414 99 add
414 99 . add 414 99 add
513 . 513
513 <-top 513 <-top
joy? joy?
On each line the stack is printed with the top to the right, then a ``.`` to On each line the stack is printed with the top to the left, then a
represent the current locus of processing, then the pending expression to the bullet symbol,````, to represent the current locus of processing, then
left. the pending expression to the right.
''' '''
# (Kinda clunky and hacky. This should be swapped out in favor of much # (Kinda clunky and hacky. This should be swapped out in favor of much
# smarter stuff.) # smarter stuff.)
@ -114,8 +113,8 @@ class TracePrinter(object):
n = len(stack) n = len(stack)
if n > max_stack_length: if n > max_stack_length:
max_stack_length = n max_stack_length = n
lines.append((n, '%s . %s' % (stack, expression))) lines.append((n, '%s %s' % (stack, expression)))
return [ # Prefix spaces to line up '.'s. return [ # Prefix spaces to line up ''s.
(' ' * (max_stack_length - length) + line) (' ' * (max_stack_length - length) + line)
for length, line in lines for length, line in lines
] ]