nydp 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -13
- data/lib/lisp/core-015-documentation.nydp +11 -2
- data/lib/lisp/core-030-syntax.nydp +52 -8
- data/lib/lisp/core-040-utils.nydp +35 -47
- data/lib/lisp/core-045-dox-utils.nydp +85 -0
- data/lib/lisp/core-050-test-runner.nydp +20 -2
- data/lib/lisp/core-080-pretty-print.nydp +5 -1
- data/lib/lisp/tests/boot-tests.nydp +125 -255
- data/lib/lisp/tests/car-examples.nydp +16 -0
- data/lib/lisp/tests/collect-tests.nydp +28 -0
- data/lib/lisp/tests/cons-examples.nydp +8 -0
- data/lib/lisp/tests/curry-tests.nydp +17 -18
- data/lib/lisp/tests/detect-examples.nydp +24 -0
- data/lib/lisp/tests/dot-syntax-examples.nydp +40 -0
- data/lib/lisp/tests/dox-tests.nydp +116 -100
- data/lib/lisp/tests/dynamic-scope-test.nydp +10 -10
- data/lib/lisp/tests/each-tests.nydp +4 -5
- data/lib/lisp/tests/error-tests.nydp +17 -16
- data/lib/lisp/tests/explain-mac-examples.nydp +24 -0
- data/lib/lisp/tests/foundation-test.nydp +57 -223
- data/lib/lisp/tests/hash-examples.nydp +41 -0
- data/lib/lisp/tests/isa-examples.nydp +7 -0
- data/lib/lisp/tests/len-examples.nydp +11 -0
- data/lib/lisp/tests/list-tests.nydp +110 -75
- data/lib/lisp/tests/parser-tests.nydp +67 -109
- data/lib/lisp/tests/pretty-print-tests.nydp +19 -20
- data/lib/lisp/tests/quasiquote-examples.nydp +10 -0
- data/lib/lisp/tests/rfnwith-tests.nydp +7 -0
- data/lib/lisp/tests/string-tests.nydp +60 -31
- data/lib/lisp/tests/syntax-tests.nydp +22 -24
- data/lib/lisp/tests/type-of-examples.nydp +48 -0
- data/lib/lisp/tests/unparse-tests.nydp +2 -3
- data/lib/nydp.rb +2 -1
- data/lib/nydp/version.rb +1 -1
- metadata +14 -1
@@ -30,11 +30,29 @@
|
|
30
30
|
(if (iso result expected)
|
31
31
|
(passf)
|
32
32
|
(do (p desc " - " (car test) " - FAILED:
|
33
|
+
running " (pp (nth 1 test)) ",
|
33
34
|
expected " (inspect expected) ",
|
34
35
|
got " (inspect result) "
|
35
36
|
")
|
36
37
|
(failf)))))
|
37
38
|
|
38
39
|
(def execute-tests (desc tests passf failf verbose)
|
39
|
-
(execute-test desc
|
40
|
-
|
40
|
+
(execute-test desc
|
41
|
+
(car tests)
|
42
|
+
passf
|
43
|
+
failf
|
44
|
+
verbose)
|
45
|
+
(if (cdr tests)
|
46
|
+
(execute-tests desc
|
47
|
+
(cdr tests)
|
48
|
+
passf
|
49
|
+
failf
|
50
|
+
verbose)))
|
51
|
+
|
52
|
+
(mac examples-for (name . examples)
|
53
|
+
(let suite-name "examples for ~(pp name)"
|
54
|
+
`(do
|
55
|
+
(register-test '(suite ,suite-name ,@examples))
|
56
|
+
(dox-add-examples ',name
|
57
|
+
',(collect (curry !caris 'comment)
|
58
|
+
examples)))))
|
@@ -25,12 +25,16 @@
|
|
25
25
|
(inspect thing)))
|
26
26
|
|
27
27
|
(mac pp/def (name args . body)
|
28
|
+
; define a pretty-printer function for forms beginning with the
|
29
|
+
; given name. 'args are usually (form indent), form being the
|
30
|
+
; complete form for pretty-printing, and indent being the current
|
31
|
+
; indent level.
|
28
32
|
`(do
|
29
33
|
(hash-set pp/special-forms ',name
|
30
34
|
(fn ,args ,@body))
|
31
35
|
(dox-add-doc ',name
|
32
36
|
'pp/def
|
33
|
-
|
37
|
+
(list "pretty-printer for forms starting with ~(quote ,name)")
|
34
38
|
',args
|
35
39
|
'(pp/def ,name ,args ,@body))))
|
36
40
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
;;
|
2
|
+
;; absurd contrived exaggerated example to test that macros that generate
|
3
|
+
;; macros that generate macros that generate expressions are likely to work
|
4
|
+
;;
|
5
|
+
;; may you never need to do this in real life
|
6
|
+
;;
|
7
7
|
(mac make-make-op (opname op)
|
8
8
|
`(mac ,opname (name n . body)
|
9
|
-
|
10
|
-
|
9
|
+
`(mac ,name (x)
|
10
|
+
`(,',',op ,,n ,x))))
|
11
11
|
|
12
12
|
(make-make-op make-mult *)
|
13
13
|
(make-make-op make-plus +)
|
@@ -20,253 +20,123 @@
|
|
20
20
|
(make-plus +seven 7)
|
21
21
|
(make-plus +eleven 11)
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
;;
|
24
|
+
;; another contrived example to check deeply nested lexical scoping
|
25
|
+
;;
|
26
26
|
(let test-a0 "a0"
|
27
27
|
(def test-foo (f0 f1)
|
28
28
|
(with (w0 "w0" w1 "w1" w2 "w2" w3 "w3")
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
nil)
|
144
|
-
|
145
|
-
("returns item if it's an atom and matches"
|
146
|
-
(detect (fn (x) (eq? (len x) 2)) "zz")
|
147
|
-
"zz")
|
148
|
-
|
149
|
-
("returns nil if it's an atom and doesn't match"
|
150
|
-
(detect (fn (x) (eq? (len x) 20))
|
151
|
-
"zz")
|
152
|
-
nil))
|
153
|
-
|
154
|
-
(suite "pre-compile"
|
155
|
-
(suite "bang-syntax"
|
156
|
-
("expansion"
|
157
|
-
(pre-compile '(!eq? a b))
|
158
|
-
((fn args (no (apply eq? args))) a b))
|
159
|
-
|
160
|
-
("bang-syntax for 'eq?"
|
161
|
-
(!eq? 1 2)
|
162
|
-
t)
|
163
|
-
|
164
|
-
("bang-syntax for 'caris"
|
165
|
-
(!caris 'foo '(foo bar))
|
166
|
-
nil)
|
167
|
-
|
168
|
-
("bang-syntax for 'caris"
|
169
|
-
(!caris 'foo '(zozo foo bar))
|
170
|
-
t))
|
171
|
-
|
172
|
-
(suite "ampersand-syntax"
|
173
|
-
("defines a hash-lookup function"
|
174
|
-
(pre-compile '&first)
|
175
|
-
(fn (obj) (hash-get obj (quote first))))
|
176
|
-
|
177
|
-
("defines a hash-lookup function with a dot-syntax arg"
|
178
|
-
(pre-compile '&teacher.address.city)
|
179
|
-
(fn (obj) (hash-get (hash-get (hash-get obj (quote teacher)) (quote address)) (quote city))) ))
|
180
|
-
|
181
|
-
(suite "colon-syntax"
|
182
|
-
("used for composition"
|
183
|
-
(pre-compile '(no:eq? a b))
|
184
|
-
((fn args (no (apply eq? args))) a b))
|
185
|
-
|
186
|
-
("used for composition"
|
187
|
-
(pre-compile '(x:y a b))
|
188
|
-
((fn args (x (apply y args))) a b)))
|
189
|
-
|
190
|
-
(suite "bang-colon syntax"
|
191
|
-
("special combination with bang"
|
192
|
-
(pre-compile '(!x:y a b))
|
193
|
-
((fn args (no (x (apply y args)))) a b)))
|
194
|
-
|
195
|
-
("expands 'let"
|
196
|
-
(do
|
197
|
-
(def x+3*z (x y)
|
198
|
-
(let y 3
|
199
|
-
(fn (z) (* (+ x y) z))))
|
200
|
-
((x+3*z 2 99) 5))
|
201
|
-
25)
|
202
|
-
|
203
|
-
("expands 'and"
|
204
|
-
(pre-compile '(and a b c))
|
205
|
-
(cond a (cond b c)))
|
206
|
-
|
207
|
-
("expands 'or"
|
208
|
-
(do (reset-uniq-counter)
|
209
|
-
(pre-compile '(or a b c)))
|
210
|
-
((fn (ora-1)
|
211
|
-
(cond ora-1
|
212
|
-
ora-1
|
213
|
-
((fn (ora-2)
|
214
|
-
(cond ora-2
|
215
|
-
ora-2
|
216
|
-
((fn (ora-3)
|
217
|
-
(cond ora-3
|
218
|
-
ora-3
|
219
|
-
nil)) c))) b))) a))
|
220
|
-
|
221
|
-
("w/uniq provides unique variables for macro expansion"
|
222
|
-
(do (reset-uniq-counter)
|
223
|
-
(pre-compile '(w/uniq a foo)))
|
224
|
-
((fn (a) foo) (uniq 'a)))
|
225
|
-
|
226
|
-
(suite "quasiquote"
|
227
|
-
("same as quote for standalone item"
|
228
|
-
`a
|
229
|
-
a)
|
230
|
-
("same as quote for standalone list"
|
231
|
-
`(a b c)
|
232
|
-
(a b c))
|
233
|
-
("substitutes single variables"
|
234
|
-
(let b 10 `(a ,b c))
|
235
|
-
(a 10 c))
|
236
|
-
("substitutes a list"
|
237
|
-
(let b '(1 2 3) `(a ,@b c))
|
238
|
-
(a 1 2 3 c))
|
239
|
-
("substitutes a list at the end of a given list"
|
240
|
-
(let b '(1 2 3) `(a ,b ,@b))
|
241
|
-
(a (1 2 3) 1 2 3))
|
242
|
-
("more complicated substitution example"
|
243
|
-
(with (d '(1 2 3) g '(x y z)) `(a (b c ,d (e f ,@g))))
|
244
|
-
(a (b c (1 2 3) (e f x y z))))
|
245
|
-
("peeks inside nested quotes"
|
246
|
-
`(a b '(c ,(+ 1 2)))
|
247
|
-
(a b '(c 3)))
|
248
|
-
("handles nested unquote-splicing"
|
249
|
-
``(a ,,@(list '+ 1 2) b)
|
250
|
-
`((a ,(+ 1 2) b)))
|
251
|
-
("returns nested quasiquotes"
|
252
|
-
`(a b `(c d ,(+ 1 2) ,,(+ 3 4)))
|
253
|
-
(a b `(c d ,(+ 1 2) ,7))))
|
254
|
-
|
255
|
-
(suite "build-keyword-args"
|
256
|
-
("takes a list of lists and returns the list with the first item of each sublist quoted"
|
257
|
-
(build-keyword-args '( (a 1) (b c) (d e "f" 22) ))
|
258
|
-
((list 'a 1) (list 'b c) (list 'd e "f" 22))))
|
259
|
-
|
260
|
-
(suite "make-macros can create macros"
|
261
|
-
("make-plus example generates a plus-seven expression"
|
262
|
-
(+seven 6)
|
263
|
-
13)
|
264
|
-
("make-mult example generates a multiply-by-seven expression"
|
265
|
-
(*seven 6)
|
266
|
-
42)
|
267
|
-
("make-mult example generates a multiply-by-eleven expression"
|
268
|
-
(*eleven 20)
|
269
|
-
220)
|
270
|
-
("make-make example expressions can be nested"
|
271
|
-
(*eleven (*five (+seven 2)))
|
272
|
-
495))))
|
29
|
+
(let f (fn (x0) (joinstr " " test-a0 x0 f0 x0 f1))
|
30
|
+
(map f (list w0 w1 w2 w3))))))
|
31
|
+
|
32
|
+
(examples-for map
|
33
|
+
("maps a function over a list of numbers"
|
34
|
+
(map (fn (x) (* x x)) '(1 2 3))
|
35
|
+
(1 4 9))
|
36
|
+
|
37
|
+
("maps a string join function over a list of strings"
|
38
|
+
(test-foo "x" "y")
|
39
|
+
("a0 w0 x w0 y" "a0 w1 x w1 y" "a0 w2 x w2 y" "a0 w3 x w3 y"))
|
40
|
+
|
41
|
+
(suite "mapx"
|
42
|
+
("provides a convenient simplification for 'map"
|
43
|
+
(mapx '(1 2 3 4) n (* n 2))
|
44
|
+
(2 4 6 8))))
|
45
|
+
|
46
|
+
(examples-for reduce
|
47
|
+
("it applies a function cumulatively over a list"
|
48
|
+
(reduce + '(1 2 3))
|
49
|
+
6))
|
50
|
+
|
51
|
+
(examples-for bang-syntax
|
52
|
+
("expansion"
|
53
|
+
(pre-compile '(!eq? a b))
|
54
|
+
((fn args (no (apply eq? args))) a b))
|
55
|
+
|
56
|
+
("bang-syntax for 'eq?"
|
57
|
+
(!eq? 1 2)
|
58
|
+
t)
|
59
|
+
|
60
|
+
("bang-syntax for 'caris"
|
61
|
+
(!caris 'foo '(foo bar))
|
62
|
+
nil)
|
63
|
+
|
64
|
+
("bang-syntax for 'caris"
|
65
|
+
(!caris 'foo '(zozo foo bar))
|
66
|
+
t))
|
67
|
+
|
68
|
+
(examples-for ampersand-syntax
|
69
|
+
("defines a hash-lookup function"
|
70
|
+
(pre-compile '&first)
|
71
|
+
(fn (obj) (hash-get obj (quote first))))
|
72
|
+
|
73
|
+
("defines a hash-lookup function with a dot-syntax arg"
|
74
|
+
(pre-compile '&teacher.address.city)
|
75
|
+
(fn (obj) (hash-get (hash-get (hash-get obj (quote teacher)) (quote address)) (quote city))) ))
|
76
|
+
|
77
|
+
(examples-for colon-syntax
|
78
|
+
("used for composition"
|
79
|
+
(pre-compile '(no:eq? a b))
|
80
|
+
((fn args (no (apply eq? args))) a b))
|
81
|
+
|
82
|
+
("used for composition"
|
83
|
+
(pre-compile '(x:y a b))
|
84
|
+
((fn args (x (apply y args))) a b))
|
85
|
+
|
86
|
+
("special combination with bang"
|
87
|
+
(pre-compile '(!x:y a b))
|
88
|
+
((fn args (no (x (apply y args)))) a b)))
|
89
|
+
|
90
|
+
(examples-for let
|
91
|
+
("expands 'let"
|
92
|
+
(do
|
93
|
+
(def x+3*z (x y)
|
94
|
+
(let y 3
|
95
|
+
(fn (z) (* (+ x y) z))))
|
96
|
+
((x+3*z 2 99) 5))
|
97
|
+
25))
|
98
|
+
|
99
|
+
(examples-for and
|
100
|
+
("expands 'and"
|
101
|
+
(pre-compile '(and a b c))
|
102
|
+
(cond a (cond b c))))
|
103
|
+
|
104
|
+
(examples-for or
|
105
|
+
("expands 'or"
|
106
|
+
(do (reset-uniq-counter)
|
107
|
+
(pre-compile '(or a b c)))
|
108
|
+
((fn (ora-1)
|
109
|
+
(cond ora-1
|
110
|
+
ora-1
|
111
|
+
((fn (ora-2)
|
112
|
+
(cond ora-2
|
113
|
+
ora-2
|
114
|
+
((fn (ora-3)
|
115
|
+
(cond ora-3
|
116
|
+
ora-3
|
117
|
+
nil)) c))) b))) a)))
|
118
|
+
|
119
|
+
(examples-for w/uniq
|
120
|
+
("w/uniq provides unique variables for macro expansion"
|
121
|
+
(do (reset-uniq-counter)
|
122
|
+
(pre-compile '(w/uniq a foo)))
|
123
|
+
((fn (a) foo) (uniq 'a))))
|
124
|
+
|
125
|
+
(examples-for build-keyword-args
|
126
|
+
("takes a list of lists and returns the list with the first item of each sublist quoted"
|
127
|
+
(build-keyword-args '( (a 1) (b c) (d e "f" 22) ))
|
128
|
+
((list 'a 1) (list 'b c) (list 'd e "f" 22))))
|
129
|
+
|
130
|
+
(examples-for mac
|
131
|
+
("make-plus example generates a plus-seven expression"
|
132
|
+
(+seven 6)
|
133
|
+
13)
|
134
|
+
("make-mult example generates a multiply-by-seven expression"
|
135
|
+
(*seven 6)
|
136
|
+
42)
|
137
|
+
("make-mult example generates a multiply-by-eleven expression"
|
138
|
+
(*eleven 20)
|
139
|
+
220)
|
140
|
+
("make-make example expressions can be nested"
|
141
|
+
(*eleven (*five (+seven 2)))
|
142
|
+
495))
|