shen-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +0 -0
  3. data/Gemfile +6 -0
  4. data/Gemfile.lock +20 -0
  5. data/MIT_LICENSE.txt +26 -0
  6. data/README.md +94 -0
  7. data/bin/shen_test_suite.rb +9 -0
  8. data/bin/srrepl +23 -0
  9. data/lib/kl.rb +7 -0
  10. data/lib/kl/absvector.rb +12 -0
  11. data/lib/kl/compiler.rb +253 -0
  12. data/lib/kl/cons.rb +51 -0
  13. data/lib/kl/empty_list.rb +12 -0
  14. data/lib/kl/environment.rb +123 -0
  15. data/lib/kl/error.rb +4 -0
  16. data/lib/kl/internal_error.rb +7 -0
  17. data/lib/kl/lexer.rb +186 -0
  18. data/lib/kl/primitives/arithmetic.rb +60 -0
  19. data/lib/kl/primitives/assignments.rb +18 -0
  20. data/lib/kl/primitives/booleans.rb +17 -0
  21. data/lib/kl/primitives/error_handling.rb +13 -0
  22. data/lib/kl/primitives/generic_functions.rb +22 -0
  23. data/lib/kl/primitives/lists.rb +21 -0
  24. data/lib/kl/primitives/streams.rb +38 -0
  25. data/lib/kl/primitives/strings.rb +55 -0
  26. data/lib/kl/primitives/symbols.rb +17 -0
  27. data/lib/kl/primitives/time.rb +17 -0
  28. data/lib/kl/primitives/vectors.rb +30 -0
  29. data/lib/kl/reader.rb +40 -0
  30. data/lib/kl/trampoline.rb +14 -0
  31. data/lib/shen_ruby.rb +7 -0
  32. data/lib/shen_ruby/version.rb +3 -0
  33. data/shen-ruby.gemspec +26 -0
  34. data/shen/README.txt +17 -0
  35. data/shen/lib/shen_ruby/shen.rb +124 -0
  36. data/shen/license.txt +34 -0
  37. data/shen/release/benchmarks/N_queens.shen +45 -0
  38. data/shen/release/benchmarks/README.shen +14 -0
  39. data/shen/release/benchmarks/benchmarks.shen +56 -0
  40. data/shen/release/benchmarks/bigprog +2173 -0
  41. data/shen/release/benchmarks/br.shen +13 -0
  42. data/shen/release/benchmarks/einstein.shen +33 -0
  43. data/shen/release/benchmarks/heatwave.gif +0 -0
  44. data/shen/release/benchmarks/interpreter.shen +219 -0
  45. data/shen/release/benchmarks/picture.jpg +0 -0
  46. data/shen/release/benchmarks/plato.jpg +0 -0
  47. data/shen/release/benchmarks/powerset.shen +10 -0
  48. data/shen/release/benchmarks/prime.shen +10 -0
  49. data/shen/release/benchmarks/short.shen +129 -0
  50. data/shen/release/benchmarks/text.txt +68 -0
  51. data/shen/release/k_lambda/core.kl +1002 -0
  52. data/shen/release/k_lambda/declarations.kl +1021 -0
  53. data/shen/release/k_lambda/load.kl +94 -0
  54. data/shen/release/k_lambda/macros.kl +479 -0
  55. data/shen/release/k_lambda/prolog.kl +1309 -0
  56. data/shen/release/k_lambda/reader.kl +1058 -0
  57. data/shen/release/k_lambda/sequent.kl +556 -0
  58. data/shen/release/k_lambda/sys.kl +582 -0
  59. data/shen/release/k_lambda/t-star.kl +3493 -0
  60. data/shen/release/k_lambda/toplevel.kl +223 -0
  61. data/shen/release/k_lambda/track.kl +208 -0
  62. data/shen/release/k_lambda/types.kl +455 -0
  63. data/shen/release/k_lambda/writer.kl +108 -0
  64. data/shen/release/k_lambda/yacc.kl +280 -0
  65. data/shen/release/test_programs/Chap13/problems.txt +26 -0
  66. data/shen/release/test_programs/README.shen +53 -0
  67. data/shen/release/test_programs/TinyLispFunctions.txt +16 -0
  68. data/shen/release/test_programs/TinyTypes.shen +55 -0
  69. data/shen/release/test_programs/binary.shen +24 -0
  70. data/shen/release/test_programs/bubble_version_1.shen +28 -0
  71. data/shen/release/test_programs/bubble_version_2.shen +22 -0
  72. data/shen/release/test_programs/calculator.shen +21 -0
  73. data/shen/release/test_programs/cartprod.shen +23 -0
  74. data/shen/release/test_programs/change.shen +25 -0
  75. data/shen/release/test_programs/classes-defaults.shen +94 -0
  76. data/shen/release/test_programs/classes-inheritance.shen +100 -0
  77. data/shen/release/test_programs/classes-typed.shen +74 -0
  78. data/shen/release/test_programs/classes-untyped.shen +46 -0
  79. data/shen/release/test_programs/depth_.shen +14 -0
  80. data/shen/release/test_programs/einstein.shen +33 -0
  81. data/shen/release/test_programs/fruit_machine.shen +46 -0
  82. data/shen/release/test_programs/interpreter.shen +219 -0
  83. data/shen/release/test_programs/metaprog.shen +85 -0
  84. data/shen/release/test_programs/minim.shen +193 -0
  85. data/shen/release/test_programs/mutual.shen +11 -0
  86. data/shen/release/test_programs/n_queens.shen +45 -0
  87. data/shen/release/test_programs/newton_version_1.shen +33 -0
  88. data/shen/release/test_programs/newton_version_2.shen +24 -0
  89. data/shen/release/test_programs/parse.prl +14 -0
  90. data/shen/release/test_programs/parser.shen +52 -0
  91. data/shen/release/test_programs/powerset.shen +10 -0
  92. data/shen/release/test_programs/prime.shen +10 -0
  93. data/shen/release/test_programs/proof_assistant.shen +81 -0
  94. data/shen/release/test_programs/proplog_version_1.shen +25 -0
  95. data/shen/release/test_programs/proplog_version_2.shen +27 -0
  96. data/shen/release/test_programs/qmachine.shen +67 -0
  97. data/shen/release/test_programs/red-black.shen +55 -0
  98. data/shen/release/test_programs/search.shen +56 -0
  99. data/shen/release/test_programs/semantic_net.shen +44 -0
  100. data/shen/release/test_programs/spreadsheet.shen +35 -0
  101. data/shen/release/test_programs/stack.shen +27 -0
  102. data/shen/release/test_programs/streams.shen +20 -0
  103. data/shen/release/test_programs/strings.shen +59 -0
  104. data/shen/release/test_programs/structures-typed.shen +71 -0
  105. data/shen/release/test_programs/structures-untyped.shen +42 -0
  106. data/shen/release/test_programs/tests.shen +294 -0
  107. data/shen/release/test_programs/types.shen +11 -0
  108. data/shen/release/test_programs/whist.shen +240 -0
  109. data/shen/release/test_programs/yacc.shen +136 -0
  110. data/spec/kl/cons_spec.rb +12 -0
  111. data/spec/kl/environment_spec.rb +306 -0
  112. data/spec/kl/lexer_spec.rb +149 -0
  113. data/spec/kl/primitives/generic_functions_spec.rb +29 -0
  114. data/spec/kl/primitives/symbols_spec.rb +21 -0
  115. data/spec/kl/reader_spec.rb +36 -0
  116. data/spec/spec_helper.rb +2 -0
  117. metadata +189 -0
