This repo is not current. Development has moved from Hg to Git. For the latest code use the "Source Code" tab above to go to the "Thun" git repo or navigate to:
https://osdn.net/projects/joypy/scm/git/Thun
リビジョン | 4425760ad7e8ed03c50a51bc528e8c8249a2d4c3 (tree) |
---|---|
日時 | 2020-05-21 07:34:30 |
作者 | Simon Forman <sforman@hush...> |
コミッター | Simon Forman |
Minor cleanup.
@@ -92,7 +92,7 @@ | ||
92 | 92 | }, |
93 | 93 | "outputs": [], |
94 | 94 | "source": [ |
95 | - "define('gsra == 1 swap [over / + 2 /] cons [dup] swoncat make_generator')" | |
95 | + "define('gsra 1 swap [over / + 2 /] cons [dup] swoncat make_generator')" | |
96 | 96 | ] |
97 | 97 | }, |
98 | 98 | { |
@@ -182,7 +182,7 @@ | ||
182 | 182 | "metadata": {}, |
183 | 183 | "outputs": [], |
184 | 184 | "source": [ |
185 | - "define('_within_P == [first - abs] dip <=')" | |
185 | + "define('_within_P [first - abs] dip <=')" | |
186 | 186 | ] |
187 | 187 | }, |
188 | 188 | { |
@@ -203,7 +203,7 @@ | ||
203 | 203 | "metadata": {}, |
204 | 204 | "outputs": [], |
205 | 205 | "source": [ |
206 | - "define('_within_B == roll< popop first')" | |
206 | + "define('_within_B roll< popop first')" | |
207 | 207 | ] |
208 | 208 | }, |
209 | 209 | { |
@@ -216,7 +216,7 @@ | ||
216 | 216 | "\n", |
217 | 217 | "1. Discard a.\n", |
218 | 218 | "2. Use `x` combinator to generate next term from `G`.\n", |
219 | - "3. Run `within` with `i` (it is a `primrec` function.)\n", | |
219 | + "3. Run `within` with `i` (it is a \"tail-recursive\" function.)\n", | |
220 | 220 | "\n", |
221 | 221 | "Pretty straightforward:\n", |
222 | 222 | "\n", |
@@ -236,7 +236,7 @@ | ||
236 | 236 | "metadata": {}, |
237 | 237 | "outputs": [], |
238 | 238 | "source": [ |
239 | - "define('_within_R == [popd x] dip')" | |
239 | + "define('_within_R [popd x] dip')" | |
240 | 240 | ] |
241 | 241 | }, |
242 | 242 | { |
@@ -257,8 +257,8 @@ | ||
257 | 257 | "metadata": {}, |
258 | 258 | "outputs": [], |
259 | 259 | "source": [ |
260 | - "define('within == x 0.000000001 [_within_P] [_within_B] [_within_R] primrec')\n", | |
261 | - "define('sqrt == gsra within')" | |
260 | + "define('within x 0.000000001 [_within_P] [_within_B] [_within_R] tailrec')\n", | |
261 | + "define('sqrt gsra within')" | |
262 | 262 | ] |
263 | 263 | }, |
264 | 264 | { |
@@ -367,14 +367,14 @@ | ||
367 | 367 | "language_info": { |
368 | 368 | "codemirror_mode": { |
369 | 369 | "name": "ipython", |
370 | - "version": 2 | |
370 | + "version": 3 | |
371 | 371 | }, |
372 | 372 | "file_extension": ".py", |
373 | 373 | "mimetype": "text/x-python", |
374 | 374 | "name": "python", |
375 | 375 | "nbconvert_exporter": "python", |
376 | - "pygments_lexer": "ipython2", | |
377 | - "version": "2.7.12" | |
376 | + "pygments_lexer": "ipython3", | |
377 | + "version": "3.8.3" | |
378 | 378 | } |
379 | 379 | }, |
380 | 380 | "nbformat": 4, |
@@ -29,7 +29,7 @@ | ||
29 | 29 | |
30 | 30 | |
31 | 31 | def J(text, stack=S, dictionary=D): |
32 | - print stack_to_string(run(text, stack, dictionary)[0]) | |
32 | + print(stack_to_string(run(text, stack, dictionary)[0])) | |
33 | 33 | |
34 | 34 | |
35 | 35 | def V(text, stack=S, dictionary=D): |
@@ -39,8 +39,8 @@ | ||
39 | 39 | except: |
40 | 40 | exc = format_exc() |
41 | 41 | tp.print_() |
42 | - print '-' * 73 | |
43 | - print exc | |
42 | + print('-' * 73) | |
43 | + print(exc) | |
44 | 44 | else: |
45 | 45 | tp.print_() |
46 | 46 |
@@ -25,7 +25,7 @@ | ||
25 | 25 | ''' |
26 | 26 | from __future__ import print_function |
27 | 27 | from builtins import input |
28 | -from traceback import print_exc, format_exc | |
28 | +from traceback import print_exc | |
29 | 29 | from .parser import text_to_expression, ParseError, Symbol |
30 | 30 | from .utils.stack import stack_to_string |
31 | 31 |
@@ -103,8 +103,7 @@ | ||
103 | 103 | try: |
104 | 104 | stack, _, dictionary = run(text, stack, dictionary) |
105 | 105 | except: |
106 | - exc = format_exc() # Capture the exception. | |
107 | - print(exc) # Print the original exception. | |
106 | + print_exc() | |
108 | 107 | except: |
109 | 108 | print_exc() |
110 | 109 | print() |
@@ -20,22 +20,21 @@ | ||
20 | 20 | ''' |
21 | 21 | Pretty printing support, e.g.:: |
22 | 22 | |
23 | - Joy? 23 18 * 99 + | |
24 | - . 23 18 mul 99 add | |
25 | - 23 . 18 mul 99 add | |
26 | - 23 18 . mul 99 add | |
27 | - 414 . 99 add | |
28 | - 414 99 . add | |
29 | - 513 . | |
23 | + Joy? [23 18 * 99 +] trace | |
24 | + • 23 18 mul 99 add | |
25 | + 23 • 18 mul 99 add | |
26 | + 23 18 • mul 99 add | |
27 | + 414 • 99 add | |
28 | + 414 99 • add | |
29 | + 513 • | |
30 | 30 | |
31 | 31 | 513 <-top |
32 | 32 | |
33 | 33 | joy? |
34 | 34 | |
35 | -On each line the stack is printed with the top to the right, then a ``.`` to | |
36 | -represent the current locus of processing, then the pending expression to the | |
37 | -left. | |
38 | - | |
35 | +On each line the stack is printed with the top to the left, then a | |
36 | +bullet symbol,``•``, to represent the current locus of processing, then | |
37 | +the pending expression to the right. | |
39 | 38 | ''' |
40 | 39 | # (Kinda clunky and hacky. This should be swapped out in favor of much |
41 | 40 | # smarter stuff.) |
@@ -114,8 +113,8 @@ | ||
114 | 113 | n = len(stack) |
115 | 114 | if n > max_stack_length: |
116 | 115 | max_stack_length = n |
117 | - lines.append((n, '%s . %s' % (stack, expression))) | |
118 | - return [ # Prefix spaces to line up '.'s. | |
116 | + lines.append((n, '%s • %s' % (stack, expression))) | |
117 | + return [ # Prefix spaces to line up '•'s. | |
119 | 118 | (' ' * (max_stack_length - length) + line) |
120 | 119 | for length, line in lines |
121 | 120 | ] |