nydp 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lisp/core-012-utils.nydp +3 -4
- data/lib/lisp/core-015-documentation.nydp +11 -10
- data/lib/lisp/core-017-builtin-dox.nydp +1 -1
- data/lib/lisp/core-040-utils.nydp +34 -7
- data/lib/lisp/core-050-test-runner.nydp +2 -2
- data/lib/lisp/core-060-benchmarking.nydp +62 -8
- data/lib/lisp/core-080-pretty-print.nydp +131 -78
- data/lib/lisp/tests/boot-tests.nydp +8 -0
- data/lib/lisp/tests/intersperse-examples.nydp +57 -0
- data/lib/lisp/tests/invocation-tests.nydp +60 -10
- data/lib/lisp/tests/list-tests.nydp +14 -1
- data/lib/lisp/tests/pretty-print-tests.nydp +274 -15
- data/lib/lisp/tests/sort-examples.nydp +3 -1
- data/lib/nydp/compiler.rb +2 -1
- data/lib/nydp/context_symbol.rb +38 -43
- data/lib/nydp/function_invocation.rb +70 -0
- data/lib/nydp/lexical_context.rb +39 -59
- data/lib/nydp/lexical_context_builder.rb +84 -176
- data/lib/nydp/symbol.rb +5 -1
- data/lib/nydp/symbol_lookup.rb +2 -24
- data/lib/nydp/version.rb +1 -1
- metadata +3 -2
@@ -34,6 +34,14 @@
|
|
34
34
|
(map (fn (x) (* x x)) '(1 2 3))
|
35
35
|
(1 4 9))
|
36
36
|
|
37
|
+
("applies the function to a singleton argument"
|
38
|
+
(map (fn (x) (* x x)) 19)
|
39
|
+
361)
|
40
|
+
|
41
|
+
("preserves dotted lists"
|
42
|
+
(map (fn (x) (* x x)) '(1 2 3 4 . 5))
|
43
|
+
(1 4 9 16 . 25))
|
44
|
+
|
37
45
|
("maps a string join function over a list of strings"
|
38
46
|
(test-foo "x" "y")
|
39
47
|
("a0 w0 x w0 y" "a0 w1 x w1 y" "a0 w2 x w2 y" "a0 w3 x w3 y"))
|
@@ -0,0 +1,57 @@
|
|
1
|
+
(examples-for intersperse
|
2
|
+
("returns nil for nothing"
|
3
|
+
(intersperse 42)
|
4
|
+
nil)
|
5
|
+
|
6
|
+
("returns nil for nil"
|
7
|
+
(intersperse 42 nil)
|
8
|
+
nil)
|
9
|
+
|
10
|
+
("returns a singleton thing"
|
11
|
+
(intersperse 42 'a)
|
12
|
+
a)
|
13
|
+
|
14
|
+
("returns a singleton list"
|
15
|
+
(intersperse 42 '(a))
|
16
|
+
(a))
|
17
|
+
|
18
|
+
("returns list with argument between each element"
|
19
|
+
(intersperse 42 '(a b))
|
20
|
+
(a 42 b))
|
21
|
+
|
22
|
+
("returns longer list with argument between each element"
|
23
|
+
(intersperse 42 '(a b c d e))
|
24
|
+
(a 42 b 42 c 42 d 42 e))
|
25
|
+
|
26
|
+
("returns list with non-atomic argument between each element"
|
27
|
+
(intersperse '(+ +) '(a b c))
|
28
|
+
(a (+ +) b (+ +) c))
|
29
|
+
|
30
|
+
("returns improper list with argument between each element"
|
31
|
+
(intersperse 'oo '(a b c . d))
|
32
|
+
(a oo b oo c oo . d)))
|
33
|
+
|
34
|
+
(examples-for intersperse-splicing
|
35
|
+
("returns nil for nothing"
|
36
|
+
(intersperse-splicing 42)
|
37
|
+
nil)
|
38
|
+
|
39
|
+
("returns nil for nil"
|
40
|
+
(intersperse-splicing 42 nil)
|
41
|
+
nil)
|
42
|
+
|
43
|
+
("returns a singleton list"
|
44
|
+
(intersperse-splicing 42 '((a)))
|
45
|
+
(a))
|
46
|
+
|
47
|
+
("returns list with argument between each element"
|
48
|
+
(intersperse-splicing 42 '((a) (b)))
|
49
|
+
(a 42 b))
|
50
|
+
|
51
|
+
("returns longer list with argument between each element"
|
52
|
+
(intersperse-splicing 42 '((a b) (c d) (e)))
|
53
|
+
(a b 42 c d 42 e))
|
54
|
+
|
55
|
+
("returns list with non-atomic argument between each element"
|
56
|
+
(intersperse-splicing '(+ +) '((a b) (c d) (e f g)))
|
57
|
+
(a b (+ +) c d (+ +) e f g)))
|
@@ -16,8 +16,12 @@
|
|
16
16
|
(def tst-3-n (a b c . n) "success a: ~a b: ~b c: ~c . n: ~(inspect n)" )
|
17
17
|
(def tst-4 (a b c d) "success a: ~a b: ~b c: ~c d: ~d" )
|
18
18
|
(def tst-4-n (a b c d . n) "success a: ~a b: ~b c: ~c d: ~d . n: ~(inspect n)" )
|
19
|
-
(def tst-5 (a b c d e)
|
20
|
-
(def tst-5-n (a b c d e . n)
|
19
|
+
(def tst-5 (a b c d e) "success a: ~a b: ~b c: ~c d: ~d e: ~e" )
|
20
|
+
(def tst-5-n (a b c d e . n) "success a: ~a b: ~b c: ~c d: ~d e: ~e . n: ~(inspect n)" )
|
21
|
+
(def tst-6 (a b c d e f) "success a: ~a b: ~b c: ~c d: ~d e: ~e f: ~f" )
|
22
|
+
(def tst-6-n (a b c d e f . n) "success a: ~a b: ~b c: ~c d: ~d e: ~e f: ~f . n: ~(inspect n)" )
|
23
|
+
(def tst-7 (a b c d e f g) "success a: ~a b: ~b c: ~c d: ~d e: ~e f: ~f g: ~g" )
|
24
|
+
(def tst-7-n (a b c d e f g . n) "success a: ~a b: ~b c: ~c d: ~d e: ~e f: ~f g: ~g . n: ~(inspect n)" )
|
21
25
|
|
22
26
|
(register-test
|
23
27
|
'(suite "Invocation Tests"
|
@@ -94,12 +98,14 @@
|
|
94
98
|
("five args" (tst-4 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4" ))
|
95
99
|
|
96
100
|
(suite "four params and rest param"
|
97
|
-
("no args" (tst-4-n)
|
98
|
-
("one arg" (tst-4-n 1)
|
99
|
-
("two args" (tst-4-n 1 2)
|
100
|
-
("three args" (tst-4-n 1 2 3)
|
101
|
-
("four args" (tst-4-n 1 2 3 4)
|
102
|
-
("five args" (tst-4-n 1 2 3 4 5)
|
101
|
+
("no args" (tst-4-n) "success a: b: c: d: . n: nil" )
|
102
|
+
("one arg" (tst-4-n 1) "success a: 1 b: c: d: . n: nil" )
|
103
|
+
("two args" (tst-4-n 1 2) "success a: 1 b: 2 c: d: . n: nil" )
|
104
|
+
("three args" (tst-4-n 1 2 3) "success a: 1 b: 2 c: 3 d: . n: nil" )
|
105
|
+
("four args" (tst-4-n 1 2 3 4) "success a: 1 b: 2 c: 3 d: 4 . n: nil" )
|
106
|
+
("five args" (tst-4-n 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 . n: (5)" )
|
107
|
+
("six args" (tst-4-n 1 2 3 4 5 6) "success a: 1 b: 2 c: 3 d: 4 . n: (5 6)" )
|
108
|
+
("seven args" (tst-4-n 1 2 3 4 5 6 7) "success a: 1 b: 2 c: 3 d: 4 . n: (5 6 7)" ))
|
103
109
|
|
104
110
|
(suite "five params"
|
105
111
|
("no args" (tst-5) "success a: b: c: d: e: " )
|
@@ -107,7 +113,9 @@
|
|
107
113
|
("two args" (tst-5 1 2) "success a: 1 b: 2 c: d: e: " )
|
108
114
|
("three args" (tst-5 1 2 3) "success a: 1 b: 2 c: 3 d: e: " )
|
109
115
|
("four args" (tst-5 1 2 3 4) "success a: 1 b: 2 c: 3 d: 4 e: " )
|
110
|
-
("five args" (tst-5 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 e: 5" )
|
116
|
+
("five args" (tst-5 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 e: 5" )
|
117
|
+
("six args" (tst-5 1 2 3 4 5 6) "success a: 1 b: 2 c: 3 d: 4 e: 5" )
|
118
|
+
("seven args" (tst-5 1 2 3 4 5 6 7) "success a: 1 b: 2 c: 3 d: 4 e: 5" ))
|
111
119
|
|
112
120
|
(suite "five params and rest param"
|
113
121
|
("no args" (tst-5-n) "success a: b: c: d: e: . n: nil" )
|
@@ -115,5 +123,47 @@
|
|
115
123
|
("two args" (tst-5-n 1 2) "success a: 1 b: 2 c: d: e: . n: nil" )
|
116
124
|
("three args" (tst-5-n 1 2 3) "success a: 1 b: 2 c: 3 d: e: . n: nil" )
|
117
125
|
("four args" (tst-5-n 1 2 3 4) "success a: 1 b: 2 c: 3 d: 4 e: . n: nil" )
|
118
|
-
("five args" (tst-5-n 1 2 3 4 5)
|
126
|
+
("five args" (tst-5-n 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 e: 5 . n: nil" )
|
127
|
+
("six args" (tst-5-n 1 2 3 4 5 6) "success a: 1 b: 2 c: 3 d: 4 e: 5 . n: (6)" )
|
128
|
+
("seven args" (tst-5-n 1 2 3 4 5 6 7) "success a: 1 b: 2 c: 3 d: 4 e: 5 . n: (6 7)" ))
|
129
|
+
|
130
|
+
(suite "six params"
|
131
|
+
("no args" (tst-6) "success a: b: c: d: e: f: " )
|
132
|
+
("one arg" (tst-6 1) "success a: 1 b: c: d: e: f: " )
|
133
|
+
("two args" (tst-6 1 2) "success a: 1 b: 2 c: d: e: f: " )
|
134
|
+
("three args" (tst-6 1 2 3) "success a: 1 b: 2 c: 3 d: e: f: " )
|
135
|
+
("four args" (tst-6 1 2 3 4) "success a: 1 b: 2 c: 3 d: 4 e: f: " )
|
136
|
+
("five args" (tst-6 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: " )
|
137
|
+
("six args" (tst-6 1 2 3 4 5 6) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6" )
|
138
|
+
("seven args" (tst-6 1 2 3 4 5 6 7) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6" ))
|
139
|
+
|
140
|
+
(suite "six params and rest param"
|
141
|
+
("no args" (tst-6-n) "success a: b: c: d: e: f: . n: nil" )
|
142
|
+
("one arg" (tst-6-n 1) "success a: 1 b: c: d: e: f: . n: nil" )
|
143
|
+
("two args" (tst-6-n 1 2) "success a: 1 b: 2 c: d: e: f: . n: nil" )
|
144
|
+
("three args" (tst-6-n 1 2 3) "success a: 1 b: 2 c: 3 d: e: f: . n: nil" )
|
145
|
+
("four args" (tst-6-n 1 2 3 4) "success a: 1 b: 2 c: 3 d: 4 e: f: . n: nil" )
|
146
|
+
("five args" (tst-6-n 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: . n: nil" )
|
147
|
+
("six args" (tst-6-n 1 2 3 4 5 6) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6 . n: nil" )
|
148
|
+
("seven args" (tst-6-n 1 2 3 4 5 6 7) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6 . n: (7)" ))
|
149
|
+
|
150
|
+
(suite "seven params"
|
151
|
+
("no args" (tst-7) "success a: b: c: d: e: f: g: " )
|
152
|
+
("one arg" (tst-7 1) "success a: 1 b: c: d: e: f: g: " )
|
153
|
+
("two args" (tst-7 1 2) "success a: 1 b: 2 c: d: e: f: g: " )
|
154
|
+
("three args" (tst-7 1 2 3) "success a: 1 b: 2 c: 3 d: e: f: g: " )
|
155
|
+
("four args" (tst-7 1 2 3 4) "success a: 1 b: 2 c: 3 d: 4 e: f: g: " )
|
156
|
+
("five args" (tst-7 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: g: " )
|
157
|
+
("six args" (tst-7 1 2 3 4 5 6) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6 g: " )
|
158
|
+
("seven args" (tst-7 1 2 3 4 5 6 7) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6 g: 7" ))
|
159
|
+
|
160
|
+
(suite "seven params and rest param"
|
161
|
+
("no args" (tst-7-n) "success a: b: c: d: e: f: g: . n: nil" )
|
162
|
+
("one arg" (tst-7-n 1) "success a: 1 b: c: d: e: f: g: . n: nil" )
|
163
|
+
("two args" (tst-7-n 1 2) "success a: 1 b: 2 c: d: e: f: g: . n: nil" )
|
164
|
+
("three args" (tst-7-n 1 2 3) "success a: 1 b: 2 c: 3 d: e: f: g: . n: nil" )
|
165
|
+
("four args" (tst-7-n 1 2 3 4) "success a: 1 b: 2 c: 3 d: 4 e: f: g: . n: nil" )
|
166
|
+
("five args" (tst-7-n 1 2 3 4 5) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: g: . n: nil" )
|
167
|
+
("six args" (tst-7-n 1 2 3 4 5 6) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6 g: . n: nil" )
|
168
|
+
("seven args" (tst-7-n 1 2 3 4 5 6 7) "success a: 1 b: 2 c: 3 d: 4 e: 5 f: 6 g: 7 . n: nil" ))
|
119
169
|
))
|
@@ -37,7 +37,7 @@
|
|
37
37
|
(joinlists '(a b c) '(x y z) '(1 2 3))
|
38
38
|
(a b c x y z 1 2 3))
|
39
39
|
|
40
|
-
("joins three lists without
|
40
|
+
("joins three lists without recursing"
|
41
41
|
(joinlists '(a b c) '(x (y1 y2 y3) z) '(1 2 (3 3 3)))
|
42
42
|
(a b c x (y1 y2 y3) z 1 2 (3 3 3))))
|
43
43
|
|
@@ -119,3 +119,16 @@
|
|
119
119
|
("nil for a very improper list"
|
120
120
|
(proper? '(a b . (c . d)))
|
121
121
|
nil))
|
122
|
+
|
123
|
+
(examples-for list-slices
|
124
|
+
("just the list if small"
|
125
|
+
(list-slices '(a b c d e) 12)
|
126
|
+
((a b c d e)))
|
127
|
+
|
128
|
+
("exactly three lists"
|
129
|
+
(list-slices '(a b c d e f g h i) 3)
|
130
|
+
((a b c) (d e f) (g h i)))
|
131
|
+
|
132
|
+
("three lists and an extra big"
|
133
|
+
(list-slices '(a b c d e f g h i j k) 3)
|
134
|
+
((a b c) (d e f) (g h i) (j k))))
|
@@ -1,34 +1,293 @@
|
|
1
|
+
(examples-for pp/breaker
|
2
|
+
("breaks 'if forms"
|
3
|
+
(pp/breaker '(if a b c d e))
|
4
|
+
((if a) (b) (c) (d) (e)))
|
5
|
+
|
6
|
+
("breaks 'let forms"
|
7
|
+
(pp/breaker '(let a b c d))
|
8
|
+
((let a b) (c) (d)))
|
9
|
+
|
10
|
+
("breaks 'def forms"
|
11
|
+
(pp/breaker '(def yoyo (x y) a b))
|
12
|
+
((def yoyo (x y)) (a) (b))))
|
13
|
+
|
14
|
+
(examples-for pp/dotify
|
15
|
+
("nothing"
|
16
|
+
(pp/dotify nil)
|
17
|
+
nil)
|
18
|
+
|
19
|
+
("atom"
|
20
|
+
(inspect:pp/dotify 'a)
|
21
|
+
"a")
|
22
|
+
|
23
|
+
("plain list"
|
24
|
+
(inspect:pp/dotify '(a b c))
|
25
|
+
"(a b c)")
|
26
|
+
|
27
|
+
("dotted list"
|
28
|
+
(map inspect (pp/dotify '(a b c . d)))
|
29
|
+
("a" "b" "c" "." "d"))
|
30
|
+
|
31
|
+
("nested dotted list"
|
32
|
+
(inspect:pp/dotify '(def foo (a b c . d)
|
33
|
+
(a (fn (x y . z) (d z) ))))
|
34
|
+
"(def foo (a b c . d) (a (fn (x y . z) (d z))))"))
|
35
|
+
|
36
|
+
(examples-for pp/indent
|
37
|
+
("nothing"
|
38
|
+
(pp/indent nil (list " "))
|
39
|
+
(" "))
|
40
|
+
|
41
|
+
("number"
|
42
|
+
(pp/indent 22 (list " "))
|
43
|
+
(" " " "))
|
44
|
+
|
45
|
+
("string"
|
46
|
+
(pp/indent "forty-two" (list " "))
|
47
|
+
(" " " "))
|
48
|
+
|
49
|
+
("symbol"
|
50
|
+
(pp/indent 'forty-two (list " "))
|
51
|
+
(" " " "))
|
52
|
+
|
53
|
+
("list"
|
54
|
+
(pp/indent '(fn (x) (blow x)) (list " "))
|
55
|
+
(" ")))
|
56
|
+
|
57
|
+
(examples-for pp/cleanup
|
58
|
+
("empty"
|
59
|
+
(pp/cleanup "")
|
60
|
+
"")
|
61
|
+
|
62
|
+
("atom"
|
63
|
+
(pp/cleanup "foo")
|
64
|
+
"foo")
|
65
|
+
|
66
|
+
("already clean"
|
67
|
+
(pp/cleanup "foo\nbar")
|
68
|
+
"foo
|
69
|
+
bar")
|
70
|
+
|
71
|
+
("removes trailing whitespace on each line"
|
72
|
+
(pp/cleanup "foo \nbar \ntoto ")
|
73
|
+
"foo
|
74
|
+
bar
|
75
|
+
toto")
|
76
|
+
|
77
|
+
("removes trailing whitespace on each line but preserves leading whitespace"
|
78
|
+
(pp/cleanup "foo \n bar \n toto ")
|
79
|
+
"foo
|
80
|
+
bar
|
81
|
+
toto"))
|
82
|
+
|
83
|
+
(examples-for pp/unsyntax
|
84
|
+
("nil"
|
85
|
+
(to-string:pp/unsyntax nil)
|
86
|
+
"")
|
87
|
+
|
88
|
+
("atom"
|
89
|
+
(to-string:pp/unsyntax 42)
|
90
|
+
"42")
|
91
|
+
|
92
|
+
("list"
|
93
|
+
(to-string:pp/unsyntax '(for a 1 10 (p 'hello 'world)))
|
94
|
+
"(for a 1 10 (p 'hello 'world))")
|
95
|
+
|
96
|
+
("list with embedded syntax"
|
97
|
+
(to-string:pp/unsyntax '(for (colon-syntax a b) 1 10 ((dot-syntax p q) 'hello 'world)))
|
98
|
+
"(for a:b 1 10 (p.q 'hello 'world))")
|
99
|
+
|
100
|
+
("percent-syntax"
|
101
|
+
(to-string:pp/unsyntax '(percent-syntax this that))
|
102
|
+
"this%that")
|
103
|
+
|
104
|
+
("prefix percent-syntax"
|
105
|
+
(to-string:pp/unsyntax '(percent-syntax || that))
|
106
|
+
"%that")
|
107
|
+
|
108
|
+
("postfix percent-syntax"
|
109
|
+
(to-string:pp/unsyntax '(percent-syntax this ||))
|
110
|
+
"this%")
|
111
|
+
|
112
|
+
("postfix multiple percent-syntax"
|
113
|
+
(to-string:pp/unsyntax '(percent-syntax this that || another))
|
114
|
+
"this%that%%another")
|
115
|
+
|
116
|
+
("nested syntax"
|
117
|
+
(to-string:pp/unsyntax '(percent-syntax this (ampersand-syntax x y) that))
|
118
|
+
"this%x&y%that"))
|
119
|
+
|
120
|
+
(examples-for pp/split-form
|
121
|
+
("first item"
|
122
|
+
(pp/split-form '(a b c d) 1)
|
123
|
+
((a) (b) (c) (d)))
|
124
|
+
|
125
|
+
("first two items"
|
126
|
+
(pp/split-form '(a b c d e) 2)
|
127
|
+
((a b) (c) (d) (e)))
|
128
|
+
|
129
|
+
("first three items"
|
130
|
+
(pp/split-form '(a b c d e f) 3)
|
131
|
+
((a b c) (d) (e) (f))))
|
132
|
+
|
133
|
+
(examples-for pp/flatly
|
134
|
+
("nil"
|
135
|
+
(pp/flatly nil)
|
136
|
+
"nil")
|
137
|
+
|
138
|
+
("number"
|
139
|
+
(pp/flatly 22)
|
140
|
+
"22")
|
141
|
+
|
142
|
+
("symbol"
|
143
|
+
(pp/flatly 'qwerty)
|
144
|
+
"qwerty")
|
145
|
+
|
146
|
+
("list"
|
147
|
+
(pp/flatly '(a b c d 21 22 23 'quoting) )
|
148
|
+
"(a b c d 21 22 23 'quoting)")
|
149
|
+
|
150
|
+
("macro example"
|
151
|
+
(pp/flatly '(mac johnny (foo bar) `(this ,foo ,@(map twisty bar))))
|
152
|
+
"(mac johnny (foo bar) `(this ,foo ,@(map twisty bar)))"))
|
153
|
+
|
1
154
|
(examples-for pp
|
155
|
+
("a quote"
|
156
|
+
(pp '(quote a))
|
157
|
+
"'a")
|
158
|
+
|
159
|
+
("unquote"
|
160
|
+
(pp '(unquote a))
|
161
|
+
",a")
|
162
|
+
|
163
|
+
("unquote-splicing"
|
164
|
+
(pp '(unquote-splicing a))
|
165
|
+
",@a")
|
166
|
+
|
167
|
+
("quasiquote"
|
168
|
+
(pp '(quasiquote a))
|
169
|
+
"`a")
|
170
|
+
|
171
|
+
("quote unquote"
|
172
|
+
(pp '(quote (unquote a)))
|
173
|
+
"',a")
|
174
|
+
|
2
175
|
("a macro invocation"
|
3
176
|
(pp '(mac pp/def (name args . body) `(hash-set pp/special-forms ',name (fn ,args ,@body))))
|
4
|
-
"(mac pp/def (name args
|
177
|
+
"(mac pp/def (name args . body)
|
178
|
+
`(hash-set pp/special-forms
|
179
|
+
',name
|
180
|
+
(fn ,args ,@body)))")
|
5
181
|
|
6
182
|
("a 'def invocation"
|
7
183
|
(pp '(def pp (form) (pp/main form 0)))
|
8
|
-
"(def pp (form)
|
184
|
+
"(def pp (form) (pp/main form 0))")
|
185
|
+
|
186
|
+
("a longer 'def invocation"
|
187
|
+
(pp '(def pp (form)
|
188
|
+
(pp/main form 0)
|
189
|
+
(pp/again form 1)
|
190
|
+
(pp/more (jump:skip form) 2)))
|
191
|
+
"(def pp (form)
|
192
|
+
(pp/main form 0)
|
193
|
+
(pp/again form 1)
|
194
|
+
(pp/more (jump:skip form) 2))")
|
195
|
+
|
196
|
+
("a 'def with a dotted argument list"
|
197
|
+
(pp '(def afun (a b c . others)
|
198
|
+
(afun a b c (a (car others) (b (cdr others))))))
|
199
|
+
"(def afun (a b c . others)
|
200
|
+
(afun a
|
201
|
+
b
|
202
|
+
c
|
203
|
+
(a (car others) (b (cdr others)))))")
|
9
204
|
|
10
205
|
("something with a plain string literal"
|
11
206
|
(pp '(def yoohoo (it) (wrangle "foobar" it)))
|
12
|
-
"(def yoohoo (it)
|
13
|
-
|
14
|
-
("
|
15
|
-
(pp
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
207
|
+
"(def yoohoo (it) (wrangle \"foobar\" it))")
|
208
|
+
|
209
|
+
("a 'let form"
|
210
|
+
(pp '(let acc nil
|
211
|
+
(rfnwith flattenize (x things)
|
212
|
+
(if (pair? x)
|
213
|
+
(eachr flattenize x)
|
214
|
+
(push x acc)))
|
215
|
+
acc))
|
216
|
+
"(let acc nil
|
217
|
+
(rfnwith flattenize (x things)
|
218
|
+
(if (pair? x)
|
219
|
+
(eachr flattenize x)
|
220
|
+
(push x acc)))
|
221
|
+
acc)")
|
222
|
+
|
223
|
+
|
224
|
+
("a real-life example from utils"
|
225
|
+
(pp '(def flatten (things)
|
226
|
+
(let acc nil
|
227
|
+
(rfnwith flattenize (x things)
|
228
|
+
(if (pair? x)
|
229
|
+
(eachr flattenize x)
|
230
|
+
(push x acc)))
|
231
|
+
acc)))
|
232
|
+
"(def flatten (things)
|
233
|
+
(let acc nil
|
234
|
+
(rfnwith flattenize (x things)
|
235
|
+
(if (pair? x)
|
236
|
+
(eachr flattenize x)
|
237
|
+
(push x acc)))
|
238
|
+
acc))")
|
239
|
+
|
240
|
+
("a real-life example from utils"
|
241
|
+
(pp '(def list-slices (things slice-size)
|
242
|
+
; slice 'things into a list of lists each with maximum 'slice-size items
|
243
|
+
(chapter pagination list-management)
|
244
|
+
(if (< (len things) slice-size)
|
245
|
+
(cons things nil)
|
246
|
+
(cons (firstn slice-size things)
|
247
|
+
(list-slices (nthcdr slice-size things)
|
248
|
+
slice-size)))))
|
249
|
+
"(def list-slices (things slice-size)
|
250
|
+
; slice 'things into a list of lists each with maximum 'slice-size items
|
251
|
+
(chapter pagination list-management)
|
252
|
+
(if (< (len things) slice-size)
|
253
|
+
(cons things nil)
|
254
|
+
(cons (firstn slice-size things)
|
255
|
+
(list-slices (nthcdr slice-size things)
|
256
|
+
slice-size))))")
|
257
|
+
|
258
|
+
("a real-life example from test-runner"
|
259
|
+
(pp '(def run-all-tests (verbose)
|
260
|
+
; runs all tests that have been registered with 'register-test
|
261
|
+
(with (passed 0 failed 0)
|
262
|
+
(with (f-pass (fn nil (assign passed (+ 1 passed)))
|
263
|
+
f-fail (fn nil (assign failed (+ 1 failed))))
|
264
|
+
(run-tests `(suite "all tests" ,@all-tests) f-pass f-fail verbose)
|
265
|
+
(p "passed: " passed)
|
266
|
+
(p "failed: " failed)
|
267
|
+
(/ passed (+ passed failed))))))
|
268
|
+
"(def run-all-tests (verbose)
|
269
|
+
; runs all tests that have been registered with 'register-test
|
270
|
+
(with (passed 0 failed 0)
|
271
|
+
(with (f-pass (fn nil (assign passed (+ 1 passed)))
|
272
|
+
f-fail (fn nil (assign failed (+ 1 failed))))
|
273
|
+
(run-tests `(suite \"all tests\" ,@all-tests)
|
274
|
+
f-pass
|
275
|
+
f-fail
|
276
|
+
verbose)
|
277
|
+
(p \"passed: \" passed)
|
278
|
+
(p \"failed: \" failed)
|
279
|
+
(/ passed (+ passed failed)))))")
|
280
|
+
|
281
|
+
|
23
282
|
|
24
283
|
("special syntax"
|
25
284
|
(pp '(string-pieces "hello " (bang-syntax || (dot-syntax x y (ampersand-syntax foo bar))) " and welcome to " (prefix-list "%%" (a b c d)) " and friends!"))
|
26
285
|
"\"hello ~~!x.y.foo&bar and welcome to ~~%%(a b c d) and friends!\"")
|
27
286
|
|
28
|
-
("
|
287
|
+
("percent-syntax"
|
29
288
|
(pp '(percent-syntax || (dot-syntax x y)))
|
30
289
|
"%x.y")
|
31
290
|
|
32
291
|
("brace list"
|
33
292
|
(pp '(&x {a 1 b "two" c 'three d ,four e (sub invocation) f {sub brace list} }))
|
34
|
-
"(&x {a 1 b \"two\" c 'three d ,four e (sub invocation) f {sub brace list}})"))
|
293
|
+
"(&x { a 1 b \"two\" c 'three d ,four e (sub invocation) f { sub brace list } })"))
|