@@ -0,0 +1,108 @@
1
+
2
+ " The License
3
+
4
+ The user is free to produce commercial applications with the software, to distribute these applications in source or binary form, and to charge monies for them as he sees fit and in concordance with the laws of the land subject to the following license.
5
+
6
+ 1. The license applies to all the software and all derived software and must appear on such.
7
+ 2. It is illegal to distribute the software without this license attached to it and use of the software implies agreement
8
+ with the license as such. It is illegal for anyone who is not the copyright holder to tamper with or change the license.
9
+ 3. Neither the names of Lambda Associates or the copyright holder may be used to endorse or promote products built using
10
+ the software without specific prior written permission from the copyright holder.
11
+ 4. That possession of this license does not confer on the copyright holder any special contractual obligation towards the user. That in no event shall the copyright holder be liable for any direct, indirect, incidental, special, exemplary or consequential damages (including but not limited to procurement of substitute goods or services, loss of use, data, or profits; or business interruption), however caused and on any theory of liability, whether in contract, strict liability or tort (including negligence) arising in any way out of the use of the software, even if advised of the possibility of such damage.
12
+ 5. It is permitted for the user to change the software, for the purpose of improving performance, correcting an error, or porting to a new platform, and distribute the modified version of Shen (hereafter the modified version) provided the resulting program conforms in all respects to the Shen standard and is issued under that title. The user must make it clear with his distribution that he/she is the author of the changes and what these changes are and why.
13
+ 6. Derived versions of this software in whatever form are subject to the same restrictions. In particular it is not permitted to make derived copies of this software which do not conform to the Shen standard or appear under a different title.
14
+ 7. It is permitted to distribute versions of Shen which incorporate libraries, graphics or other facilities which are not part of the Shen standard.
15
+
16
+ For an explication of this license see http://www.lambdassociates.org/News/june11/license.htm which explains this license in full."
17
+
18
+ (defun print (V1081)
19
+ (do
20
+ (pr (shen-ms-h (cons "~" (cons "S" ())) (@p V1081 shen-skip))
21
+ (shen-stoutput 0))
22
+ V1081))
23
+
24
+ (defun format (V1082 V1083 V1084)
25
+ (cond ((= true V1082) (intoutput V1083 (@p V1084 ())))
26
+ ((= false V1082) (intmake-string V1083 (@p V1084 ())))
27
+ (true (pr (shen-ms-h (explode V1083) V1084) V1082))))
28
+
29
+ (defun intoutput (V1085 V1086)
30
+ (pr (shen-ms-h (shen-explode-string V1085) V1086) (shen-stoutput 0)))
31
+
32
+ (defun interror (V1087 V1088)
33
+ (simple-error (shen-ms-h (shen-explode-string V1087) V1088)))
34
+
35
+ (defun intmake-string (V1089 V1090)
36
+ (shen-ms-h (shen-explode-string V1089) V1090))
37
+
38
+ (defun shen-ms-h (V1093 V1094)
39
+ (cond ((= () V1093) "")
40
+ ((and (cons? V1093)
41
+ (and (= "~" (hd V1093))
42
+ (and (cons? (tl V1093)) (= "%" (hd (tl V1093))))))
43
+ (cn (n->string 10) (shen-ms-h (tl (tl V1093)) V1094)))
44
+ ((and (cons? V1093)
45
+ (and (= "~" (hd V1093))
46
+ (and (cons? (tl V1093))
47
+ (and (tuple? V1094)
48
+ (element? (hd (tl V1093)) (cons "A" (cons "S" (cons "R" ()))))))))
49
+ (cn (shen-ob->str (hd (tl V1093)) (fst V1094))
50
+ (shen-ms-h (tl (tl V1093)) (snd V1094))))
51
+ ((cons? V1093) (cn (hd V1093) (shen-ms-h (tl V1093) V1094)))
52
+ (true (shen-sys-error shen-ms-h))))
53
+
54
+ (defun shen-ob->str (V1098 V1099)
55
+ (cond ((= V1099 (fail)) "...")
56
+ ((= () V1099) (if (= V1098 "R") "()" "[]"))
57
+ ((= V1099 (vector 0)) "<>")
58
+ ((cons? V1099)
59
+ (shen-cn-all
60
+ (append (if (= V1098 "R") (cons "(" ()) (cons "[" ()))
61
+ (append (cons (shen-ob->str V1098 (hd V1099)) ())
62
+ (append
63
+ (shen-xmapcan (value *maximum-print-sequence-size*)
64
+ (lambda Z (cons " " (cons (shen-ob->str V1098 Z) ()))) (tl V1099))
65
+ (if (= V1098 "R") (cons ")" ()) (cons "]" ())))))))
66
+ ((vector? V1099)
67
+ (let L (shen-vector->list V1099 1)
68
+ (let E
69
+ (tlstr
70
+ (shen-cn-all
71
+ (shen-xmapcan (- (value *maximum-print-sequence-size*) 1)
72
+ (lambda Z
73
+ (cons " " (cons (shen-ob->str V1098 Z) ())))
74
+ L)))
75
+ (let V (cn "<" (cn E ">")) V))))
76
+ ((and (not (string? V1099)) (absvector? V1099))
77
+ (trap-error (shen-ob->str "A" ((<-address V1099 0) V1099))
78
+ (lambda Ignore
79
+ (let L (shen-vector->list V1099 0)
80
+ (let E
81
+ (tlstr
82
+ (shen-cn-all
83
+ (shen-xmapcan (- (value *maximum-print-sequence-size*) 1)
84
+ (lambda Z (cons " " (cons (shen-ob->str V1098 Z) ()))) L)))
85
+ (let V (cn "<" (cn E ">")) V))))))
86
+ (true (if (and (= V1098 "A") (string? V1099)) V1099 (str V1099)))))
87
+
88
+ (defun shen-tuple (V1101)
89
+ (intmake-string "(@p ~S ~S)" (@p (fst V1101) (@p (snd V1101) ()))))
90
+
91
+ (defun shen-cn-all (V1102)
92
+ (cond ((= () V1102) "")
93
+ ((cons? V1102) (cn (hd V1102) (shen-cn-all (tl V1102))))
94
+ (true (shen-sys-error shen-cn-all))))
95
+
96
+ (defun shen-xmapcan (V1115 V1116 V1117)
97
+ (cond ((= () V1117) ()) ((= 0 V1115) (cons "... etc" ()))
98
+ ((cons? V1117)
99
+ (append (V1116 (hd V1117)) (shen-xmapcan (- V1115 1) V1116 (tl V1117))))
100
+ (true (cons " |" (V1116 V1117)))))
101
+
102
+ (defun shen-vector->list (V1118 V1119) (shen-vector->listh V1118 V1119 ()))
103
+
104
+ (defun shen-vector->listh (V1120 V1121 V1122)
105
+ (let Y (trap-error (<-address V1120 V1121) (lambda E shen-out-of-range))
106
+ (if (= Y shen-out-of-range) (reverse V1122)
107
+ (shen-vector->listh V1120 (+ V1121 1) (cons Y V1122)))))
108
+
@@ -0,0 +1,280 @@
1
+
2
+ " The License
3
+
4
+ The user is free to produce commercial applications with the software, to distribute these applications in source or binary form, and to charge monies for them as he sees fit and in concordance with the laws of the land subject to the following license.
5
+
6
+ 1. The license applies to all the software and all derived software and must appear on such.
7
+ 2. It is illegal to distribute the software without this license attached to it and use of the software implies agreement
8
+ with the license as such. It is illegal for anyone who is not the copyright holder to tamper with or change the license.
9
+ 3. Neither the names of Lambda Associates or the copyright holder may be used to endorse or promote products built using
10
+ the software without specific prior written permission from the copyright holder.
11
+ 4. That possession of this license does not confer on the copyright holder any special contractual obligation towards the user. That in no event shall the copyright holder be liable for any direct, indirect, incidental, special, exemplary or consequential damages (including but not limited to procurement of substitute goods or services, loss of use, data, or profits; or business interruption), however caused and on any theory of liability, whether in contract, strict liability or tort (including negligence) arising in any way out of the use of the software, even if advised of the possibility of such damage.
12
+ 5. It is permitted for the user to change the software, for the purpose of improving performance, correcting an error, or porting to a new platform, and distribute the modified version of Shen (hereafter the modified version) provided the resulting program conforms in all respects to the Shen standard and is issued under that title. The user must make it clear with his distribution that he/she is the author of the changes and what these changes are and why.
13
+ 6. Derived versions of this software in whatever form are subject to the same restrictions. In particular it is not permitted to make derived copies of this software which do not conform to the Shen standard or appear under a different title.
14
+ 7. It is permitted to distribute versions of Shen which incorporate libraries, graphics or other facilities which are not part of the Shen standard.
15
+
16
+ For an explication of this license see http://www.lambdassociates.org/News/june11/license.htm which explains this license in full."
17
+
18
+ (defun shen-yacc (V293)
19
+ (cond
20
+ ((and (cons? V293) (and (= defcc (hd V293)) (cons? (tl V293))))
21
+ (shen-yacc->shen (hd (tl V293)) (tl (tl V293))
22
+ (shen-extract-segvars (tl (tl V293)))))
23
+ (true (shen-sys-error shen-yacc))))
24
+
25
+ (defun shen-extract-segvars (V298)
26
+ (cond ((shen-segvar? V298) (cons V298 ()))
27
+ ((cons? V298)
28
+ (union (shen-extract-segvars (hd V298)) (shen-extract-segvars (tl V298))))
29
+ (true ())))
30
+
31
+ (defun shen-yacc->shen (V299 V300 V301)
32
+ (let Main
33
+ (cons define
34
+ (cons V299
35
+ (shen-yacc_cases
36
+ (map (lambda V302 (shen-cc_body V302)) (shen-split_cc_rules V300 ())))))
37
+ (if (empty? V301) Main
38
+ (cons package
39
+ (cons null
40
+ (cons () (cons Main (map (lambda V303 (shen-segdef V303)) V301))))))))
41
+
42
+ (defun shen-segdef (V304)
43
+ (cons define
44
+ (cons V304
45
+ (cons (cons @p (cons In (cons Out ())))
46
+ (cons Continuation
47
+ (cons ->
48
+ (cons
49
+ (cons let
50
+ (cons Continue
51
+ (cons
52
+ (cons Continuation
53
+ (cons (cons reverse (cons Out ()))
54
+ (cons (cons @p (cons In (cons () ()))) ())))
55
+ (cons
56
+ (cons if
57
+ (cons
58
+ (cons and
59
+ (cons (cons = (cons Continue (cons (cons fail ()) ())))
60
+ (cons (cons cons? (cons In ())) ())))
61
+ (cons
62
+ (cons V304
63
+ (cons
64
+ (cons @p
65
+ (cons (cons tl (cons In ()))
66
+ (cons
67
+ (cons cons (cons (cons hd (cons In ())) (cons Out ())))
68
+ ())))
69
+ (cons Continuation ())))
70
+ (cons Continue ()))))
71
+ ()))))
72
+ ())))))))
73
+
74
+ (defun shen-yacc_cases (V305)
75
+ (append (mapcan (lambda Case (cons Stream (cons <- (cons Case ())))) V305)
76
+ (cons _ (cons -> (cons (cons fail ()) ())))))
77
+
78
+ (defun shen-first_n (V310 V311)
79
+ (cond ((= 0 V310) ()) ((= () V311) ())
80
+ ((cons? V311) (cons (hd V311) (shen-first_n (- V310 1) (tl V311))))
81
+ (true (shen-sys-error shen-first_n))))
82
+
83
+ (defun shen-split_cc_rules (V312 V313)
84
+ (cond ((and (= () V312) (= () V313)) ())
85
+ ((= () V312) (cons (shen-split_cc_rule (reverse V313) ()) ()))
86
+ ((and (cons? V312) (= ; (hd V312)))
87
+ (cons (shen-split_cc_rule (reverse V313) ())
88
+ (shen-split_cc_rules (tl V312) ())))
89
+ ((cons? V312) (shen-split_cc_rules (tl V312) (cons (hd V312) V313)))
90
+ (true (shen-sys-error shen-split_cc_rules))))
91
+
92
+ (defun shen-split_cc_rule (V314 V315)
93
+ (cond
94
+ ((and (cons? V314)
95
+ (and (= := (hd V314))
96
+ (and (cons? (tl V314)) (= () (tl (tl V314))))))
97
+ (cons (reverse V315) (tl V314)))
98
+ ((and (cons? V314) (= := (hd V314)))
99
+ (cons (reverse V315) (cons (shen-cons_form (tl V314)) ())))
100
+ ((= () V314)
101
+ (do (intoutput "warning: " ())
102
+ (do (map (lambda X (intoutput "~A " (@p X ()))) (reverse V315))
103
+ (do (intoutput "has no semantics.~%" ())
104
+ (shen-split_cc_rule
105
+ (cons := (cons (shen-default_semantics (reverse V315)) ())) V315)))))
106
+ ((cons? V314) (shen-split_cc_rule (tl V314) (cons (hd V314) V315)))
107
+ (true (shen-sys-error shen-split_cc_rule))))
108
+
109
+ (defun shen-default_semantics (V316)
110
+ (cond ((= () V316) ())
111
+ ((and (cons? V316) (shen-grammar_symbol? (hd V316)))
112
+ (let PS (cons snd (cons (concat Parse_ (hd V316)) ()))
113
+ (if (empty? (tl V316)) PS
114
+ (cons append (cons PS (cons (shen-default_semantics (tl V316)) ()))))))
115
+ ((cons? V316)
116
+ (cons cons (cons (hd V316) (cons (shen-default_semantics (tl V316)) ()))))
117
+ (true (shen-sys-error shen-default_semantics))))
118
+
119
+ (defun shen-cc_body (V317)
120
+ (cond
121
+ ((and (cons? V317) (and (cons? (tl V317)) (= () (tl (tl V317)))))
122
+ (shen-syntax (hd V317) Stream (hd (tl V317))))
123
+ (true (shen-sys-error shen-cc_body))))
124
+
125
+ (defun shen-syntax (V318 V319 V320)
126
+ (cond
127
+ ((= () V318)
128
+ (cons shen-reassemble
129
+ (cons (cons fst (cons V319 ())) (cons (shen-semantics V320) ()))))
130
+ ((cons? V318)
131
+ (if (shen-grammar_symbol? (hd V318)) (shen-recursive_descent V318 V319 V320)
132
+ (if (shen-segvar? (hd V318)) (shen-segment-match V318 V319 V320)
133
+ (if (shen-terminal? (hd V318)) (shen-check_stream V318 V319 V320)
134
+ (if (shen-jump_stream? (hd V318)) (shen-jump_stream V318 V319 V320)
135
+ (if (shen-list_stream? (hd V318))
136
+ (shen-list_stream (shen-decons (hd V318)) (tl V318) V319 V320)
137
+ (interror "~A is not legal syntax~%" (@p (hd V318) ()))))))))
138
+ (true (shen-sys-error shen-syntax))))
139
+
140
+ (defun shen-list_stream? (V329) (cond ((cons? V329) true) (true false)))
141
+
142
+ (defun shen-decons (V330)
143
+ (cond
144
+ ((and (cons? V330)
145
+ (and (= cons (hd V330))
146
+ (and (cons? (tl V330))
147
+ (and (cons? (tl (tl V330))) (= () (tl (tl (tl V330))))))))
148
+ (cons (hd (tl V330)) (shen-decons (hd (tl (tl V330))))))
149
+ (true V330)))
150
+
151
+ (defun shen-list_stream (V331 V332 V333 V334)
152
+ (let Test
153
+ (cons and
154
+ (cons (cons cons? (cons (cons fst (cons V333 ())) ()))
155
+ (cons
156
+ (cons cons? (cons (cons hd (cons (cons fst (cons V333 ())) ())) ()))
157
+ ())))
158
+ (let Action
159
+ (cons shen-snd-or-fail
160
+ (cons
161
+ (shen-syntax V331
162
+ (cons shen-reassemble
163
+ (cons (cons hd (cons (cons fst (cons V333 ())) ()))
164
+ (cons (cons snd (cons V333 ())) ())))
165
+ (cons shen-leave!
166
+ (cons
167
+ (shen-syntax V332
168
+ (cons shen-reassemble
169
+ (cons (cons tl (cons (cons fst (cons V333 ())) ()))
170
+ (cons (cons snd (cons V333 ())) ())))
171
+ V334)
172
+ ())))
173
+ ()))
174
+ (let Else (cons fail ())
175
+ (cons if (cons Test (cons Action (cons Else ()))))))))
176
+
177
+ (defun shen-snd-or-fail (V341) (cond ((tuple? V341) (snd V341)) (true (fail))))
178
+
179
+ (defun shen-grammar_symbol? (V342)
180
+ (and (symbol? V342)
181
+ (let Cs (explode V342)
182
+ (and (= (hd Cs) "<") (= (hd (reverse Cs)) ">")))))
183
+
184
+ (defun shen-recursive_descent (V343 V344 V345)
185
+ (cond
186
+ ((cons? V343)
187
+ (let Test (cons (hd V343) (cons V344 ()))
188
+ (let Action (shen-syntax (tl V343) (concat Parse_ (hd V343)) V345)
189
+ (let Else (cons fail ())
190
+ (cons let
191
+ (cons (concat Parse_ (hd V343))
192
+ (cons Test
193
+ (cons
194
+ (cons if
195
+ (cons
196
+ (cons not
197
+ (cons
198
+ (cons =
199
+ (cons (cons fail ()) (cons (concat Parse_ (hd V343)) ())))
200
+ ()))
201
+ (cons Action (cons Else ()))))
202
+ ()))))))))
203
+ (true (shen-sys-error shen-recursive_descent))))
204
+
205
+ (defun shen-segvar? (V346) (and (symbol? V346) (= (hd (explode V346)) "?")))
206
+
207
+ (defun shen-segment-match (V347 V348 V349)
208
+ (cond
209
+ ((cons? V347)
210
+ (let Continuation
211
+ (cons lambda
212
+ (cons (hd V347)
213
+ (cons
214
+ (cons lambda
215
+ (cons Restart (cons (shen-syntax (tl V347) Restart V349) ())))
216
+ ())))
217
+ (cons (hd V347) (cons V348 (cons Continuation ())))))
218
+ (true (shen-sys-error shen-segment-match))))
219
+
220
+ (defun shen-terminal? (V358)
221
+ (cond ((cons? V358) false) ((= -*- V358) false) (true true)))
222
+
223
+ (defun shen-jump_stream? (V363) (cond ((= -*- V363) true) (true false)))
224
+
225
+ (defun shen-check_stream (V364 V365 V366)
226
+ (cond
227
+ ((cons? V364)
228
+ (let Test
229
+ (cons and
230
+ (cons (cons cons? (cons (cons fst (cons V365 ())) ()))
231
+ (cons
232
+ (cons =
233
+ (cons (hd V364)
234
+ (cons (cons hd (cons (cons fst (cons V365 ())) ())) ())))
235
+ ())))
236
+ (let Action
237
+ (shen-syntax (tl V364)
238
+ (cons shen-reassemble
239
+ (cons (cons tl (cons (cons fst (cons V365 ())) ()))
240
+ (cons (cons snd (cons V365 ())) ())))
241
+ V366)
242
+ (let Else (cons fail ())
243
+ (cons if (cons Test (cons Action (cons Else ()))))))))
244
+ (true (shen-sys-error shen-check_stream))))
245
+
246
+ (defun shen-reassemble (V368 V369)
247
+ (cond ((= V369 (fail)) V369) (true (@p V368 V369))))
248
+
249
+ (defun shen-jump_stream (V370 V371 V372)
250
+ (cond
251
+ ((cons? V370)
252
+ (let Test (cons cons? (cons (cons fst (cons V371 ())) ()))
253
+ (let Action
254
+ (shen-syntax (tl V370)
255
+ (cons shen-reassemble
256
+ (cons (cons tl (cons (cons fst (cons V371 ())) ()))
257
+ (cons (cons snd (cons V371 ())) ())))
258
+ V372)
259
+ (let Else (cons fail ())
260
+ (cons if (cons Test (cons Action (cons Else ()))))))))
261
+ (true (shen-sys-error shen-jump_stream))))
262
+
263
+ (defun shen-semantics (V373)
264
+ (cond
265
+ ((and (cons? V373)
266
+ (and (= shen-leave! (hd V373))
267
+ (and (cons? (tl V373)) (= () (tl (tl V373))))))
268
+ (hd (tl V373)))
269
+ ((= () V373) ())
270
+ ((shen-grammar_symbol? V373) (cons snd (cons (concat Parse_ V373) ())))
271
+ ((= -o- V373) (cons snd (cons Stream ())))
272
+ ((= -*- V373) (cons hd (cons (cons fst (cons Stream ())) ())))
273
+ ((= -s- V373) (cons fst (cons Stream ())))
274
+ ((cons? V373) (map (lambda V374 (shen-semantics V374)) V373)) (true V373)))
275
+
276
+ (defun fail () shen-fail!)
277
+
278
+ (defun <!> (V379)
279
+ (cond ((tuple? V379) (@p () (fst V379))) (true (shen-sys-error <!>))))
280
+
@@ -0,0 +1,26 @@
1
+
2
+ [[[y-combinator [/. ADD [/. X [/. Y [if [= X 0] Y [[ADD [-- X]] [++ Y]]]]]]] 2] 3]
3
+
4
+
5
+ [[[y-combinator [/. ADD [/. X [/. Y [if [= X 0] Y [[ADD [-- X]] [++ Y]]]]]]] 33] 4]
6
+
7
+ [[[/. [@p X Y] X]
8
+ [y-combinator [/. T
9
+ [@p [/. A [cases [[/. 1 false] A]
10
+ [[/. X [[[/. [@p X Y] Y] T] [-- X]]] A]]]
11
+ [/. A [cases [[/. 1 true] A]
12
+ [[/. X [[[/. [@p X Y] X] T] [-- X]]] A]]]]]]] 6]
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
@@ -0,0 +1,53 @@
1
+ \*
2
+
3
+ This is the test harness for Shen. Assuming your port to Blub is in the directory Platforms/Blub; do the
4
+ following.
5
+
6
+ (cd "../../Test Programs")
7
+ (load "README.shen")
8
+ (load "tests.shen")
9
+
10
+ *\
11
+
12
+ (package test-harness- [report reset ok passed failed]
13
+
14
+ (define reset
15
+ -> (set *passed* (set *failed* 0)))
16
+
17
+ (defmacro exec-macro
18
+ [exec Name Expr Prediction] -> [trap-error [let (protect Output) [output "~%~A: ~R = ~S" Name (rcons Expr) Prediction]
19
+ (protect Result) [time Expr]
20
+ [if [= (protect Result) Prediction] [passed] [failed (protect Result)]]]
21
+ [/. (protect E) [err (protect E)]]])
22
+
23
+ (define rcons
24
+ [X | Y] -> [cons (rcons X) (rcons Y)]
25
+ X -> X)
26
+
27
+ (define passed
28
+ -> (do (trap-error (set *passed* (+ 1 (value *passed*))) (/. E (set *passed* 1)))
29
+ (print passed)))
30
+
31
+ (define failed
32
+ Result -> (let Fail+ (trap-error (set *failed* (+ 1 (value *failed*))) (/. E (set *failed* 1)))
33
+ ShowResult (output "~S returned~%" Result)
34
+ (if (y-or-n? "failed; continue?") ok (error "kill"))))
35
+
36
+ (define err
37
+ E -> (error "") where (= (error-to-string E) "kill")
38
+ E -> (do (trap-error (set *failed* (+ 1 (value *failed*))) (/. E (set *failed* 1)))
39
+ (output "~%failed with error ~A~%" (error-to-string E))))
40
+
41
+ (defmacro report-results-macro
42
+ [report Name | Tests] -> (let NewTests (create-tests Name Tests)
43
+ [do | NewTests]))
44
+
45
+ (define create-tests
46
+ Name [] -> [[results] ok]
47
+ Name [Test Prediction | Tests] -> [[exec Name Test Prediction] | (create-tests Name Tests)])
48
+
49
+ (define results
50
+ -> (let Passed (trap-error (value *passed*) (/. E 0))
51
+ Failed (trap-error (value *failed*) (/. E 0))
52
+ Percent (* (/ Passed (+ Passed Failed)) 100)
53
+ (output "~%passed ... ~A~%failed ...~A~%pass rate ...~A%~%~%" Passed Failed Percent))) )