shen-ruby 0.12.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +5 -0
  3. data/README.md +8 -12
  4. data/Rakefile +4 -9
  5. data/bin/shen_test_suite.rb +0 -1
  6. data/bin/srrepl +2 -4
  7. data/lib/shen_ruby/shen.rb +98 -0
  8. data/lib/shen_ruby/version.rb +1 -1
  9. data/shen-ruby.gemspec +3 -3
  10. data/shen/README.txt +9 -13
  11. data/shen/release/BSD +24 -0
  12. data/shen/release/klambda/core.kl +157 -0
  13. data/shen/release/klambda/declarations.kl +109 -0
  14. data/shen/release/klambda/load.kl +59 -0
  15. data/shen/release/klambda/macros.kl +91 -0
  16. data/shen/release/klambda/prolog.kl +228 -0
  17. data/shen/release/klambda/reader.kl +198 -0
  18. data/shen/release/klambda/sequent.kl +142 -0
  19. data/shen/release/klambda/sys.kl +253 -0
  20. data/shen/release/klambda/t-star.kl +123 -0
  21. data/shen/release/klambda/toplevel.kl +110 -0
  22. data/shen/release/klambda/track.kl +79 -0
  23. data/shen/release/{k_lambda → klambda}/types.kl +41 -63
  24. data/shen/release/klambda/writer.kl +81 -0
  25. data/shen/release/klambda/yacc.kl +87 -0
  26. data/shen/release/license.pdf +0 -0
  27. data/shen/release/test_programs/Chap13/problems.txt +26 -26
  28. data/shen/release/test_programs/README.shen +52 -52
  29. data/shen/release/test_programs/TinyLispFunctions.txt +15 -15
  30. data/shen/release/test_programs/TinyTypes.shen +55 -55
  31. data/shen/release/test_programs/binary.shen +24 -24
  32. data/shen/release/test_programs/bubble_version_1.shen +28 -28
  33. data/shen/release/test_programs/bubble_version_2.shen +22 -22
  34. data/shen/release/test_programs/calculator.shen +21 -21
  35. data/shen/release/test_programs/cartprod.shen +23 -23
  36. data/shen/release/test_programs/change.shen +25 -25
  37. data/shen/release/test_programs/classes-defaults.shen +94 -94
  38. data/shen/release/test_programs/classes-inheritance.shen +100 -100
  39. data/shen/release/test_programs/classes-typed.shen +74 -74
  40. data/shen/release/test_programs/classes-untyped.shen +46 -46
  41. data/shen/release/test_programs/depth_.shen +14 -14
  42. data/shen/release/test_programs/einstein.shen +34 -34
  43. data/shen/release/test_programs/fruit_machine.shen +46 -46
  44. data/shen/release/test_programs/interpreter.shen +217 -217
  45. data/shen/release/test_programs/metaprog.shen +85 -85
  46. data/shen/release/test_programs/minim.shen +192 -192
  47. data/shen/release/test_programs/mutual.shen +11 -11
  48. data/shen/release/test_programs/n_queens.shen +45 -45
  49. data/shen/release/test_programs/newton_version_1.shen +33 -33
  50. data/shen/release/test_programs/newton_version_2.shen +24 -24
  51. data/shen/release/test_programs/parse.prl +14 -14
  52. data/shen/release/test_programs/parser.shen +51 -51
  53. data/shen/release/test_programs/powerset.shen +10 -10
  54. data/shen/release/test_programs/prime.shen +10 -10
  55. data/shen/release/test_programs/prolog.shen +78 -78
  56. data/shen/release/test_programs/proof_assistant.shen +80 -80
  57. data/shen/release/test_programs/proplog_version_1.shen +25 -25
  58. data/shen/release/test_programs/proplog_version_2.shen +27 -27
  59. data/shen/release/test_programs/qmachine.shen +66 -66
  60. data/shen/release/test_programs/red-black.shen +54 -54
  61. data/shen/release/test_programs/search.shen +55 -55
  62. data/shen/release/test_programs/semantic_net.shen +44 -44
  63. data/shen/release/test_programs/spreadsheet.shen +34 -34
  64. data/shen/release/test_programs/stack.shen +27 -27
  65. data/shen/release/test_programs/streams.shen +20 -20
  66. data/shen/release/test_programs/strings.shen +57 -57
  67. data/shen/release/test_programs/structures-typed.shen +71 -71
  68. data/shen/release/test_programs/structures-untyped.shen +41 -41
  69. data/shen/release/test_programs/tests.shen +232 -232
  70. data/shen/release/test_programs/types.shen +11 -11
  71. data/shen/release/test_programs/whist.shen +239 -239
  72. data/shen/release/test_programs/yacc.shen +132 -132
  73. metadata +21 -35
  74. data/shen/lib/shen_ruby/shen.rb +0 -160
  75. data/shen/license.txt +0 -34
  76. data/shen/release/benchmarks/N_queens.shen +0 -45
  77. data/shen/release/benchmarks/README.shen +0 -14
  78. data/shen/release/benchmarks/benchmarks.shen +0 -52
  79. data/shen/release/benchmarks/bigprog +0 -2173
  80. data/shen/release/benchmarks/einstein.shen +0 -33
  81. data/shen/release/benchmarks/heatwave.gif +0 -0
  82. data/shen/release/benchmarks/interpreter.shen +0 -219
  83. data/shen/release/benchmarks/jnk.shen +0 -194
  84. data/shen/release/benchmarks/picture.jpg +0 -0
  85. data/shen/release/benchmarks/plato.jpg +0 -0
  86. data/shen/release/benchmarks/powerset.shen +0 -10
  87. data/shen/release/benchmarks/prime.shen +0 -10
  88. data/shen/release/benchmarks/short.shen +0 -129
  89. data/shen/release/benchmarks/text.txt +0 -68
  90. data/shen/release/k_lambda/core.kl +0 -181
  91. data/shen/release/k_lambda/declarations.kl +0 -131
  92. data/shen/release/k_lambda/load.kl +0 -84
  93. data/shen/release/k_lambda/macros.kl +0 -112
  94. data/shen/release/k_lambda/prolog.kl +0 -252
  95. data/shen/release/k_lambda/reader.kl +0 -222
  96. data/shen/release/k_lambda/sequent.kl +0 -166
  97. data/shen/release/k_lambda/sys.kl +0 -271
  98. data/shen/release/k_lambda/t-star.kl +0 -139
  99. data/shen/release/k_lambda/toplevel.kl +0 -135
  100. data/shen/release/k_lambda/track.kl +0 -103
  101. data/shen/release/k_lambda/writer.kl +0 -105
  102. data/shen/release/k_lambda/yacc.kl +0 -113
