Interpreter and library.
Révision | 5d856bf444196b5570b0585108b99e26331dba10 (tree) |
---|---|
l'heure | 2021-11-29 08:03:47 |
Auteur | ![]() |
Commiter | Simon Forman |
I think the real solution is to "not do that" as it were.
Unquoted symbols on the stack are verboten.
@@ -35,7 +35,7 @@ expected_result = '[1 [2 [3 4 625 6] 7] 8]' | ||
35 | 35 | expected_result_as_stack = text_to_expression(expected_result) |
36 | 36 | |
37 | 37 | |
38 | -def test_expr(ds): | |
38 | +def test_expr(ds, e=expression): | |
39 | 39 | ''' |
40 | 40 | Run the test expression with the defs in ds. |
41 | 41 | Return the resulting stack as a string or the |
@@ -44,7 +44,7 @@ def test_expr(ds): | ||
44 | 44 | D = dictionary.copy() |
45 | 45 | D.update(ds) |
46 | 46 | try: |
47 | - stack, _, _ = joy((), expression, D) | |
47 | + stack, _, _ = joy((), e, D) | |
48 | 48 | except Exception as err: |
49 | 49 | return err |
50 | 50 | return stack_to_string(stack) |
@@ -202,9 +202,9 @@ del CD['unit'] | ||
202 | 202 | del CD['unswons'] |
203 | 203 | del CD['x'] |
204 | 204 | |
205 | -print(test_expr(CD)) | |
206 | -for n in sorted(CD): | |
207 | - print(n) | |
205 | +##print(test_expr(CD)) | |
206 | +##for n in sorted(CD): | |
207 | +## print(n) | |
208 | 208 | ## ? |
209 | 209 | ## _step0 |
210 | 210 | ## _step1 |
@@ -217,7 +217,8 @@ for n in sorted(CD): | ||
217 | 217 | ## step |
218 | 218 | ## uncons |
219 | 219 | |
220 | - | |
220 | +expr = text_to_expression('[[dip]] [uncons] trace') | |
221 | +print(test_expr(CD, e=expr)) | |
221 | 222 | |
222 | 223 | |
223 | 224 |
@@ -541,18 +541,52 @@ | ||
541 | 541 | "source": [] |
542 | 542 | }, |
543 | 543 | { |
544 | + "cell_type": "markdown", | |
545 | + "metadata": {}, | |
546 | + "source": [ | |
547 | + "Argh! It is inside `uncons` itself, isn't it!?" | |
548 | + ] | |
549 | + }, | |
550 | + { | |
544 | 551 | "cell_type": "code", |
545 | - "execution_count": null, | |
552 | + "execution_count": 1, | |
546 | 553 | "metadata": {}, |
547 | - "outputs": [], | |
548 | - "source": [] | |
554 | + "outputs": [ | |
555 | + { | |
556 | + "name": "stdout", | |
557 | + "output_type": "stream", | |
558 | + "text": [] | |
559 | + } | |
560 | + ], | |
561 | + "source": [ | |
562 | + "clear" | |
563 | + ] | |
564 | + }, | |
565 | + { | |
566 | + "cell_type": "code", | |
567 | + "execution_count": 2, | |
568 | + "metadata": {}, | |
569 | + "outputs": [ | |
570 | + { | |
571 | + "name": "stdout", | |
572 | + "output_type": "stream", | |
573 | + "text": [ | |
574 | + "[Q] [dip dip infra dip infra dip infra]" | |
575 | + ] | |
576 | + } | |
577 | + ], | |
578 | + "source": [ | |
579 | + "[Q] [dip dip infra dip infra dip infra]" | |
580 | + ] | |
549 | 581 | }, |
550 | 582 | { |
551 | 583 | "cell_type": "code", |
552 | 584 | "execution_count": null, |
553 | 585 | "metadata": {}, |
554 | 586 | "outputs": [], |
555 | - "source": [] | |
587 | + "source": [ | |
588 | + "uncons" | |
589 | + ] | |
556 | 590 | }, |
557 | 591 | { |
558 | 592 | "cell_type": "code", |
@@ -563,6 +597,72 @@ | ||
563 | 597 | }, |
564 | 598 | { |
565 | 599 | "cell_type": "code", |
600 | + "execution_count": 4, | |
601 | + "metadata": {}, | |
602 | + "outputs": [ | |
603 | + { | |
604 | + "name": "stdout", | |
605 | + "output_type": "stream", | |
606 | + "text": [ | |
607 | + "[Q] [dip dip infra dip infra dip infra]" | |
608 | + ] | |
609 | + } | |
610 | + ], | |
611 | + "source": [ | |
612 | + "[popdd roll< pop] inscribe" | |
613 | + ] | |
614 | + }, | |
615 | + { | |
616 | + "cell_type": "code", | |
617 | + "execution_count": 5, | |
618 | + "metadata": {}, | |
619 | + "outputs": [ | |
620 | + { | |
621 | + "name": "stdout", | |
622 | + "output_type": "stream", | |
623 | + "text": [] | |
624 | + } | |
625 | + ], | |
626 | + "source": [ | |
627 | + "clear" | |
628 | + ] | |
629 | + }, | |
630 | + { | |
631 | + "cell_type": "code", | |
632 | + "execution_count": 6, | |
633 | + "metadata": {}, | |
634 | + "outputs": [ | |
635 | + { | |
636 | + "name": "stdout", | |
637 | + "output_type": "stream", | |
638 | + "text": [ | |
639 | + "[Q] [dip dip infra dip infra dip infra]" | |
640 | + ] | |
641 | + } | |
642 | + ], | |
643 | + "source": [ | |
644 | + "[Q] [dip dip infra dip infra dip infra]" | |
645 | + ] | |
646 | + }, | |
647 | + { | |
648 | + "cell_type": "code", | |
649 | + "execution_count": 7, | |
650 | + "metadata": {}, | |
651 | + "outputs": [ | |
652 | + { | |
653 | + "name": "stdout", | |
654 | + "output_type": "stream", | |
655 | + "text": [ | |
656 | + "[Q] dip [dip infra dip infra dip infra]" | |
657 | + ] | |
658 | + } | |
659 | + ], | |
660 | + "source": [ | |
661 | + "uncons" | |
662 | + ] | |
663 | + }, | |
664 | + { | |
665 | + "cell_type": "code", | |
566 | 666 | "execution_count": null, |
567 | 667 | "metadata": {}, |
568 | 668 | "outputs": [], |