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,582 @@
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 thaw (V650) (V650))
19
+
20
+ (defun eval (V651)
21
+ (let Macroexpand (shen-walk (lambda V652 (macroexpand V652)) V651)
22
+ (if (shen-packaged? Macroexpand)
23
+ (map (lambda V653 (shen-eval-without-macros V653))
24
+ (shen-package-contents Macroexpand))
25
+ (shen-eval-without-macros Macroexpand))))
26
+
27
+ (defun shen-eval-without-macros (V654)
28
+ (eval-kl (shen-elim-define (shen-proc-input+ V654))))
29
+
30
+ (defun shen-proc-input+ (V655)
31
+ (cond
32
+ ((and (cons? V655)
33
+ (and (= input+ (hd V655))
34
+ (and (cons? (tl V655))
35
+ (and (cons? (tl (tl V655))) (= () (tl (tl (tl V655))))))))
36
+ (cons input+
37
+ (cons (hd (tl V655)) (cons (shen-rcons_form (hd (tl (tl V655)))) ()))))
38
+ ((cons? V655) (map (lambda V656 (shen-proc-input+ V656)) V655)) (true V655)))
39
+
40
+ (defun shen-elim-define (V657)
41
+ (cond
42
+ ((and (cons? V657) (and (= define (hd V657)) (cons? (tl V657))))
43
+ (shen-shen->kl (hd (tl V657)) (tl (tl V657))))
44
+ ((cons? V657) (map (lambda V658 (shen-elim-define V658)) V657)) (true V657)))
45
+
46
+ (defun shen-packaged? (V665)
47
+ (cond
48
+ ((and (cons? V665)
49
+ (and (= package (hd V665))
50
+ (and (cons? (tl V665)) (cons? (tl (tl V665))))))
51
+ true)
52
+ (true false)))
53
+
54
+ (defun external (V666)
55
+ (trap-error (get V666 shen-external-symbols (value shen-*property-vector*))
56
+ (lambda E (interror "package ~A has not been used.~%" (@p V666 ())))))
57
+
58
+ (defun shen-package-contents (V669)
59
+ (cond
60
+ ((and (cons? V669)
61
+ (and (= package (hd V669))
62
+ (and (cons? (tl V669))
63
+ (and (= null (hd (tl V669))) (cons? (tl (tl V669)))))))
64
+ (tl (tl (tl V669))))
65
+ ((and (cons? V669)
66
+ (and (= package (hd V669))
67
+ (and (cons? (tl V669)) (cons? (tl (tl V669))))))
68
+ (shen-packageh (hd (tl V669)) (hd (tl (tl V669))) Code))
69
+ (true (shen-sys-error shen-package-contents))))
70
+
71
+ (defun shen-walk (V670 V671)
72
+ (cond ((cons? V671) (V670 (map (lambda Z (shen-walk V670 Z)) V671)))
73
+ (true (V670 V671))))
74
+
75
+ (defun compile (V672 V673 V674)
76
+ (let O (V672 (@p V673 ()))
77
+ (if (or (= (fail) O) (not (empty? (fst O)))) (shen-compile-error O V674)
78
+ (snd O))))
79
+
80
+ (defun shen-compile-error (V687 V688)
81
+ (cond ((= () V688) (fail))
82
+ ((and (tuple? V687) (cons? (fst V687))) (V688 (fst V687)))
83
+ (true (interror "syntax error~%" ()))))
84
+
85
+ (defun <e> (V693)
86
+ (cond ((tuple? V693) (@p (fst V693) ())) (true (shen-sys-error <e>))))
87
+
88
+ (defun fail-if (V694 V695) (if (V694 V695) (fail) V695))
89
+
90
+ (defun @s (V696 V697) (cn V696 V697))
91
+
92
+ (defun tc? (V702) (value shen-*tc*))
93
+
94
+ (defun ps (V703)
95
+ (trap-error (get V703 shen-source (value shen-*property-vector*))
96
+ (lambda E (interror "~A not found.~%" (@p V703 ())))))
97
+
98
+ (defun explode (V704)
99
+ (if (string? V704) (shen-explode-string V704)
100
+ (explode (intmake-string "~A" (@p V704 ())))))
101
+
102
+ (defun shen-explode-string (V705)
103
+ (cond ((= "" V705) ())
104
+ (true
105
+ (let S (pos V705 0)
106
+ (let Ss (tlstr V705)
107
+ (if (= Ss shen-eos) () (cons S (shen-explode-string Ss))))))))
108
+
109
+ (defun stinput (V710) (value *stinput*))
110
+
111
+ (defun shen-+vector? (V711)
112
+ (and (absvector? V711) (> (<-address V711 0) 0)))
113
+
114
+ (defun vector (V712)
115
+ (let Vector (absvector (+ V712 1))
116
+ (let ZeroStamp (address-> Vector 0 V712)
117
+ (let Standard
118
+ (if (= V712 0) ZeroStamp (shen-fillvector ZeroStamp 1 V712 (fail)))
119
+ Standard))))
120
+
121
+ (defun shen-fillvector (V713 V714 V715 V716)
122
+ (cond ((= V715 V714) (address-> V713 V715 V716))
123
+ (true (shen-fillvector (address-> V713 V714 V716) (+ 1 V714) V715 V716))))
124
+
125
+ (defun vector? (V718)
126
+ (and (absvector? V718)
127
+ (trap-error (>= (<-address V718 0) 0) (lambda E false))))
128
+
129
+ (defun vector-> (V719 V720 V721)
130
+ (if (= V720 0) (interror "cannot access 0th element of a vector~%" ())
131
+ (address-> V719 V720 V721)))
132
+
133
+ (defun <-vector (V722 V723)
134
+ (if (= V723 0) (interror "cannot access 0th element of a vector~%" ())
135
+ (let VectorElement (<-address V722 V723)
136
+ (if (= VectorElement (fail)) (interror "vector element not found~%" ())
137
+ VectorElement))))
138
+
139
+ (defun shen-posint? (V724) (and (integer? V724) (>= V724 0)))
140
+
141
+ (defun limit (V725) (<-address V725 0))
142
+
143
+ (defun symbol? (V726)
144
+ (cond ((or (boolean? V726) (or (number? V726) (string? V726))) false)
145
+ (true
146
+ (trap-error (let Explode (explode V726) (shen-analyse-symbol? Explode))
147
+ (lambda E false)))))
148
+
149
+ (defun shen-analyse-symbol? (V727)
150
+ (cond ((cons? V727) (and (shen-alpha? (hd V727)) (shen-alphanums? (tl V727))))
151
+ (true (shen-sys-error shen-analyse-symbol?))))
152
+
153
+ (defun shen-alpha? (V728)
154
+ (element? V728
155
+ (cons "A"
156
+ (cons "B"
157
+ (cons "C"
158
+ (cons "D"
159
+ (cons "E"
160
+ (cons "F"
161
+ (cons "G"
162
+ (cons "H"
163
+ (cons "I"
164
+ (cons "J"
165
+ (cons "K"
166
+ (cons "L"
167
+ (cons "M"
168
+ (cons "N"
169
+ (cons "O"
170
+ (cons "P"
171
+ (cons "Q"
172
+ (cons "R"
173
+ (cons "S"
174
+ (cons "T"
175
+ (cons "U"
176
+ (cons "V"
177
+ (cons "W"
178
+ (cons "X"
179
+ (cons "Y"
180
+ (cons "Z"
181
+ (cons "a"
182
+ (cons "b"
183
+ (cons "c"
184
+ (cons "d"
185
+ (cons "e"
186
+ (cons "f"
187
+ (cons "g"
188
+ (cons "h"
189
+ (cons "i"
190
+ (cons "j"
191
+ (cons "k"
192
+ (cons "l"
193
+ (cons "m"
194
+ (cons "n"
195
+ (cons "o"
196
+ (cons "p"
197
+ (cons "q"
198
+ (cons "r"
199
+ (cons "s"
200
+ (cons "t"
201
+ (cons "u"
202
+ (cons "v"
203
+ (cons "w"
204
+ (cons "x"
205
+ (cons "y"
206
+ (cons "z"
207
+ (cons "="
208
+ (cons "*"
209
+ (cons "/"
210
+ (cons "+"
211
+ (cons "-"
212
+ (cons "_"
213
+ (cons "?"
214
+ (cons "$"
215
+ (cons "!"
216
+ (cons "@"
217
+ (cons "~"
218
+ (cons ">"
219
+ (cons "<"
220
+ (cons "&"
221
+ (cons "%"
222
+ (cons "{"
223
+ (cons "}"
224
+ (cons
225
+ ":"
226
+ (cons
227
+ ";"
228
+ (cons
229
+ "`"
230
+ (cons
231
+ "#"
232
+ (cons
233
+ "'"
234
+ (cons
235
+ "."
236
+ ())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
237
+
238
+ (defun shen-alphanums? (V729)
239
+ (cond ((= () V729) true)
240
+ ((cons? V729) (and (shen-alphanum? (hd V729)) (shen-alphanums? (tl V729))))
241
+ (true (shen-sys-error shen-alphanums?))))
242
+
243
+ (defun shen-alphanum? (V730) (or (shen-alpha? V730) (shen-digit? V730)))
244
+
245
+ (defun shen-digit? (V731)
246
+ (element? V731
247
+ (cons "1"
248
+ (cons "2"
249
+ (cons "3"
250
+ (cons "4"
251
+ (cons "5"
252
+ (cons "6" (cons "7" (cons "8" (cons "9" (cons "0" ()))))))))))))
253
+
254
+ (defun variable? (V732)
255
+ (cond ((or (boolean? V732) (or (number? V732) (string? V732))) false)
256
+ (true
257
+ (trap-error (let Explode (explode V732) (shen-analyse-variable? Explode))
258
+ (lambda E false)))))
259
+
260
+ (defun shen-analyse-variable? (V733)
261
+ (cond
262
+ ((cons? V733) (and (shen-uppercase? (hd V733)) (shen-alphanums? (tl V733))))
263
+ (true (shen-sys-error shen-analyse-variable?))))
264
+
265
+ (defun shen-uppercase? (V734)
266
+ (element? V734
267
+ (cons "A"
268
+ (cons "B"
269
+ (cons "C"
270
+ (cons "D"
271
+ (cons "E"
272
+ (cons "F"
273
+ (cons "G"
274
+ (cons "H"
275
+ (cons "I"
276
+ (cons "J"
277
+ (cons "K"
278
+ (cons "L"
279
+ (cons "M"
280
+ (cons "N"
281
+ (cons "O"
282
+ (cons "P"
283
+ (cons "Q"
284
+ (cons "R"
285
+ (cons "S"
286
+ (cons "T"
287
+ (cons "U"
288
+ (cons "V"
289
+ (cons "W"
290
+ (cons "X"
291
+ (cons "Y" (cons "Z" ()))))))))))))))))))))))))))))
292
+
293
+ (defun gensym (V735)
294
+ (concat V735 (set shen-*gensym* (+ 1 (value shen-*gensym*)))))
295
+
296
+ (defun concat (V736 V737) (intern (cn (str V736) (str V737))))
297
+
298
+ (defun @p (V738 V739)
299
+ (let Vector (absvector 3)
300
+ (let Tag (address-> Vector 0 shen-tuple)
301
+ (let Fst (address-> Vector 1 V738)
302
+ (let Snd (address-> Vector 2 V739) Vector)))))
303
+
304
+ (defun fst (V740) (<-address V740 1))
305
+
306
+ (defun snd (V741) (<-address V741 2))
307
+
308
+ (defun tuple? (V742)
309
+ (trap-error (and (absvector? V742) (= shen-tuple (<-address V742 0)))
310
+ (lambda E false)))
311
+
312
+ (defun append (V743 V744)
313
+ (cond ((= () V743) V744)
314
+ ((cons? V743) (cons (hd V743) (append (tl V743) V744)))
315
+ (true (shen-sys-error append))))
316
+
317
+ (defun @v (V745 V746)
318
+ (let Limit (limit V746)
319
+ (let NewVector (vector (+ Limit 1))
320
+ (let X+NewVector (vector-> NewVector 1 V745)
321
+ (if (= Limit 0) X+NewVector (shen-@v-help V746 1 Limit X+NewVector))))))
322
+
323
+ (defun shen-@v-help (V747 V748 V749 V750)
324
+ (cond ((= V749 V748) (shen-copyfromvector V747 V750 V749 (+ V749 1)))
325
+ (true
326
+ (shen-@v-help V747 (+ V748 1) V749
327
+ (shen-copyfromvector V747 V750 V748 (+ V748 1))))))
328
+
329
+ (defun shen-copyfromvector (V752 V753 V754 V755)
330
+ (trap-error (vector-> V753 V755 (<-vector V752 V754)) (lambda E V753)))
331
+
332
+ (defun hdv (V756)
333
+ (trap-error (<-vector V756 1)
334
+ (lambda E
335
+ (interror "hdv needs a non-empty vector as an argument; not ~S~%"
336
+ (@p V756 ())))))
337
+
338
+ (defun tlv (V757)
339
+ (let Limit (limit V757)
340
+ (if (= Limit 0)
341
+ (interror "cannot take the tail of the empty vector~%" ())
342
+ (if (= Limit 1) (vector 0)
343
+ (let NewVector (vector (- Limit 1))
344
+ (shen-tlv-help V757 2 Limit (vector (- Limit 1))))))))
345
+
346
+ (defun shen-tlv-help (V758 V759 V760 V761)
347
+ (cond ((= V760 V759) (shen-copyfromvector V758 V761 V760 (- V760 1)))
348
+ (true
349
+ (shen-tlv-help V758 (+ V759 1) V760
350
+ (shen-copyfromvector V758 V761 V759 (- V759 1))))))
351
+
352
+ (defun assoc (V771 V772)
353
+ (cond ((= () V772) ())
354
+ ((and (cons? V772) (and (cons? (hd V772)) (= (hd (hd V772)) V771)))
355
+ (hd V772))
356
+ ((cons? V772) (assoc V771 (tl V772))) (true (shen-sys-error assoc))))
357
+
358
+ (defun boolean? (V778)
359
+ (cond ((= true V778) true) ((= false V778) true) (true false)))
360
+
361
+ (defun nl (V779)
362
+ (cond ((= 0 V779) 0) (true (do (intoutput "~%" ()) (nl (- V779 1))))))
363
+
364
+ (defun difference (V782 V783)
365
+ (cond ((= () V782) ())
366
+ ((cons? V782)
367
+ (if (element? (hd V782) V783) (difference (tl V782) V783)
368
+ (cons (hd V782) (difference (tl V782) V783))))
369
+ (true (shen-sys-error difference))))
370
+
371
+ (defun do (V784 V785) V785)
372
+
373
+ (defun element? (V794 V795)
374
+ (cond ((= () V795) false) ((and (cons? V795) (= (hd V795) V794)) true)
375
+ ((cons? V795) (element? V794 (tl V795))) (true (shen-sys-error element?))))
376
+
377
+ (defun empty? (V801) (cond ((= () V801) true) (true false)))
378
+
379
+ (defun fix (V802 V803) (shen-fix-help V802 V803 (V802 V803)))
380
+
381
+ (defun shen-fix-help (V810 V811 V812)
382
+ (cond ((= V812 V811) V812) (true (shen-fix-help V810 V812 (V810 V812)))))
383
+
384
+ (defun put (V814 V815 V816 V817)
385
+ (let N (hash V814 (limit V817))
386
+ (let Entry (trap-error (<-vector V817 N) (lambda E ()))
387
+ (let Change
388
+ (vector-> V817 N (shen-change-pointer-value V814 V815 V816 Entry)) V816))))
389
+
390
+ (defun shen-change-pointer-value (V820 V821 V822 V823)
391
+ (cond ((= () V823) (cons (cons (cons V820 (cons V821 ())) V822) ()))
392
+ ((and (cons? V823)
393
+ (and (cons? (hd V823))
394
+ (and (cons? (hd (hd V823)))
395
+ (and (cons? (tl (hd (hd V823))))
396
+ (and (= () (tl (tl (hd (hd V823)))))
397
+ (and (= (hd (tl (hd (hd V823)))) V821)
398
+ (= (hd (hd (hd V823))) V820)))))))
399
+ (cons (cons (hd (hd V823)) V822) (tl V823)))
400
+ ((cons? V823)
401
+ (cons (hd V823) (shen-change-pointer-value V820 V821 V822 (tl V823))))
402
+ (true (shen-sys-error shen-change-pointer-value))))
403
+
404
+ (defun get (V826 V827 V828)
405
+ (let N (hash V826 (limit V828))
406
+ (let Entry
407
+ (trap-error (<-vector V828 N)
408
+ (lambda E (interror "pointer not found~%" ())))
409
+ (let Result (assoc (cons V826 (cons V827 ())) Entry)
410
+ (if (empty? Result) (interror "value not found~%" ()) (tl Result))))))
411
+
412
+ (defun hash (V829 V830)
413
+ (let Hash
414
+ (shen-mod (sum (map (lambda V831 (string->n V831)) (explode V829))) V830)
415
+ (if (= 0 Hash) 1 Hash)))
416
+
417
+ (defun shen-mod (V832 V833)
418
+ (shen-modh V832 (shen-multiples V832 (cons V833 ()))))
419
+
420
+ (defun shen-multiples (V834 V835)
421
+ (cond ((and (cons? V835) (> (hd V835) V834)) (tl V835))
422
+ ((cons? V835) (shen-multiples V834 (cons (* 2 (hd V835)) V835)))
423
+ (true (shen-sys-error shen-multiples))))
424
+
425
+ (defun shen-modh (V838 V839)
426
+ (cond ((= 0 V838) 0) ((= () V839) V838)
427
+ ((and (cons? V839) (> (hd V839) V838))
428
+ (if (empty? (tl V839)) V838 (shen-modh V838 (tl V839))))
429
+ ((cons? V839) (shen-modh (- V838 (hd V839)) V839))
430
+ (true (shen-sys-error shen-modh))))
431
+
432
+ (defun sum (V840)
433
+ (cond ((= () V840) 0) ((cons? V840) (+ (hd V840) (sum (tl V840))))
434
+ (true (shen-sys-error sum))))
435
+
436
+ (defun head (V847)
437
+ (cond ((cons? V847) (hd V847))
438
+ (true (interror "head expects a non-empty list" ()))))
439
+
440
+ (defun tail (V854)
441
+ (cond ((cons? V854) (tl V854))
442
+ (true (interror "tail expects a non-empty list" ()))))
443
+
444
+ (defun hdstr (V855) (pos V855 0))
445
+
446
+ (defun intersection (V858 V859)
447
+ (cond ((= () V858) ())
448
+ ((cons? V858)
449
+ (if (element? (hd V858) V859) (cons (hd V858) (intersection (tl V858) V859))
450
+ (intersection (tl V858) V859)))
451
+ (true (shen-sys-error intersection))))
452
+
453
+ (defun reverse (V860) (shen-reverse_help V860 ()))
454
+
455
+ (defun shen-reverse_help (V861 V862)
456
+ (cond ((= () V861) V862)
457
+ ((cons? V861) (shen-reverse_help (tl V861) (cons (hd V861) V862)))
458
+ (true (shen-sys-error shen-reverse_help))))
459
+
460
+ (defun union (V863 V864)
461
+ (cond ((= () V863) V864)
462
+ ((cons? V863)
463
+ (if (element? (hd V863) V864) (union (tl V863) V864)
464
+ (cons (hd V863) (union (tl V863) V864))))
465
+ (true (shen-sys-error union))))
466
+
467
+ (defun y-or-n? (V865)
468
+ (let Message (intoutput V865 ())
469
+ (let Y-or-N (intoutput " (y/n) " ())
470
+ (let Input (intmake-string "~S" (@p (input) ()))
471
+ (if (= "y" Input) true
472
+ (if (= "n" Input) false
473
+ (do (intoutput "please answer y or n~%" ()) (y-or-n? V865))))))))
474
+
475
+ (defun not (V866) (if V866 false true))
476
+
477
+ (defun subst (V875 V876 V877)
478
+ (cond ((= V877 V876) V875)
479
+ ((cons? V877) (cons (subst V875 V876 (hd V877)) (subst V875 V876 (tl V877))))
480
+ (true V877)))
481
+
482
+ (defun cd (V879)
483
+ (set *home-directory*
484
+ (if (= V879 "") "" (intmake-string "~A/" (@p V879 ())))))
485
+
486
+ (defun map (V880 V881) (shen-map-h V880 V881 ()))
487
+
488
+ (defun shen-map-h (V884 V885 V886)
489
+ (cond ((= () V885) (reverse V886))
490
+ ((cons? V885) (shen-map-h V884 (tl V885) (cons (V884 (hd V885)) V886)))
491
+ (true (shen-sys-error shen-map-h))))
492
+
493
+ (defun length (V887) (shen-length-h V887 0))
494
+
495
+ (defun shen-length-h (V888 V889)
496
+ (cond ((= () V888) V889) (true (shen-length-h (tl V888) (+ V889 1)))))
497
+
498
+ (defun occurrences (V898 V899)
499
+ (cond ((= V899 V898) 1)
500
+ ((cons? V899) (+ (occurrences V898 (hd V899)) (occurrences V898 (tl V899))))
501
+ (true 0)))
502
+
503
+ (defun nth (V907 V908)
504
+ (cond ((and (= 1 V907) (cons? V908)) (hd V908))
505
+ ((cons? V908) (nth (- V907 1) (tl V908))) (true (shen-sys-error nth))))
506
+
507
+ (defun integer? (V909)
508
+ (and (number? V909)
509
+ (let Abs (shen-abs V909) (shen-integer-test? Abs (shen-magless Abs 1)))))
510
+
511
+ (defun shen-abs (V910) (if (> V910 0) V910 (- 0 V910)))
512
+
513
+ (defun shen-magless (V911 V912)
514
+ (let Nx2 (* V912 2) (if (> Nx2 V911) V912 (shen-magless V911 Nx2))))
515
+
516
+ (defun shen-integer-test? (V916 V917)
517
+ (cond ((= 0 V916) true) ((> 1 V916) false)
518
+ (true
519
+ (let Abs-N (- V916 V917)
520
+ (if (> 0 Abs-N) (integer? V916) (shen-integer-test? Abs-N V917))))))
521
+
522
+ (defun mapcan (V920 V921)
523
+ (cond ((= () V921) ())
524
+ ((cons? V921) (append (V920 (hd V921)) (mapcan V920 (tl V921))))
525
+ (true (shen-sys-error mapcan))))
526
+
527
+ (defun read-file-as-bytelist (V922)
528
+ (let Stream (open file V922 in)
529
+ (let Byte (read-byte Stream)
530
+ (let Bytes (shen-read-file-as-bytelist-help Stream Byte ())
531
+ (let Close (close Stream) (reverse Bytes))))))
532
+
533
+ (defun shen-read-file-as-bytelist-help (V923 V924 V925)
534
+ (cond ((= -1 V924) V925)
535
+ (true
536
+ (shen-read-file-as-bytelist-help V923 (read-byte V923) (cons V924 V925)))))
537
+
538
+ (defun read-file-as-string (V926)
539
+ (let Stream (open file V926 in) (shen-rfas-h Stream (read-byte Stream) "")))
540
+
541
+ (defun shen-rfas-h (V927 V928 V929)
542
+ (cond ((= -1 V928) (do (close V927) V929))
543
+ (true (shen-rfas-h V927 (read-byte V927) (cn V929 (n->string V928))))))
544
+
545
+ (defun == (V938 V939) (cond ((= V939 V938) true) (true false)))
546
+
547
+ (defun abort () (simple-error ""))
548
+
549
+ (defun read () (hd (lineread)))
550
+
551
+ (defun input () (eval (read)))
552
+
553
+ (defun input+ (V945 V946)
554
+ (let Input (read)
555
+ (let Check (shen-typecheck Input V946)
556
+ (if (= false Check)
557
+ (do (intoutput "input is not of type ~R: please re-enter " (@p V946 ()))
558
+ (input+ : V946))
559
+ (eval Input)))))
560
+
561
+ (defun bound? (V947)
562
+ (and (symbol? V947)
563
+ (let Val (trap-error (value V947) (lambda E shen-this-symbol-is-unbound))
564
+ (if (= Val shen-this-symbol-is-unbound) false true))))
565
+
566
+ (defun shen-string->bytes (V948)
567
+ (cond ((= "" V948) ())
568
+ (true (cons (string->n (pos V948 0)) (shen-string->bytes (tlstr V948))))))
569
+
570
+ (defun maxinferences (V949) (set shen-*maxinferences* V949))
571
+
572
+ (defun inferences (V954) (value shen-*infs*))
573
+
574
+ (defun shen-hush (V959)
575
+ (cond ((= + V959) (set shen-*hush* shen-hushed))
576
+ ((= - V959) (set shen-*hush* shen-unhushed))
577
+ (true (interror "'hush' expects a + or a -~%" ()))))
578
+
579
+ (defun protect (V960) V960)
580
+
581
+ (defun shen-stoutput (V965) (value *stoutput*))
582
+