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,223 @@
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-shen () (do (shen-credits) (shen-loop)))
19
+
20
+ (defun shen-loop ()
21
+ (do (shen-initialise_environment)
22
+ (do (shen-prompt)
23
+ (do
24
+ (trap-error (shen-read-evaluate-print)
25
+ (lambda E (pr (error-to-string E) (value *stoutput*))))
26
+ (shen-loop)))))
27
+
28
+ (defun version (V568) (set *version* V568))
29
+
30
+ (version "version 7.1")
31
+
32
+ (defun shen-credits ()
33
+ (do (intoutput "~%Shen 2010, copyright (C) 2010 Mark Tarver~%" ())
34
+ (do (intoutput "www.shenlanguage.org, ~A~%" (@p (value *version*) ()))
35
+ (do
36
+ (intoutput "running under ~A, implementation: ~A"
37
+ (@p (value *language*) (@p (value *implementation*) ())))
38
+ (intoutput "~%port ~A ported by ~A~%"
39
+ (@p (value *port*) (@p (value *porters*) ())))))))
40
+
41
+ (defun shen-initialise_environment ()
42
+ (shen-multiple-set
43
+ (cons shen-*call*
44
+ (cons 0
45
+ (cons shen-*infs*
46
+ (cons 0
47
+ (cons shen-*process-counter*
48
+ (cons 0 (cons shen-*catch* (cons 0 ()))))))))))
49
+
50
+ (defun shen-multiple-set (V569)
51
+ (cond ((= () V569) ())
52
+ ((and (cons? V569) (cons? (tl V569)))
53
+ (do (set (hd V569) (hd (tl V569))) (shen-multiple-set (tl (tl V569)))))
54
+ (true (shen-sys-error shen-multiple-set))))
55
+
56
+ (defun destroy (V570) (declare V570 ()))
57
+
58
+ (set shen-*history* ())
59
+
60
+ (defun shen-read-evaluate-print ()
61
+ (let Lineread (shen-toplineread)
62
+ (let History (value shen-*history*)
63
+ (let NewLineread (shen-retrieve-from-history-if-needed Lineread History)
64
+ (let NewHistory (shen-update_history NewLineread History)
65
+ (let Parsed (fst NewLineread) (shen-toplevel Parsed)))))))
66
+
67
+ (defun shen-retrieve-from-history-if-needed (V580 V581)
68
+ (cond
69
+ ((and (tuple? V580)
70
+ (and (cons? (snd V580))
71
+ (and (cons? (tl (snd V580)))
72
+ (and (= () (tl (tl (snd V580))))
73
+ (and (cons? V581)
74
+ (and (= (hd (snd V580)) (shen-exclamation))
75
+ (= (hd (tl (snd V580))) (shen-exclamation))))))))
76
+ (let PastPrint (shen-prbytes (snd (hd V581))) (hd V581)))
77
+ ((and (tuple? V580)
78
+ (and (cons? (snd V580)) (= (hd (snd V580)) (shen-exclamation))))
79
+ (let Key? (shen-make-key (tl (snd V580)) V581)
80
+ (let Find (head (shen-find-past-inputs Key? V581))
81
+ (let PastPrint (shen-prbytes (snd Find)) Find))))
82
+ ((and (tuple? V580)
83
+ (and (cons? (snd V580))
84
+ (and (= () (tl (snd V580))) (= (hd (snd V580)) (shen-percent)))))
85
+ (do (shen-print-past-inputs (lambda X true) (reverse V581) 0) (abort)))
86
+ ((and (tuple? V580)
87
+ (and (cons? (snd V580)) (= (hd (snd V580)) (shen-percent))))
88
+ (let Key? (shen-make-key (tl (snd V580)) V581)
89
+ (let Pastprint (shen-print-past-inputs Key? (reverse V581) 0) (abort))))
90
+ (true V580)))
91
+
92
+ (defun shen-percent () 37)
93
+
94
+ (defun shen-exclamation () 33)
95
+
96
+ (defun shen-prbytes (V582)
97
+ (do (map (lambda Byte (pr (n->string Byte) (stinput 0))) V582) (nl 1)))
98
+
99
+ (defun shen-update_history (V583 V584) (set shen-*history* (cons V583 V584)))
100
+
101
+ (defun shen-toplineread ()
102
+ (shen-toplineread_loop (read-byte (stinput 0)) ()))
103
+
104
+ (defun shen-toplineread_loop (V586 V587)
105
+ (cond ((= V586 (shen-hat)) (interror "line read aborted" ()))
106
+ ((element? V586 (cons (shen-newline) (cons (shen-carriage-return) ())))
107
+ (let Line (compile (lambda V588 (shen-<st_input> V588)) V587 ())
108
+ (if (or (= Line (fail)) (empty? Line))
109
+ (shen-toplineread_loop (read-byte (stinput 0))
110
+ (append V587 (cons V586 ())))
111
+ (@p Line V587))))
112
+ (true
113
+ (shen-toplineread_loop (read-byte (stinput 0))
114
+ (append V587 (cons V586 ()))))))
115
+
116
+ (defun shen-hat () 94)
117
+
118
+ (defun shen-newline () 10)
119
+
120
+ (defun shen-carriage-return () 13)
121
+
122
+ (defun tc (V593)
123
+ (cond ((= + V593) (set shen-*tc* true))
124
+ ((= - V593) (set shen-*tc* false))
125
+ (true (interror "tc expects a + or -" ()))))
126
+
127
+ (defun shen-prompt ()
128
+ (if (value shen-*tc*)
129
+ (intoutput "~%~%(~A+) " (@p (length (value shen-*history*)) ()))
130
+ (intoutput "~%~%(~A-) " (@p (length (value shen-*history*)) ()))))
131
+
132
+ (defun shen-toplevel (V594) (shen-toplevel_evaluate V594 (value shen-*tc*)))
133
+
134
+ (defun shen-find-past-inputs (V595 V596)
135
+ (let F (shen-find V595 V596)
136
+ (if (empty? F) (interror "input not found~%" ()) F)))
137
+
138
+ (defun shen-make-key (V597 V598)
139
+ (let Atom (hd (compile (lambda V599 (shen-<st_input> V599)) V597 ()))
140
+ (if (integer? Atom) (lambda X (= X (nth (+ Atom 1) (reverse V598))))
141
+ (lambda X (shen-prefix? V597 (shen-trim-gubbins (snd X)))))))
142
+
143
+ (defun shen-trim-gubbins (V600)
144
+ (cond
145
+ ((and (cons? V600) (= (hd V600) (shen-space)))
146
+ (shen-trim-gubbins (tl V600)))
147
+ ((and (cons? V600) (= (hd V600) (shen-newline)))
148
+ (shen-trim-gubbins (tl V600)))
149
+ ((and (cons? V600) (= (hd V600) (shen-carriage-return)))
150
+ (shen-trim-gubbins (tl V600)))
151
+ ((and (cons? V600) (= (hd V600) (shen-tab)))
152
+ (shen-trim-gubbins (tl V600)))
153
+ ((and (cons? V600) (= (hd V600) (shen-left-round)))
154
+ (shen-trim-gubbins (tl V600)))
155
+ (true V600)))
156
+
157
+ (defun shen-space () 32)
158
+
159
+ (defun shen-tab () 9)
160
+
161
+ (defun shen-left-round () 40)
162
+
163
+ (defun shen-find (V607 V608)
164
+ (cond ((= () V608) ())
165
+ ((and (cons? V608) (V607 (hd V608)))
166
+ (cons (hd V608) (shen-find V607 (tl V608))))
167
+ ((cons? V608) (shen-find V607 (tl V608))) (true (shen-sys-error shen-find))))
168
+
169
+ (defun shen-prefix? (V619 V620)
170
+ (cond ((= () V619) true)
171
+ ((and (cons? V619) (and (cons? V620) (= (hd V620) (hd V619))))
172
+ (shen-prefix? (tl V619) (tl V620)))
173
+ (true false)))
174
+
175
+ (defun shen-print-past-inputs (V630 V631 V632)
176
+ (cond ((= () V631) _)
177
+ ((and (cons? V631) (not (V630 (hd V631))))
178
+ (shen-print-past-inputs V630 (tl V631) (+ V632 1)))
179
+ ((and (cons? V631) (tuple? (hd V631)))
180
+ (do (intoutput "~A. " (@p V632 ()))
181
+ (do (shen-prbytes (snd (hd V631)))
182
+ (shen-print-past-inputs V630 (tl V631) (+ V632 1)))))
183
+ (true (shen-sys-error shen-print-past-inputs))))
184
+
185
+ (defun shen-toplevel_evaluate (V633 V634)
186
+ (cond
187
+ ((and (cons? V633)
188
+ (and (cons? (tl V633))
189
+ (and (= : (hd (tl V633)))
190
+ (and (cons? (tl (tl V633)))
191
+ (and (= () (tl (tl (tl V633)))) (= true V634))))))
192
+ (shen-typecheck-and-evaluate (hd V633) (hd (tl (tl V633)))))
193
+ ((and (cons? V633) (cons? (tl V633)))
194
+ (do (shen-toplevel_evaluate (cons (hd V633) ()) V634)
195
+ (do (nl 1) (shen-toplevel_evaluate (tl V633) V634))))
196
+ ((and (cons? V633) (and (= () (tl V633)) (= true V634)))
197
+ (shen-typecheck-and-evaluate (hd V633) (gensym A)))
198
+ ((and (cons? V633) (and (= () (tl V633)) (= false V634)))
199
+ (let Eval (shen-eval-without-macros (hd V633)) (print Eval)))
200
+ (true (shen-sys-error shen-toplevel_evaluate))))
201
+
202
+ (defun shen-typecheck-and-evaluate (V635 V636)
203
+ (let Typecheck (shen-typecheck V635 V636)
204
+ (if (= Typecheck false) (interror "type error~%" ())
205
+ (let Eval (shen-eval-without-macros V635)
206
+ (let Type (shen-pretty-type Typecheck)
207
+ (intoutput "~S : ~R" (@p Eval (@p Type ()))))))))
208
+
209
+ (defun shen-pretty-type (V637)
210
+ (shen-mult_subst (value shen-*alphabet*) (shen-extract-pvars V637) V637))
211
+
212
+ (defun shen-extract-pvars (V642)
213
+ (cond ((shen-pvar? V642) (cons V642 ()))
214
+ ((cons? V642)
215
+ (union (shen-extract-pvars (hd V642)) (shen-extract-pvars (tl V642))))
216
+ (true ())))
217
+
218
+ (defun shen-mult_subst (V647 V648 V649)
219
+ (cond ((= () V647) V649) ((= () V648) V649)
220
+ ((and (cons? V647) (cons? V648))
221
+ (shen-mult_subst (tl V647) (tl V648) (subst (hd V647) (hd V648) V649)))
222
+ (true (shen-sys-error shen-mult_subst))))
223
+
@@ -0,0 +1,208 @@
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-f_error (V1123)
19
+ (do (intoutput "partial function ~A;~%" (@p V1123 ()))
20
+ (do
21
+ (if
22
+ (and (not (shen-tracked? V1123))
23
+ (y-or-n? (intmake-string "track ~A? " (@p V1123 ()))))
24
+ (shen-track-function (ps V1123)) shen-ok)
25
+ (simple-error "aborted"))))
26
+
27
+ (defun shen-tracked? (V1124) (element? V1124 (value shen-*tracking*)))
28
+
29
+ (defun track (V1125) (let Source (ps V1125) (shen-track-function Source)))
30
+
31
+ (defun shen-track-function (V1126)
32
+ (cond
33
+ ((and (cons? V1126)
34
+ (and (= defun (hd V1126))
35
+ (and (cons? (tl V1126))
36
+ (and (cons? (tl (tl V1126)))
37
+ (and (cons? (tl (tl (tl V1126))))
38
+ (= () (tl (tl (tl (tl V1126))))))))))
39
+ (let KL
40
+ (cons defun
41
+ (cons (hd (tl V1126))
42
+ (cons (hd (tl (tl V1126)))
43
+ (cons
44
+ (shen-insert-tracking-code (hd (tl V1126)) (hd (tl (tl V1126)))
45
+ (hd (tl (tl (tl V1126)))))
46
+ ()))))
47
+ (let Ob (eval KL)
48
+ (let Tr (set shen-*tracking* (cons Ob (value shen-*tracking*))) Ob))))
49
+ (true (shen-sys-error shen-track-function))))
50
+
51
+ (defun shen-insert-tracking-code (V1127 V1128 V1129)
52
+ (cons do
53
+ (cons
54
+ (cons set
55
+ (cons shen-*call*
56
+ (cons (cons + (cons (cons value (cons shen-*call* ())) (cons 1 ())))
57
+ ())))
58
+ (cons
59
+ (cons do
60
+ (cons
61
+ (cons shen-input-track
62
+ (cons (cons value (cons shen-*call* ()))
63
+ (cons V1127 (cons (shen-cons_form V1128) ()))))
64
+ (cons
65
+ (cons do
66
+ (cons (cons shen-terpri-or-read-char ())
67
+ (cons
68
+ (cons let
69
+ (cons Result
70
+ (cons V1129
71
+ (cons
72
+ (cons do
73
+ (cons
74
+ (cons shen-output-track
75
+ (cons (cons value (cons shen-*call* ()))
76
+ (cons V1127 (cons Result ()))))
77
+ (cons
78
+ (cons do
79
+ (cons
80
+ (cons set
81
+ (cons shen-*call*
82
+ (cons
83
+ (cons -
84
+ (cons (cons value (cons shen-*call* ())) (cons 1 ())))
85
+ ())))
86
+ (cons
87
+ (cons do
88
+ (cons (cons shen-terpri-or-read-char ())
89
+ (cons Result ())))
90
+ ())))
91
+ ())))
92
+ ()))))
93
+ ())))
94
+ ())))
95
+ ()))))
96
+
97
+ (set shen-*step* false)
98
+
99
+ (defun step (V1134)
100
+ (cond ((= + V1134) (set shen-*step* true))
101
+ ((= - V1134) (set shen-*step* false))
102
+ (true (interror "step expects a + or a -.~%" ()))))
103
+
104
+ (defun spy (V1139)
105
+ (cond ((= + V1139) (set shen-*spy* true))
106
+ ((= - V1139) (set shen-*spy* false))
107
+ (true (interror "spy expects a + or a -.~%" ()))))
108
+
109
+ (defun shen-terpri-or-read-char ()
110
+ (if (value shen-*step*) (shen-check-byte (read-byte (value *stinput*)))
111
+ (nl 1)))
112
+
113
+ (defun shen-check-byte (V1144)
114
+ (cond ((= V1144 (shen-hat)) (interror "aborted" ())) (true true)))
115
+
116
+ (defun shen-input-track (V1145 V1146 V1147)
117
+ (do
118
+ (intoutput "~%~A<~A> Inputs to ~A ~%~A"
119
+ (@p (shen-spaces V1145)
120
+ (@p V1145 (@p V1146 (@p (shen-spaces V1145) (@p V1147 ()))))))
121
+ (shen-recursively-print V1147)))
122
+
123
+ (defun shen-recursively-print (V1148)
124
+ (cond ((= () V1148) (intoutput " ==>" ()))
125
+ ((cons? V1148)
126
+ (do (print (hd V1148))
127
+ (do (intoutput ", " ()) (shen-recursively-print (tl V1148)))))
128
+ (true (shen-sys-error shen-recursively-print))))
129
+
130
+ (defun shen-spaces (V1149)
131
+ (cond ((= 0 V1149) "") (true (cn " " (shen-spaces (- V1149 1))))))
132
+
133
+ (defun shen-output-track (V1150 V1151 V1152)
134
+ (intoutput "~%~A<~A> Output from ~A ~%~A==> ~S"
135
+ (@p (shen-spaces V1150)
136
+ (@p V1150 (@p V1151 (@p (shen-spaces V1150) (@p V1152 ())))))))
137
+
138
+ (defun untrack (V1153) (eval (ps V1153)))
139
+
140
+ (defun profile (V1154) (shen-profile-help (ps V1154)))
141
+
142
+ (defun shen-profile-help (V1159)
143
+ (cond
144
+ ((and (cons? V1159)
145
+ (and (= defun (hd V1159))
146
+ (and (cons? (tl V1159))
147
+ (and (cons? (tl (tl V1159)))
148
+ (and (cons? (tl (tl (tl V1159))))
149
+ (= () (tl (tl (tl (tl V1159))))))))))
150
+ (let G (gensym shen-f)
151
+ (let Profile
152
+ (cons defun
153
+ (cons (hd (tl V1159))
154
+ (cons (hd (tl (tl V1159)))
155
+ (cons
156
+ (shen-profile-func (hd (tl V1159)) (hd (tl (tl V1159)))
157
+ (cons G (hd (tl (tl V1159)))))
158
+ ()))))
159
+ (let Def
160
+ (cons defun
161
+ (cons G
162
+ (cons (hd (tl (tl V1159)))
163
+ (cons (subst G (hd (tl V1159)) (hd (tl (tl (tl V1159))))) ()))))
164
+ (let CompileProfile (shen-eval-without-macros Profile)
165
+ (let CompileG (shen-eval-without-macros Def) (hd (tl V1159))))))))
166
+ (true (interror "Cannot profile.~%" ()))))
167
+
168
+ (defun unprofile (V1160) (untrack V1160))
169
+
170
+ (defun shen-profile-func (V1161 V1162 V1163)
171
+ (cons let
172
+ (cons Start
173
+ (cons (cons get-time (cons run ()))
174
+ (cons
175
+ (cons let
176
+ (cons Result
177
+ (cons V1163
178
+ (cons
179
+ (cons let
180
+ (cons Finish
181
+ (cons
182
+ (cons - (cons (cons get-time (cons run ())) (cons Start ())))
183
+ (cons
184
+ (cons let
185
+ (cons Record
186
+ (cons
187
+ (cons shen-put-profile
188
+ (cons V1161
189
+ (cons
190
+ (cons +
191
+ (cons (cons shen-get-profile (cons V1161 ()))
192
+ (cons Finish ())))
193
+ ())))
194
+ (cons Result ()))))
195
+ ()))))
196
+ ()))))
197
+ ())))))
198
+
199
+ (defun profile-results (V1164)
200
+ (let Results (shen-get-profile V1164)
201
+ (let Initialise (shen-put-profile V1164 0) (@p V1164 Results))))
202
+
203
+ (defun shen-get-profile (V1165)
204
+ (trap-error (get V1165 profile (value shen-*property-vector*)) (lambda E 0)))
205
+
206
+ (defun shen-put-profile (V1166 V1167)
207
+ (put V1166 profile V1167 (value shen-*property-vector*)))
208
+
@@ -0,0 +1,455 @@
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 declare (V1681 V1682)
19
+ (let Record (set shen-*signedfuncs* (adjoin V1681 (value shen-*signedfuncs*)))
20
+ (let Variancy
21
+ (trap-error (shen-variancy-test V1681 V1682) (lambda E shen-skip))
22
+ (let Type (shen-rcons_form (shen-normalise-type V1682))
23
+ (let F* (concat shen-type-signature-of- V1681)
24
+ (let Parameters (shen-parameters 1)
25
+ (let Clause
26
+ (cons (cons F* (cons X ()))
27
+ (cons :- (cons (cons (cons unify! (cons X (cons Type ()))) ()) ())))
28
+ (let AUM_instruction (shen-aum Clause Parameters)
29
+ (let Code (shen-aum_to_shen AUM_instruction)
30
+ (let ShenDef
31
+ (cons define
32
+ (cons F*
33
+ (append Parameters
34
+ (append (cons ProcessN (cons Continuation ()))
35
+ (cons -> (cons Code ()))))))
36
+ (let Eval (shen-eval-without-macros ShenDef) V1681)))))))))))
37
+
38
+ (defun shen-normalise-type (V1683)
39
+ (fix (lambda V1684 (shen-normalise-type-help V1684)) V1683))
40
+
41
+ (defun shen-normalise-type-help (V1685)
42
+ (cond
43
+ ((cons? V1685)
44
+ (shen-normalise-X
45
+ (map (lambda V1686 (shen-normalise-type-help V1686)) V1685)))
46
+ (true (shen-normalise-X V1685))))
47
+
48
+ (defun shen-normalise-X (V1687)
49
+ (let Val (assoc V1687 (value shen-*synonyms*))
50
+ (if (empty? Val) V1687 (tl Val))))
51
+
52
+ (defun shen-variancy-test (V1688 V1689)
53
+ (let TypeF (shen-typecheck V1688 B)
54
+ (let Check
55
+ (if (= symbol TypeF) shen-skip
56
+ (if (shen-variant? TypeF V1689) shen-skip
57
+ (intoutput "warning: changing the type of ~A may create errors~%"
58
+ (@p V1688 ()))))
59
+ shen-skip)))
60
+
61
+ (defun shen-variant? (V1698 V1699)
62
+ (cond ((= V1699 V1698) true)
63
+ ((and (cons? V1698) (and (cons? V1699) (= (hd V1699) (hd V1698))))
64
+ (shen-variant? (tl V1698) (tl V1699)))
65
+ ((and (cons? V1698)
66
+ (and (cons? V1699) (and (shen-pvar? (hd V1698)) (variable? (hd V1699)))))
67
+ (shen-variant? (subst shen-a (hd V1698) (tl V1698))
68
+ (subst shen-a (hd V1699) (tl V1699))))
69
+ ((and (cons? V1698)
70
+ (and (cons? (hd V1698)) (and (cons? V1699) (cons? (hd V1699)))))
71
+ (shen-variant? (append (hd V1698) (tl V1698))
72
+ (append (hd V1699) (tl V1699))))
73
+ (true false)))
74
+
75
+ (declare absvector? (cons A (cons --> (cons boolean ()))))
76
+
77
+ (declare adjoin
78
+ (cons A
79
+ (cons -->
80
+ (cons
81
+ (cons (cons list (cons A ()))
82
+ (cons --> (cons (cons list (cons A ())) ())))
83
+ ()))))
84
+
85
+ (declare and
86
+ (cons boolean
87
+ (cons --> (cons (cons boolean (cons --> (cons boolean ()))) ()))))
88
+
89
+ (declare append
90
+ (cons (cons list (cons A ()))
91
+ (cons -->
92
+ (cons
93
+ (cons (cons list (cons A ()))
94
+ (cons --> (cons (cons list (cons A ())) ())))
95
+ ()))))
96
+
97
+ (declare arity (cons A (cons --> (cons number ()))))
98
+
99
+ (declare assoc
100
+ (cons A
101
+ (cons -->
102
+ (cons
103
+ (cons (cons list (cons (cons list (cons A ())) ()))
104
+ (cons --> (cons (cons list (cons A ())) ())))
105
+ ()))))
106
+
107
+ (declare boolean? (cons A (cons --> (cons boolean ()))))
108
+
109
+ (declare bound? (cons symbol (cons --> (cons boolean ()))))
110
+
111
+ (declare cd (cons string (cons --> (cons string ()))))
112
+
113
+ (declare close
114
+ (cons (cons stream (cons A ()))
115
+ (cons --> (cons (cons list (cons B ())) ()))))
116
+
117
+ (declare cn
118
+ (cons string
119
+ (cons --> (cons (cons string (cons --> (cons string ()))) ()))))
120
+
121
+ (declare concat
122
+ (cons symbol
123
+ (cons --> (cons (cons symbol (cons --> (cons symbol ()))) ()))))
124
+
125
+ (declare cons? (cons A (cons --> (cons boolean ()))))
126
+
127
+ (declare destroy
128
+ (cons (cons A (cons --> (cons B ())))
129
+ (cons --> (cons (cons A (cons --> (cons B ()))) ()))))
130
+
131
+ (declare difference
132
+ (cons (cons list (cons A ()))
133
+ (cons -->
134
+ (cons
135
+ (cons (cons list (cons A ()))
136
+ (cons --> (cons (cons list (cons A ())) ())))
137
+ ()))))
138
+
139
+ (declare do (cons A (cons --> (cons (cons B (cons --> (cons B ()))) ()))))
140
+
141
+ (declare element?
142
+ (cons A
143
+ (cons -->
144
+ (cons (cons (cons list (cons A ())) (cons --> (cons boolean ()))) ()))))
145
+
146
+ (declare empty? (cons A (cons --> (cons boolean ()))))
147
+
148
+ (declare enable-type-theory (cons symbol (cons --> (cons boolean ()))))
149
+
150
+ (declare external
151
+ (cons symbol (cons --> (cons (cons list (cons symbol ())) ()))))
152
+
153
+ (declare interror
154
+ (cons string (cons --> (cons (cons A (cons --> (cons B ()))) ()))))
155
+
156
+ (declare error-to-string (cons exception (cons --> (cons string ()))))
157
+
158
+ (declare explode (cons A (cons --> (cons (cons list (cons string ())) ()))))
159
+
160
+ (declare fail-if
161
+ (cons (cons symbol (cons --> (cons boolean ())))
162
+ (cons --> (cons (cons symbol (cons --> (cons symbol ()))) ()))))
163
+
164
+ (declare fix
165
+ (cons (cons A (cons --> (cons A ())))
166
+ (cons --> (cons (cons A (cons --> (cons A ()))) ()))))
167
+
168
+ (declare format
169
+ (cons (cons stream (cons out ()))
170
+ (cons -->
171
+ (cons
172
+ (cons string (cons --> (cons (cons A (cons --> (cons string ()))) ())))
173
+ ()))))
174
+
175
+ (declare freeze (cons A (cons --> (cons (cons lazy (cons A ())) ()))))
176
+
177
+ (declare fst (cons (cons A (cons * (cons B ()))) (cons --> (cons A ()))))
178
+
179
+ (declare gensym (cons symbol (cons --> (cons symbol ()))))
180
+
181
+ (declare <-vector
182
+ (cons (cons vector (cons A ()))
183
+ (cons --> (cons (cons number (cons --> (cons A ()))) ()))))
184
+
185
+ (declare vector->
186
+ (cons (cons vector (cons A ()))
187
+ (cons -->
188
+ (cons
189
+ (cons number
190
+ (cons -->
191
+ (cons (cons A (cons --> (cons (cons vector (cons A ())) ()))) ())))
192
+ ()))))
193
+
194
+ (declare vector (cons number (cons --> (cons (cons vector (cons A ())) ()))))
195
+
196
+ (declare get-time (cons symbol (cons --> (cons number ()))))
197
+
198
+ (declare hash
199
+ (cons A (cons --> (cons (cons number (cons --> (cons number ()))) ()))))
200
+
201
+ (declare head (cons (cons list (cons A ())) (cons --> (cons A ()))))
202
+
203
+ (declare hdv (cons (cons vector (cons A ())) (cons --> (cons A ()))))
204
+
205
+ (declare hdstr (cons string (cons --> (cons string ()))))
206
+
207
+ (declare if
208
+ (cons boolean
209
+ (cons -->
210
+ (cons (cons A (cons --> (cons (cons A (cons --> (cons A ()))) ())))
211
+ ()))))
212
+
213
+ (declare include
214
+ (cons (cons list (cons symbol ()))
215
+ (cons --> (cons (cons list (cons symbol ())) ()))))
216
+
217
+ (declare include-all-but
218
+ (cons (cons list (cons symbol ()))
219
+ (cons --> (cons (cons list (cons symbol ())) ()))))
220
+
221
+ (declare inferences (cons A (cons --> (cons number ()))))
222
+
223
+ (declare integer? (cons A (cons --> (cons boolean ()))))
224
+
225
+ (declare intersection
226
+ (cons (cons list (cons A ()))
227
+ (cons -->
228
+ (cons
229
+ (cons (cons list (cons A ()))
230
+ (cons --> (cons (cons list (cons A ())) ())))
231
+ ()))))
232
+
233
+ (declare length (cons (cons list (cons A ())) (cons --> (cons number ()))))
234
+
235
+ (declare limit (cons (cons vector (cons A ())) (cons --> (cons number ()))))
236
+
237
+ (declare load (cons string (cons --> (cons symbol ()))))
238
+
239
+ (declare intmake-string
240
+ (cons string (cons --> (cons (cons A (cons --> (cons string ()))) ()))))
241
+
242
+ (declare map
243
+ (cons (cons A (cons --> (cons B ())))
244
+ (cons -->
245
+ (cons
246
+ (cons (cons list (cons A ()))
247
+ (cons --> (cons (cons list (cons B ())) ())))
248
+ ()))))
249
+
250
+ (declare mapcan
251
+ (cons (cons A (cons --> (cons (cons list (cons B ())) ())))
252
+ (cons -->
253
+ (cons
254
+ (cons (cons list (cons A ()))
255
+ (cons --> (cons (cons list (cons B ())) ())))
256
+ ()))))
257
+
258
+ (declare maxinferences (cons number (cons --> (cons number ()))))
259
+
260
+ (declare n->string (cons number (cons --> (cons string ()))))
261
+
262
+ (declare nl (cons number (cons --> (cons number ()))))
263
+
264
+ (declare not (cons boolean (cons --> (cons boolean ()))))
265
+
266
+ (declare nth
267
+ (cons number
268
+ (cons -->
269
+ (cons (cons (cons list (cons A ())) (cons --> (cons A ()))) ()))))
270
+
271
+ (declare number? (cons A (cons --> (cons boolean ()))))
272
+
273
+ (declare occurrences
274
+ (cons A (cons --> (cons (cons B (cons --> (cons number ()))) ()))))
275
+
276
+ (declare occurs-check (cons symbol (cons --> (cons boolean ()))))
277
+
278
+ (declare or
279
+ (cons boolean
280
+ (cons --> (cons (cons boolean (cons --> (cons boolean ()))) ()))))
281
+
282
+ (declare intoutput
283
+ (cons string (cons --> (cons (cons A (cons --> (cons string ()))) ()))))
284
+
285
+ (declare pos
286
+ (cons string
287
+ (cons --> (cons (cons number (cons --> (cons string ()))) ()))))
288
+
289
+ (declare pr
290
+ (cons string
291
+ (cons -->
292
+ (cons (cons (cons stream (cons out ())) (cons --> (cons string ())))
293
+ ()))))
294
+
295
+ (declare print (cons A (cons --> (cons A ()))))
296
+
297
+ (declare profile
298
+ (cons (cons A (cons --> (cons B ())))
299
+ (cons --> (cons (cons A (cons --> (cons B ()))) ()))))
300
+
301
+ (declare preclude
302
+ (cons (cons list (cons symbol ()))
303
+ (cons --> (cons (cons list (cons symbol ())) ()))))
304
+
305
+ (declare profile-results (cons A (cons --> (cons symbol ()))))
306
+
307
+ (declare protect (cons symbol (cons --> (cons symbol ()))))
308
+
309
+ (declare preclude-all-but
310
+ (cons (cons list (cons symbol ()))
311
+ (cons --> (cons (cons list (cons symbol ())) ()))))
312
+
313
+ (declare read-byte
314
+ (cons (cons stream (cons in ())) (cons --> (cons number ()))))
315
+
316
+ (declare read-file
317
+ (cons string (cons --> (cons (cons list (cons unit ())) ()))))
318
+
319
+ (declare read-file-as-bytelist
320
+ (cons string (cons --> (cons (cons list (cons number ())) ()))))
321
+
322
+ (declare read-file-as-string (cons string (cons --> (cons string ()))))
323
+
324
+ (declare remove
325
+ (cons A
326
+ (cons -->
327
+ (cons
328
+ (cons (cons list (cons A ()))
329
+ (cons --> (cons (cons list (cons A ())) ())))
330
+ ()))))
331
+
332
+ (declare reverse
333
+ (cons (cons list (cons A ()))
334
+ (cons --> (cons (cons list (cons A ())) ()))))
335
+
336
+ (declare simple-error (cons string (cons --> (cons A ()))))
337
+
338
+ (declare snd (cons (cons A (cons * (cons B ()))) (cons --> (cons B ()))))
339
+
340
+ (declare specialise (cons symbol (cons --> (cons symbol ()))))
341
+
342
+ (declare spy (cons symbol (cons --> (cons boolean ()))))
343
+
344
+ (declare step (cons symbol (cons --> (cons boolean ()))))
345
+
346
+ (declare stinput (cons A (cons --> (cons (cons stream (cons in ())) ()))))
347
+
348
+ (declare shen-stoutput
349
+ (cons A (cons --> (cons (cons stream (cons out ())) ()))))
350
+
351
+ (declare string? (cons A (cons --> (cons boolean ()))))
352
+
353
+ (declare sum (cons (cons list (cons number ())) (cons --> (cons number ()))))
354
+
355
+ (declare str (cons A (cons --> (cons string ()))))
356
+
357
+ (declare string->n (cons string (cons --> (cons number ()))))
358
+
359
+ (declare symbol? (cons A (cons --> (cons boolean ()))))
360
+
361
+ (declare systemf
362
+ (cons symbol (cons --> (cons (cons list (cons symbol ())) ()))))
363
+
364
+ (declare tail
365
+ (cons (cons list (cons A ()))
366
+ (cons --> (cons (cons list (cons A ())) ()))))
367
+
368
+ (declare tlstr (cons string (cons --> (cons string ()))))
369
+
370
+ (declare tlv
371
+ (cons (cons vector (cons A ()))
372
+ (cons --> (cons (cons vector (cons A ())) ()))))
373
+
374
+ (declare tc (cons symbol (cons --> (cons boolean ()))))
375
+
376
+ (declare tc? (cons A (cons --> (cons boolean ()))))
377
+
378
+ (declare thaw (cons (cons lazy (cons A ())) (cons --> (cons A ()))))
379
+
380
+ (declare track (cons symbol (cons --> (cons symbol ()))))
381
+
382
+ (declare trap-error
383
+ (cons A
384
+ (cons -->
385
+ (cons
386
+ (cons (cons exception (cons --> (cons A ()))) (cons --> (cons A ())))
387
+ ()))))
388
+
389
+ (declare tuple? (cons A (cons --> (cons boolean ()))))
390
+
391
+ (declare union
392
+ (cons (cons list (cons A ()))
393
+ (cons -->
394
+ (cons
395
+ (cons (cons list (cons A ()))
396
+ (cons --> (cons (cons list (cons A ())) ())))
397
+ ()))))
398
+
399
+ (declare unprofile
400
+ (cons (cons A (cons --> (cons B ())))
401
+ (cons --> (cons (cons A (cons --> (cons B ()))) ()))))
402
+
403
+ (declare untrack (cons symbol (cons --> (cons symbol ()))))
404
+
405
+ (declare unspecialise (cons symbol (cons --> (cons symbol ()))))
406
+
407
+ (declare variable? (cons A (cons --> (cons boolean ()))))
408
+
409
+ (declare vector? (cons A (cons --> (cons boolean ()))))
410
+
411
+ (declare version (cons string (cons --> (cons string ()))))
412
+
413
+ (declare write-to-file
414
+ (cons string (cons --> (cons (cons A (cons --> (cons A ()))) ()))))
415
+
416
+ (declare y-or-n? (cons string (cons --> (cons boolean ()))))
417
+
418
+ (declare >
419
+ (cons number
420
+ (cons --> (cons (cons number (cons --> (cons boolean ()))) ()))))
421
+
422
+ (declare <
423
+ (cons number
424
+ (cons --> (cons (cons number (cons --> (cons boolean ()))) ()))))
425
+
426
+ (declare >=
427
+ (cons number
428
+ (cons --> (cons (cons number (cons --> (cons boolean ()))) ()))))
429
+
430
+ (declare <=
431
+ (cons number
432
+ (cons --> (cons (cons number (cons --> (cons boolean ()))) ()))))
433
+
434
+ (declare =
435
+ (cons A (cons --> (cons (cons A (cons --> (cons boolean ()))) ()))))
436
+
437
+ (declare +
438
+ (cons number
439
+ (cons --> (cons (cons number (cons --> (cons number ()))) ()))))
440
+
441
+ (declare /
442
+ (cons number
443
+ (cons --> (cons (cons number (cons --> (cons number ()))) ()))))
444
+
445
+ (declare -
446
+ (cons number
447
+ (cons --> (cons (cons number (cons --> (cons number ()))) ()))))
448
+
449
+ (declare *
450
+ (cons number
451
+ (cons --> (cons (cons number (cons --> (cons number ()))) ()))))
452
+
453
+ (declare ==
454
+ (cons A (cons --> (cons (cons B (cons --> (cons boolean ()))) ()))))
455
+