@@ -1,33 +0,0 @@
1
- (defprolog einsteins_riddle
2
- Fish_Owner <-- (einstein Houses Fish_Owner);)
3
-
4
- (defprolog einstein
5
- Houses Fish_Owner <-- (unify Houses [[house norwegian _ _ _ _] _ [house _ _ _ milk _] _ _])
6
- (member [house brit _ _ _ red] Houses)
7
- (member [house swede dog _ _ _] Houses)
8
- (member [house dane _ _ tea _] Houses)
9
- (iright [house _ _ _ _ green] [house _ _ _ _ white] Houses)
10
- (member [house _ _ _ coffee green] Houses)
11
- (member [house _ bird pallmall _ _] Houses)
12
- (member [house _ _ dunhill _ yellow] Houses)
13
- (next_to [house _ _ dunhill _ _] [house _ horse _ _ _] Houses)
14
- (member [house _ _ _ milk _] Houses)
15
- (next_to [house _ _ marlboro _ _] [house _ cat _ _ _] Houses)
16
- (next_to [house _ _ marlboro _ _] [house _ _ _ water _] Houses)
17
- (member [house _ _ winfield beer _] Houses)
18
- (member [house german _ rothmans _ _] Houses)
19
- (next_to [house norwegian _ _ _ _] [house _ _ _ _ blue] Houses)
20
- (unify Houses [[house norwegian _ _ _ _] _ [house _ _ _ milk _] _ _])
21
- (member [house Fish_Owner fish _ _ _] Houses);)
22
-
23
- (defprolog member
24
- X [X | _] <--;
25
- X [_ | Z] <-- (member X Z);)
26
-
27
- (defprolog next_to
28
- X Y List <-- (iright X Y List);
29
- X Y List <-- (iright Y X List);)
30
-
31
- (defprolog iright
32
- L R [L | [R | _]] <--;
33
- L R [_ | Rest] <-- (iright L R Rest);)
Binary file
@@ -1,219 +0,0 @@
1
- (datatype num
2
-
3
- ____________________________________
4
- (number? X) : verified >> X : number;)
5
-
6
- (datatype primitive_object
7
-
8
- if (variable? X)
9
- _______________
10
- X : variable;
11
-
12
- X : variable;
13
- _____________
14
- X : primitive_object;
15
-
16
- X : symbol;
17
- ___________
18
- X : primitive_object;
19
-
20
- X : string;
21
- ___________
22
- X : primitive_object;
23
-
24
- X : boolean;
25
- ___________
26
- X : primitive_object;
27
-
28
- X : number;
29
- ___________
30
- X : primitive_object;
31
-
32
- _____________________
33
- [] : primitive_object;)
34
-
35
- (datatype pattern
36
-
37
- X : primitive_object;
38
- ___________
39
- X : pattern;
40
-
41
- P1 : pattern; P2 : pattern;
42
- ===========================
43
- [cons P1 P2] : pattern;
44
-
45
- P1 : pattern; P2 : pattern;
46
- ===========================
47
- [@p P1 P2] : pattern;)
48
-
49
- (datatype l_formula
50
-
51
- X : pattern;
52
- _____________
53
- X : l_formula;
54
-
55
- X : l_formula; Y : l_formula; Z : l_formula;
56
- =================================
57
- [if X Y Z] : l_formula;
58
-
59
- X : variable; Y : l_formula; Z : l_formula;
60
- ================================
61
- [let X Y Z] : l_formula;
62
-
63
- X : l_formula; Y : l_formula;
64
- ======================
65
- [cons X Y] : l_formula;
66
-
67
- X : l_formula; Y : l_formula;
68
- ======================
69
- [@p X Y] : l_formula;
70
-
71
- X : l_formula; Y : l_formula;
72
- ======================
73
- [where X Y] : l_formula;
74
-
75
- X : l_formula; Y : l_formula;
76
- ======================
77
- [= X Y] : l_formula;
78
-
79
- X : l_formula; Y : l_formula;
80
- ======================
81
- [X Y] : l_formula;
82
-
83
- Xn : (list l_formula);
84
- ===================
85
- [cases | Xn] : l_formula;
86
-
87
- P : pattern; X : l_formula;
88
- ===========================
89
- [/. P X] : l_formula;)
90
-
91
- (define l_interpreter
92
- {A --> B}
93
- _ -> (read_eval_print_loop (output "~%L interpreter ~%~%~%~%l-interp --> ~A~%"
94
- (normal_form (input+ : l_formula)))))
95
-
96
- (define read_eval_print_loop
97
- {string --> A}
98
- _ -> (read_eval_print_loop
99
- (output "l-interp --> ~A~%"
100
- (normal_form (input+ : l_formula)))))
101
-
102
- (define normal_form
103
- {l_formula --> l_formula}
104
- X -> (fix (function ==>>) X))
105
-
106
- (define ==>>
107
- {l_formula --> l_formula}
108
- [= X Y] -> (let X* (normal_form X)
109
- (let Y* (normal_form Y)
110
- (if (or (eval_error? X*) (eval_error? Y*))
111
- "error!"
112
- (if (= X* Y*) true false))))
113
- [[/. P X] Y] -> (let Match (match P (normal_form Y))
114
- (if (no_match? Match)
115
- "no match"
116
- (sub Match X)))
117
- [if X Y Z] -> (let X* (normal_form X)
118
- (if (= X* true)
119
- Y
120
- (if (= X* false)
121
- Z
122
- "error!")))
123
- [let X Y Z] -> [[/. X Z] Y]
124
- [@p X Y] -> (let X* (normal_form X)
125
- (let Y* (normal_form Y)
126
- (if (or (eval_error? X*) (eval_error? Y*))
127
- "error!"
128
- [@p X* Y*])))
129
- [cons X Y] -> (let X* (normal_form X)
130
- (let Y* (normal_form Y)
131
- (if (or (eval_error? X*) (eval_error? Y*))
132
- "error!"
133
- [cons X* Y*])))
134
- [++ X] -> (successor (normal_form X))
135
- [-- X] -> (predecessor (normal_form X))
136
- \*[cases X1 | Xn] -> (let Case1 (normal_form X1)
137
- (if (= Case1 "no match")
138
- [cases | Xn]
139
- Case1))
140
- [cases] -> "error!"
141
- [where X Y] -> [if X Y "no match"]
142
- [y-combinator [/. X Y]] -> (replace X [y-combinator [/. X Y]] Y)
143
- [X Y] -> (let X* (normal_form X)
144
- (let Y* (normal_form Y)
145
- (if (or (eval_error? X*) (eval_error? Y*))
146
- "error!"
147
- [X* Y*])))*\
148
- X -> X)
149
-
150
- (define eval_error?
151
- {l_formula --> boolean}
152
- "error!" -> true
153
- "no match" -> true
154
- _ -> false)
155
-
156
- (define successor
157
- {A --> l_formula}
158
- X -> (+ 1 X) where (number? X)
159
- _ -> "error!")
160
-
161
- (define predecessor
162
- {A --> l_formula}
163
- X -> (- X 1) where (number? X)
164
- _ -> "error!")
165
-
166
- \* (spy +) *\
167
-
168
- (define sub
169
- {[(pattern * l_formula)] --> l_formula --> l_formula}
170
- [] X -> X
171
- [(@p Var Val) | Assoc] X -> (sub Assoc (replace Var Val X)))
172
-
173
- (define match
174
- {pattern --> l_formula --> (list (pattern * l_formula))}
175
- P X -> [] where (== P X)
176
- P X -> [(@p P X)] where (variable? P)
177
- [cons P1 P2] [cons X Y] -> (let Match1 (match P1 X)
178
- (if (no_match? Match1)
179
- Match1
180
- (let Match2 (match P2 Y)
181
- (if (no_match? Match2)
182
- Match2
183
- (append Match1 Match2)))))
184
- [@p P1 P2] [@p X Y] -> (let Match1 (match P1 X)
185
- (if (no_match? Match1)
186
- Match1
187
- (let Match2 (match P2 Y)
188
- (if (no_match? Match2)
189
- Match2
190
- (append Match1 Match2)))))
191
-
192
- _ _ -> [(@p no matching)])
193
-
194
- (define no_match?
195
- {[(pattern * l_formula)] --> boolean}
196
- [(@p no matching)] -> true
197
- _ -> false)
198
-
199
- (define replace
200
- {pattern --> l_formula --> l_formula --> l_formula}
201
- V W [let V* X Y] -> [let V* X Y] where (== V V*)
202
- X Y X -> Y
203
- V W [= X Y] -> [= (replace V W X) (replace V W Y)]
204
- V W [/. P X] -> [/. P (replace V W X)] where (free? V P)
205
- V W [if X Y Z] -> [if (replace V W X) (replace V W Y) (replace V W Z)]
206
- V W [let X Y Z] -> [let X (replace V W Y) (replace V W Z)]
207
- V W [@p X Y] -> [@p (replace V W X) (replace V W Y)]
208
- V W [cons X Y] -> [cons (replace V W X) (replace V W Y)]
209
- V W [cases | Xn] -> [cases | (map (/. Xi (replace V W Xi)) Xn)]
210
- V W [where X Y] -> [where (replace V W X) (replace V W Y)]
211
- V W [X Y] -> [(replace V W X) (replace V W Y)]
212
- _ _ X -> X)
213
-
214
- (define free?
215
- {pattern --> pattern --> boolean}
216
- P P -> false
217
- P [cons P1 P2] -> (and (free? P P1) (free? P P2))
218
- P [@p P1 P2] -> (and (free? P P1) (free? P P2))
219
- _ _ -> true)
@@ -1,194 +0,0 @@
1
- (define kl-to-lisp
2
- Params Param -> Param where (element? Param Params)
3
- Params [type X _] -> (kl-to-lisp Params X)
4
- Params [lambda X Y] -> [FUNCTION [LAMBDA [X] (kl-to-lisp [X | Params] Y)]]
5
- Params [let X Y Z] -> [LET [[X (kl-to-lisp Params Y)]]
6
- (kl-to-lisp [X | Params] Z)]
7
- _ [defun F Params Code] -> [DEFUN F Params (kl-to-lisp Params Code)]
8
- Params [cond | Cond] -> [COND | (map (/. C (cond_code Params C)) (insert-default Cond))]
9
- Params [Param | X] -> (higher-order-code Param
10
- (map (/. Y (kl-to-lisp Params Y)) X))
11
- where (element? Param Params)
12
- Params [[X | Y] | Z] -> (higher-order-code (kl-to-lisp Params [X | Y])
13
- (map (/. W (kl-to-lisp Params W)) Z))
14
- Params [F | X] -> (assemble-application F
15
- (map (/. Y (kl-to-lisp Params Y)) X))
16
- where (symbol? F)
17
- _ [] -> []
18
- _ S -> [QUOTE S] where (or (symbol? S) (boolean? S))
19
- _ X -> X)
20
-
21
- (define insert-default
22
- [] -> [[true [ERROR "error: cond failure~%"]]]
23
- [[true X] | Y] -> [[true X] | Y]
24
- [Case | Cases] -> [Case | (insert-default Cases)])
25
-
26
- (define higher-order-code
27
- F X -> [let Args [LIST | X]
28
- [let NewF [maplispsym F]
29
- [trap-error [APPLY NewF Args]
30
- [lambda E [COND [[arity-error? F Args]
31
- [funcall [EVAL [nest-lambda F NewF]] Args]]
32
- [[EQ NewF [QUOTE or]]
33
- [funcall [lambda X1 [lambda X2 [or X1 X2]]] Args]]
34
- [[EQ NewF [QUOTE and]]
35
- [funcall [lambda X1 [lambda X2 [and X1 X2]]] Args]]
36
- [[EQ NewF [QUOTE trap-error]]
37
- [funcall [lambda X1 [lambda X2 [trap-error X1 X2]]] Args]]
38
- [[bad-lambda-call? NewF Args]
39
- [funcall NewF Args]]
40
- [T [relay-error E]]]]]]])
41
-
42
- (define bad-lambda-call?
43
- F Args -> (AND (FUNCTIONP F) (NOT (= (LIST-LENGTH Args) 1))))
44
-
45
- (define relay-error
46
- E -> (ERROR (error-to-string E)))
47
-
48
- (define funcall
49
- Lambda [] -> Lambda
50
- Lambda [X | Y] -> (funcall (FUNCALL Lambda X) Y))
51
-
52
- (define arity-error?
53
- F Args -> (AND (SYMBOLP F)
54
- (> (trap-error (arity F) (/. E -1)) (LIST-LENGTH Args)))
55
-
56
- (define nest-lambda
57
- F NewF -> (nest-lambda-help NewF (trap-error (arity F) (/. E -1))))
58
-
59
- (define nest-lambda-help
60
- F -1 -> F
61
- F 0 -> F
62
- F N -> (let X (gensym (protect Y))
63
- [lambda X (nest-lambda-help (add-p F X) (- N 1))]))
64
-
65
- (define add-p
66
- [F | X] Y -> (append [F | X] [Y])
67
- F X -> [F X])
68
-
69
- (define cond_code
70
- Params [Test Result] -> [(lisp_test Params Test)
71
- (kl-to-lisp Params Result)])
72
-
73
- (define lisp_test
74
- _ true -> T
75
- Params [and | Tests] -> [AND | (map (/. X (wrap (kl-to-lisp Params X))) Tests)]
76
- Params Test -> (wrap (kl-to-lisp Params Test)))
77
-
78
- (define wrap
79
- [cons? X] -> [CONSP X]
80
- [string? X] -> [STRINGP X]
81
- [number? X] -> [NUMBERP X]
82
- [empty? X] -> [NULL X]
83
- [and P Q] -> [AND (wrap P) (wrap Q)]
84
- [or P Q] -> [OR (wrap P) (wrap Q)]
85
- [not P] -> [NOT (wrap P)]
86
- [equal? X []] -> [NULL X]
87
- [equal? [] X] -> [NULL X]
88
- [equal? X [Quote Y]] -> [EQ X [Quote Y]]
89
- where (and (= (SYMBOLP Y) T) (= Quote QUOTE))
90
- [equal? [Quote Y] X] -> [EQ [Quote Y] X]
91
- where (and (= (SYMBOLP Y) T) (= Quote QUOTE))
92
- [equal? [fail] X] -> [EQ [fail] X]
93
- [equal? X [fail]] -> [EQ X [fail]]
94
- [equal? S X] -> [EQUAL S X] where (string? S)
95
- [equal? X S] -> [EQUAL X S] where (string? S)
96
- [equal? X Y] -> [shen-ABSEQUAL X Y]
97
- [shen-+string? [tlstr X]] -> [NOT [STRING-EQUAL [tlstr X] ""]]
98
- [shen-pvar? X] -> [AND [ARRAYP X] [NOT [STRINGP X]] [EQ [AREF X 0] [QUOTE shen-pvar]]]
99
- [tuple? X] -> [AND [ARRAYP X] [NOT [STRINGP X]] [EQ [AREF X 0] [QUOTE shen-tuple]]]
100
- [greater? X Y] -> [> X Y]
101
- [greater-than-or-equal-to? X Y] -> [>= X Y]
102
- [less? X Y] -> [< X Y]
103
- [less-than-or-equal-to? X Y] -> [<= X Y]
104
- X -> [wrapper X])
105
-
106
- (define wrapper
107
- true -> T
108
- false -> []
109
- X -> (error "boolean expected: not ~S~%" X))
110
-
111
- (define assemble-application
112
- hd [X] -> (protect [CAR X])
113
- tl [X] -> (protect [CDR X])
114
- cons [X Y] -> (protect [CONS X Y])
115
- append [X Y] -> (protect [APPEND X Y])
116
- reverse [X] -> (protect [REVERSE X])
117
- if [P Q R] -> (protect [IF (wrap P) Q R])
118
- + [1 X] -> [1+ X]
119
- + [X 1] -> [1+ X]
120
- - [X 1] -> [1- X]
121
- value [[Quote X]] -> X where (= Quote (protect QUOTE))
122
- set [[Quote X] [1+ X]] -> [INCF X] where (= Quote (protect QUOTE))
123
- set [[Quote X] [1- X]] -> [DECF X] where (= Quote (protect QUOTE))
124
- F X -> (let NewF (maplispsym F)
125
- Arity (trap-error (arity F) (/. E -1))
126
- (if (or (= Arity (length X)) (= Arity -1))
127
- [NewF | X]
128
- [funcall (nest-lambda F NewF) [(protect LIST) | X]])))
129
-
130
- (define maplispsym
131
- = -> equal?
132
- > -> greater?
133
- < -> less?
134
- >= -> greater-than-or-equal-to?
135
- <= -> less-than-or-equal-to?
136
- + -> add
137
- - -> subtract
138
- / -> divide
139
- * -> multiply
140
- F -> F)
141
-
142
- (define factorh
143
- [Defun F Params [Cond | Code]] -> [Defun F Params [BLOCK [] (process-tree (tree (map returns Code)))]]
144
- where (and (= Cond COND) (= Defun DEFUN))
145
- Code -> Code)
146
-
147
- (define returns
148
- [Test Result] -> [Test [RETURN Result]])
149
-
150
- (define process-tree
151
- (@p P Q R no-tag) -> [IF P (optimise-selectors P (process-tree Q)) (process-tree R)]
152
- (@p P Q R Tag) -> [TAGBODY [IF P (optimise-selectors P (process-tree Q))] Tag (process-tree R)]
153
- Q -> Q where (not (tuple? Q)))
154
-
155
- (define optimise-selectors
156
- Test Code -> (optimise-selectors-help (selectors-from Test) Code))
157
-
158
- (define selectors-from
159
- [Consp X] -> [[CAR X] [CDR X]] where (= Consp CONSP)
160
- [tuple? X] -> [[fst X] [snd X]]
161
- _ -> [])
162
-
163
- (define optimise-selectors-help
164
- [] Code -> Code
165
- [S1 S2] Code -> (let O1 (occurrences S1 Code)
166
- O2 (occurrences S2 Code)
167
- V1 (gensym V)
168
- V2 (gensym V)
169
- (if (and (> O1 1) (> O2 1))
170
- [LET [[V1 S1] [V2 S2]]
171
- (subst V1 S1 (subst V2 S2 Code))]
172
- (if (> O1 1)
173
- [LET [[V1 S1]] (subst V1 S1 Code)]
174
- (if (> O2 1)
175
- [LET [[V2 S2]] (subst V2 S2 Code)]
176
- Code)))))
177
-
178
- (define tree
179
- [[[And P Q] R] | S] -> (let Tag (gensym tag)
180
- Left (tree (append (branch-by P [[[And P Q] R] | S]) [[T [GO Tag]]]))
181
- Right (tree (branch-by-not P [[[And P Q] R] | S]))
182
- (@p P Left Right Tag)) where (= And AND)
183
- [[True Q] | _] -> Q where (= True T)
184
- [[P Q] | R] -> (@p P Q (tree R) no-tag))
185
-
186
- (define branch-by
187
- P [[[And P Q] R] | S] -> [[Q R] | (branch-by P S)] where (= And AND)
188
- P [[P R] | S] -> [[T R]]
189
- _ Code -> [])
190
-
191
- (define branch-by-not
192
- P [[[And P Q] R] | S] -> (branch-by-not P S) where (= And AND)
193
- P [[P R] | S] -> S
194
- _ Code -> Code)