nydp 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +44 -0
- data/lib/lisp/core-010-precompile.nydp +13 -16
- data/lib/lisp/core-012-utils.nydp +3 -2
- data/lib/lisp/core-015-documentation.nydp +54 -23
- data/lib/lisp/core-017-builtin-dox.nydp +14 -12
- data/lib/lisp/core-020-utils.nydp +5 -5
- data/lib/lisp/core-030-syntax.nydp +166 -72
- data/lib/lisp/core-035-flow-control.nydp +38 -11
- data/lib/lisp/core-037-list-utils.nydp +12 -0
- data/lib/lisp/core-039-module.nydp +24 -0
- data/lib/lisp/core-040-utils.nydp +32 -12
- data/lib/lisp/core-041-string-utils.nydp +25 -1
- data/lib/lisp/core-042-date-utils.nydp +21 -1
- data/lib/lisp/core-043-list-utils.nydp +96 -64
- data/lib/lisp/core-070-prefix-list.nydp +1 -1
- data/lib/lisp/core-080-pretty-print.nydp +57 -17
- data/lib/lisp/core-090-hook.nydp +35 -1
- data/lib/lisp/core-100-utils.nydp +82 -2
- data/lib/lisp/core-110-hash-utils.nydp +56 -2
- data/lib/lisp/core-120-settings.nydp +16 -5
- data/lib/lisp/core-130-validations.nydp +51 -0
- data/lib/lisp/core-900-benchmarking.nydp +78 -20
- data/lib/lisp/tests/accum-examples.nydp +28 -1
- data/lib/lisp/tests/aif-examples.nydp +8 -3
- data/lib/lisp/tests/andify-examples.nydp +7 -0
- data/lib/lisp/tests/at-syntax-examples.nydp +17 -0
- data/lib/lisp/tests/best-examples.nydp +9 -0
- data/lib/lisp/tests/builtin-tests.nydp +19 -0
- data/lib/lisp/tests/case-examples.nydp +14 -0
- data/lib/lisp/tests/date-examples.nydp +54 -1
- data/lib/lisp/tests/destructuring-examples.nydp +46 -14
- data/lib/lisp/tests/detect-examples.nydp +12 -0
- data/lib/lisp/tests/dp-examples.nydp +24 -0
- data/lib/lisp/tests/each-tests.nydp +5 -0
- data/lib/lisp/tests/empty-examples.nydp +1 -1
- data/lib/lisp/tests/error-tests.nydp +4 -4
- data/lib/lisp/tests/explain-mac-examples.nydp +1 -1
- data/lib/lisp/tests/filter-forms-examples.nydp +15 -0
- data/lib/lisp/tests/hash-examples.nydp +25 -1
- data/lib/lisp/tests/list-grep-examples.nydp +40 -0
- data/lib/lisp/tests/list-tests.nydp +58 -1
- data/lib/lisp/tests/map-hash-examples.nydp +11 -0
- data/lib/lisp/tests/module-examples.nydp +10 -0
- data/lib/lisp/tests/multi-assign-examples.nydp +6 -0
- data/lib/lisp/tests/parser-tests.nydp +25 -0
- data/lib/lisp/tests/pretty-print-tests.nydp +17 -14
- data/lib/lisp/tests/set-difference-examples.nydp +8 -0
- data/lib/lisp/tests/settings-examples.nydp +17 -1
- data/lib/lisp/tests/string-tests.nydp +70 -1
- data/lib/lisp/tests/syntax-tests.nydp +5 -1
- data/lib/lisp/tests/to-integer-examples.nydp +16 -0
- data/lib/lisp/tests/validation-examples.nydp +15 -0
- data/lib/nydp.rb +10 -3
- data/lib/nydp/assignment.rb +10 -3
- data/lib/nydp/builtin.rb +1 -1
- data/lib/nydp/builtin/abs.rb +8 -0
- data/lib/nydp/builtin/date.rb +15 -1
- data/lib/nydp/builtin/error.rb +1 -1
- data/lib/nydp/builtin/hash.rb +24 -1
- data/lib/nydp/builtin/inspect.rb +1 -1
- data/lib/nydp/builtin/plus.rb +10 -2
- data/lib/nydp/builtin/random_string.rb +2 -2
- data/lib/nydp/builtin/{car.rb → regexp.rb} +2 -2
- data/lib/nydp/builtin/ruby_wrap.rb +72 -0
- data/lib/nydp/builtin/string_match.rb +2 -2
- data/lib/nydp/builtin/string_pad_left.rb +7 -0
- data/lib/nydp/builtin/string_pad_right.rb +7 -0
- data/lib/nydp/builtin/string_replace.rb +3 -3
- data/lib/nydp/builtin/string_split.rb +4 -3
- data/lib/nydp/builtin/to_integer.rb +23 -0
- data/lib/nydp/builtin/to_string.rb +2 -9
- data/lib/nydp/builtin/type_of.rb +9 -6
- data/lib/nydp/closure.rb +0 -3
- data/lib/nydp/cond.rb +23 -1
- data/lib/nydp/context_symbol.rb +14 -6
- data/lib/nydp/core.rb +36 -28
- data/lib/nydp/core_ext.rb +21 -5
- data/lib/nydp/date.rb +26 -18
- data/lib/nydp/function_invocation.rb +34 -26
- data/lib/nydp/helper.rb +35 -3
- data/lib/nydp/interpreted_function.rb +68 -40
- data/lib/nydp/literal.rb +1 -1
- data/lib/nydp/pair.rb +22 -5
- data/lib/nydp/parser.rb +11 -7
- data/lib/nydp/string_atom.rb +3 -4
- data/lib/nydp/symbol_lookup.rb +7 -7
- data/lib/nydp/tokeniser.rb +2 -2
- data/lib/nydp/truth.rb +10 -10
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp/vm.rb +7 -0
- data/nydp.gemspec +2 -4
- data/spec/date_spec.rb +93 -0
- data/spec/embedded_spec.rb +12 -12
- data/spec/foreign_hash_spec.rb +14 -2
- data/spec/hash_non_hash_behaviour_spec.rb +7 -7
- data/spec/hash_spec.rb +24 -2
- data/spec/nydp_spec.rb +14 -2
- data/spec/pair_spec.rb +3 -1
- data/spec/parser_spec.rb +31 -20
- data/spec/rand_spec.rb +3 -3
- data/spec/spec_helper.rb +10 -1
- metadata +24 -37
- data/lib/nydp/builtin/cdr.rb +0 -7
- data/lib/nydp/builtin/cons.rb +0 -9
@@ -184,26 +184,79 @@
|
|
184
184
|
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)))
|
185
185
|
|
186
186
|
(in-private
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
187
|
+
(def bm-no-closures ()
|
188
|
+
(list λ(+ 1 2)
|
189
|
+
λ(+ 1 2)
|
190
|
+
λ(+ 1 2)
|
191
|
+
λ(+ 1 2)
|
192
|
+
λ(+ 1 2)
|
193
|
+
λ(+ 1 2)
|
194
|
+
λ(+ 1 2)
|
195
|
+
λ(+ 1 2)
|
196
|
+
λ(+ 1 2)
|
197
|
+
λ(+ 1 2)))
|
198
|
+
|
199
|
+
(def bm-cons () (cons 'a 'b))
|
200
|
+
(def bm-type-of () (type-of 'a)))
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
;; ================================================
|
205
|
+
;; Benchmark: string concatenation - 10 runs of 20000 iterations each
|
206
|
+
;; took: 0.702480166 ms, 3.51240083e-05 ms per iteration
|
207
|
+
;; took: 0.71368384 ms, 3.5684192e-05 ms per iteration
|
208
|
+
;; took: 0.722608668 ms, 3.61304334e-05 ms per iteration
|
209
|
+
;; took: 0.716350427 ms, 3.5817521349999995e-05 ms per iteration
|
210
|
+
;; took: 0.72145049 ms, 3.60725245e-05 ms per iteration
|
211
|
+
;; took: 0.745082221 ms, 3.725411105e-05 ms per iteration
|
212
|
+
;; took: 0.722694129 ms, 3.613470645e-05 ms per iteration
|
213
|
+
;; took: 0.71999777 ms, 3.59998885e-05 ms per iteration
|
214
|
+
;; took: 0.727236822 ms, 3.63618411e-05 ms per iteration
|
215
|
+
;; took: 0.73657519 ms, 3.68287595e-05 ms per iteration
|
216
|
+
;; total 7.228159722999999, average 0.7228159722999999 per run
|
217
|
+
;; ================================================
|
218
|
+
;; string concatenation : total 7.228159722999999, average 0.7228159722999999 per run
|
219
|
+
;; (def bm-string-concat ()
|
220
|
+
;; (+
|
221
|
+
;; (+ "this" "that" "another")
|
222
|
+
;; (+ "this" "that" "another")
|
223
|
+
;; (+ "this" "that" "another")
|
224
|
+
;; (+ "this" "that" "another")
|
225
|
+
;; (+ "this" "that" "another")
|
226
|
+
;; (+ "this" "that" "another")
|
227
|
+
;; (+ "this" "that" "another")
|
228
|
+
;; (+ "this" "that" "another")
|
229
|
+
;; (+ "this" "that" "another")
|
230
|
+
;; (+ "this" "that" "another")))
|
231
|
+
|
232
|
+
|
233
|
+
;; ================================================
|
234
|
+
;; Benchmark: random string - 10 runs of 20000 iterations each
|
235
|
+
;; took: 0.693267608 ms, 3.4663380399999996e-05 ms per iteration
|
236
|
+
;; took: 0.763436112 ms, 3.8171805599999996e-05 ms per iteration
|
237
|
+
;; took: 0.682000681 ms, 3.410003405e-05 ms per iteration
|
238
|
+
;; took: 0.687733846 ms, 3.43866923e-05 ms per iteration
|
239
|
+
;; took: 0.686838878 ms, 3.43419439e-05 ms per iteration
|
240
|
+
;; took: 0.681588034 ms, 3.40794017e-05 ms per iteration
|
241
|
+
;; took: 0.689589352 ms, 3.44794676e-05 ms per iteration
|
242
|
+
;; took: 0.690437907 ms, 3.4521895349999996e-05 ms per iteration
|
243
|
+
;; took: 0.683199842 ms, 3.4159992099999995e-05 ms per iteration
|
244
|
+
;; took: 0.696863126 ms, 3.48431563e-05 ms per iteration
|
245
|
+
;; total 6.954955385999999, average 0.6954955385999999 per run
|
246
|
+
;; ================================================
|
247
|
+
;; random string : total 6.954955385999999, average 0.6954955385999999 per run
|
248
|
+
|
249
|
+
;; (def bm-random-string ()
|
250
|
+
;; (list (random-string)
|
251
|
+
;; (random-string)
|
252
|
+
;; (random-string)
|
253
|
+
;; (random-string)
|
254
|
+
;; (random-string)
|
255
|
+
;; (random-string)
|
256
|
+
;; (random-string)
|
257
|
+
;; (random-string)
|
258
|
+
;; (random-string)
|
259
|
+
;; (random-string)))
|
207
260
|
|
208
261
|
(def bm-repeat (f n)
|
209
262
|
; used in benchmarking
|
@@ -223,8 +276,13 @@
|
|
223
276
|
(p "================================================\n")
|
224
277
|
"~desc : total ~(just times), average ~(/ times repeats) per run"))
|
225
278
|
|
279
|
+
|
280
|
+
|
226
281
|
(def rbs (name)
|
227
282
|
(let summary nil
|
283
|
+
;; (push (bm "random string " bm-random-string 10 20000) summary)
|
284
|
+
;; (push (bm "string concatenation " bm-string-concat 10 20000) summary)
|
285
|
+
;; (push (bm "type-of " bm-type-of 10 20000) summary)
|
228
286
|
;; (push (bm "accum " bm-acc 10 500) summary)
|
229
287
|
;; (push (bm "accum " bm-facc 10 500) summary)
|
230
288
|
;; (push (bm "mapsum " bm-mapsum 10 100) summary)
|
@@ -4,4 +4,31 @@
|
|
4
4
|
(a 1)
|
5
5
|
(a 2)
|
6
6
|
(a 3))
|
7
|
-
(1 2 3))
|
7
|
+
(1 2 3))
|
8
|
+
|
9
|
+
("accum function returns the accumulated object in each case"
|
10
|
+
(let watcher nil
|
11
|
+
(let accumulated (accum b
|
12
|
+
(= watcher (cons (b 1) watcher))
|
13
|
+
(= watcher (cons (b 2) watcher))
|
14
|
+
(= watcher (cons (b 3) watcher)))
|
15
|
+
(list 'watcher watcher 'accumulated accumulated)))
|
16
|
+
(watcher (3 2 1)
|
17
|
+
accumulated (1 2 3))))
|
18
|
+
|
19
|
+
(examples-for accum-hash
|
20
|
+
("accumulate the values passed to a given function under the given key, return the resulting hash"
|
21
|
+
(let h
|
22
|
+
(accum-hash hi
|
23
|
+
(hi 'a 1)
|
24
|
+
(hi 'a 2)
|
25
|
+
(hi 'b 42)
|
26
|
+
(hi 'b 43)
|
27
|
+
(hi 'a 3)
|
28
|
+
(hi 'b 44)
|
29
|
+
(hi 'c 'x)
|
30
|
+
(hi 'a 4)
|
31
|
+
(hi 'c 'y)
|
32
|
+
(hi 'c 'z))
|
33
|
+
(list h.a h.b h.c))
|
34
|
+
((4 3 2 1) (44 43 42) (z y x))))
|
@@ -12,9 +12,14 @@
|
|
12
12
|
"hello world")
|
13
13
|
|
14
14
|
("recurses as necessary"
|
15
|
-
(explain-mac
|
16
|
-
(let it (a) (if it (b) (
|
15
|
+
(explain-mac 2 '(aif (a) (b) (c) (d) (e)))
|
16
|
+
(let it (a) (if it (b) (ifv it (c) (d) (e)))))
|
17
|
+
|
18
|
+
("assigns each successive condition to 'it"
|
19
|
+
(aif (eq? 1 2) nil
|
20
|
+
42 (list it it))
|
21
|
+
(42 42))
|
17
22
|
|
18
23
|
("avoids unnecessary expansion"
|
19
|
-
(explain-mac
|
24
|
+
(explain-mac 2 '(aif (a) (b) (c)))
|
20
25
|
(let it (a) (if it (b) (c)))))
|
@@ -0,0 +1,7 @@
|
|
1
|
+
(examples-for andify
|
2
|
+
("takes a list of functions A and returns a function that applies its arguments to each f in A in turn, returning the logical AND of the set of return values"
|
3
|
+
(with (even? λn(eq? (mod n 2) 0)
|
4
|
+
triple? λn(eq? (mod n 3) 0)
|
5
|
+
big? λn(> n 10))
|
6
|
+
(select (andify even? triple? big?) (range -10 31)))
|
7
|
+
(12 18 24 30)))
|
@@ -0,0 +1,17 @@
|
|
1
|
+
(examples-for at-syntax
|
2
|
+
("at-symbol as argument"
|
3
|
+
(let @ {}
|
4
|
+
(= @foo 1)
|
5
|
+
(= @bar 2)
|
6
|
+
(list @foo @bar))
|
7
|
+
(1 2))
|
8
|
+
|
9
|
+
("at-syntax assignment"
|
10
|
+
(pre-compile '(= @a 42))
|
11
|
+
(hash-set @ 'a 42))
|
12
|
+
|
13
|
+
("mixed at-syntax and dot-syntax assignment"
|
14
|
+
(pre-compile '(= @a.b 42))
|
15
|
+
(hash-set (hash-get @ 'a) 'b 42)))
|
16
|
+
|
17
|
+
;; (let @ {} 123)
|
@@ -19,6 +19,15 @@
|
|
19
19
|
(best > '(c g d o a p b m e g a z m))
|
20
20
|
z)
|
21
21
|
|
22
|
+
("finds object with max size"
|
23
|
+
(to-string:best (map-compare-f > &size)
|
24
|
+
(list { i 0 size 3 }
|
25
|
+
{ i 1 size 1 }
|
26
|
+
{ i 2 size 7 }
|
27
|
+
{ i 3 size 4 }
|
28
|
+
{ i 4 size 5 }))
|
29
|
+
"{i=>2, size=>7}")
|
30
|
+
|
22
31
|
("finds maximum of list of numbers"
|
23
32
|
(best > '(3 5 4 7 8 2))
|
24
33
|
8))
|
@@ -84,3 +84,22 @@
|
|
84
84
|
|
85
85
|
(examples-for mod
|
86
86
|
("modulus for two ints" (mod 64 6) 4))
|
87
|
+
|
88
|
+
(examples-for abs
|
89
|
+
("a positive integer" (abs 64) 64)
|
90
|
+
("a negative integer" (abs -42) 42)
|
91
|
+
("zero" (abs 0) 0)
|
92
|
+
("negative zero" (abs -0) 0)
|
93
|
+
("float zero" (abs 0.0) 0)
|
94
|
+
("float negative zero" (abs -0.0) 0)
|
95
|
+
("float negative" (abs -1.6) 1.6)
|
96
|
+
("float positive" (abs 4.2) 4.2))
|
97
|
+
|
98
|
+
(examples-for inspect
|
99
|
+
("truth" (inspect t) "t")
|
100
|
+
("nil" (inspect nil) "nil")
|
101
|
+
("number" (inspect 42) "42")
|
102
|
+
("string" (inspect "hello") "\"hello\"")
|
103
|
+
("list" (inspect '(fn (x) (this that))) "(fn (x) (this that))")
|
104
|
+
("list with string" (inspect '(fn (x) (this "string"))) "(fn (x) (this \"string\"))")
|
105
|
+
("list with sym" (inspect '(fn (x) (this 'quoted))) "(fn (x) (this (quote quoted)))"))
|
@@ -0,0 +1,14 @@
|
|
1
|
+
(examples-for 'case
|
2
|
+
("expands to an if-expression"
|
3
|
+
(do (reset-uniq-counter)
|
4
|
+
(explain-mac 1
|
5
|
+
`(case eq? person.name
|
6
|
+
"conan" (greet person)
|
7
|
+
"egg" (delete person)
|
8
|
+
"bach" (play person)
|
9
|
+
else (interrogate person))))
|
10
|
+
(let caseval-1 (dot-syntax person name)
|
11
|
+
(if (eq? caseval-1 "conan") (greet person)
|
12
|
+
(eq? caseval-1 "egg") (delete person)
|
13
|
+
(eq? caseval-1 "bach") (play person)
|
14
|
+
(interrogate person)))))
|
@@ -18,6 +18,9 @@
|
|
18
18
|
("navigates to week end from sun" (let d (date 2015 11 1) (to-string d.end-of-week)) "2015-11-01" )
|
19
19
|
("navigates to week end" (let d (date 2015 11 6) (to-string d.end-of-week)) "2015-11-08" )
|
20
20
|
|
21
|
+
("works with apply" (to-string (apply date '(2006 6 21))) "2006-06-21")
|
22
|
+
("works with apply again" (to-string (apply date 2006 6 21 nil)) "2006-06-21")
|
23
|
+
|
21
24
|
("parses string" (let d (date "2004-03-12") (list d.year d.month d.day)) (2004 3 12))
|
22
25
|
|
23
26
|
("can act as hash key"
|
@@ -47,4 +50,54 @@
|
|
47
50
|
("adds days" (let d (date 2015 11 8) (to-string (+ d 1))) "2015-11-09")
|
48
51
|
("adds more days" (let d (date 2015 11 8) (to-string (+ d 10))) "2015-11-18")
|
49
52
|
("subtracts a day" (let d (date 2015 11 18) (to-string (- d 1))) "2015-11-17")
|
50
|
-
("subtracts more days" (let d (date 2015 11 18) (to-string (- d 5))) "2015-11-13")
|
53
|
+
("subtracts more days" (let d (date 2015 11 18) (to-string (- d 5))) "2015-11-13")
|
54
|
+
|
55
|
+
("advances by -2 weeks" (let d (date 1965 6 8) (to-string (+ d '(-2 week)))) "1965-05-25")
|
56
|
+
("advances by -1 week" (let d (date 1965 6 8) (to-string (+ d '(-1 week)))) "1965-06-01")
|
57
|
+
("advances by 1 week" (let d (date 1965 6 8) (to-string (+ d '( 1 week)))) "1965-06-15")
|
58
|
+
("advances by 2 weeks" (let d (date 1965 6 8) (to-string (+ d '( 2 week)))) "1965-06-22")
|
59
|
+
|
60
|
+
("advances by -2 weeks" (let d (date 1965 6 8) (to-string (+ d '(-2 week)))) "1965-05-25")
|
61
|
+
("advances by -1 week" (let d (date 1965 6 8) (to-string (+ d '(-1 week)))) "1965-06-01")
|
62
|
+
("advances by 1 week" (let d (date 1965 6 8) (to-string (+ d '( 1 week)))) "1965-06-15")
|
63
|
+
("advances by 2 weeks" (let d (date 1965 6 8) (to-string (+ d '( 2 week)))) "1965-06-22")
|
64
|
+
|
65
|
+
("advances by -2 days" (let d (date 1965 6 8) (to-string (+ d '(-2 day)))) "1965-06-06")
|
66
|
+
("advances by -1 day" (let d (date 1965 6 8) (to-string (+ d '(-1 day)))) "1965-06-07")
|
67
|
+
("advances by 1 day" (let d (date 1965 6 8) (to-string (+ d '( 1 day)))) "1965-06-09")
|
68
|
+
("advances by 2 days" (let d (date 1965 6 8) (to-string (+ d '( 2 day)))) "1965-06-10")
|
69
|
+
|
70
|
+
("advances by -2 months" (let d (date 1965 6 8) (to-string (+ d '(-2 month)))) "1965-04-08")
|
71
|
+
("advances by -1 month" (let d (date 1965 6 8) (to-string (+ d '(-1 month)))) "1965-05-08")
|
72
|
+
("advances by 1 month" (let d (date 1965 6 8) (to-string (+ d '( 1 month)))) "1965-07-08")
|
73
|
+
("advances by 2 months" (let d (date 1965 6 8) (to-string (+ d '( 2 month)))) "1965-08-08")
|
74
|
+
|
75
|
+
("advances by -2 years" (let d (date 1965 6 8) (to-string (+ d '(-2 year)))) "1963-06-08")
|
76
|
+
("advances by -1 year" (let d (date 1965 6 8) (to-string (+ d '(-1 year)))) "1964-06-08")
|
77
|
+
("advances by 1 year" (let d (date 1965 6 8) (to-string (+ d '( 1 year)))) "1966-06-08")
|
78
|
+
("advances by 2 years" (let d (date 1965 6 8) (to-string (+ d '( 2 year)))) "1967-06-08")
|
79
|
+
|
80
|
+
("adapts for leap years" (let d (date 2019 12 31) (to-string (+ d '( 2 month)))) "2020-02-29")
|
81
|
+
("jumps one year" (let d (date 2019 12 31) (to-string (+ d '( 1 year) ))) "2020-12-31")
|
82
|
+
("jumps to 28 feb a year later" (let d (date 2019 12 31) (to-string (+ d '(14 month)))) "2021-02-28")
|
83
|
+
("jumps to end of june" (let d (date 2019 12 31) (to-string (+ d '( 6 month)))) "2020-06-30")
|
84
|
+
("jumps to end of july" (let d (date 2019 12 31) (to-string (+ d '( 7 month)))) "2020-07-31")
|
85
|
+
("jumps from end feb to end feb" (let d (date 2020 02 29) (to-string (+ d '(12 month)))) "2021-02-28")
|
86
|
+
|
87
|
+
("finds anniversary before a given date in previous year"
|
88
|
+
(to-string (anniversary/previous (date 2019 6 21) (date 1949 10 3)))
|
89
|
+
"2018-10-03")
|
90
|
+
|
91
|
+
("finds anniversary before a given date in same year"
|
92
|
+
(to-string (anniversary/previous (date 2019 11 20) (date 1949 10 3)))
|
93
|
+
"2019-10-03")
|
94
|
+
|
95
|
+
("finds anniversary after a given date in same year"
|
96
|
+
(to-string (anniversary/next (date 2019 6 21) (date 1949 10 3)))
|
97
|
+
"2019-10-03")
|
98
|
+
|
99
|
+
|
100
|
+
("finds anniversary after a given date in following year"
|
101
|
+
(to-string (anniversary/next (date 2019 11 20) (date 1949 10 3)))
|
102
|
+
"2020-10-03")
|
103
|
+
)
|
@@ -20,25 +20,25 @@
|
|
20
20
|
|
21
21
|
(examples-for destructure/build
|
22
22
|
("with no args"
|
23
|
-
(destructure/build nil nil '(x))
|
23
|
+
(destructure/build nil nil '(x) (fn (a b) `(fn ,a ,@b)))
|
24
24
|
(fn nil x))
|
25
25
|
|
26
26
|
("with one arg"
|
27
|
-
(destructure/build '(a) nil '(x))
|
27
|
+
(destructure/build '(a) nil '(x) (fn (a b) `(fn ,a ,@b)))
|
28
28
|
(fn (a) x))
|
29
29
|
|
30
30
|
("with one rest-arg"
|
31
|
-
(destructure/build 'args nil '(x))
|
31
|
+
(destructure/build 'args nil '(x) (fn (a b) `(fn ,a ,@b)))
|
32
32
|
(fn args x))
|
33
33
|
|
34
34
|
("with one destructuring arg"
|
35
35
|
(do (reset-uniq-counter)
|
36
|
-
(destructure/build '((a b)) nil '(x)))
|
36
|
+
(destructure/build '((a b)) nil '(x) (fn (a b) `(fn ,a ,@b))))
|
37
37
|
(fn (destructure-1) (with (a (nth 0 destructure-1) b (nth 1 destructure-1)) x)))
|
38
38
|
|
39
39
|
("with complex args"
|
40
40
|
(do (reset-uniq-counter)
|
41
|
-
(destructure/build '(a (b c) (d (e f)) g . h) nil '(x)))
|
41
|
+
(destructure/build '(a (b c) (d (e f)) g . h) nil '(x) (fn (a b) `(fn ,a ,@b))))
|
42
42
|
(fn (a destructure-1 destructure-2 g . h)
|
43
43
|
(with (d (nth 0 destructure-2)
|
44
44
|
(e f) (nth 1 destructure-2))
|
@@ -49,12 +49,23 @@
|
|
49
49
|
(examples-for fun
|
50
50
|
("complete expansion, handles recursive destructures"
|
51
51
|
(do (reset-uniq-counter)
|
52
|
-
(pre-compile '(fun ((a (b c)) d . e)
|
52
|
+
(pre-compile '(fun ((a (b c)) d . e) (do-the-thing a b c d e))))
|
53
53
|
(fn (destructure-1 d . e)
|
54
54
|
((fn (a destructure-2)
|
55
|
-
((fn (b c)
|
56
|
-
|
57
|
-
|
55
|
+
((fn (b c)
|
56
|
+
((fn nil
|
57
|
+
(assign b (nth 0 destructure-2))
|
58
|
+
(assign c (nth 1 destructure-2))))
|
59
|
+
((fn nil
|
60
|
+
(assign a (nth 0 destructure-1))
|
61
|
+
((fn (destructuring-assign-3)
|
62
|
+
(assign b (car destructuring-assign-3))
|
63
|
+
(assign c (car (cdr destructuring-assign-3))))
|
64
|
+
(nth 1 destructure-1))))
|
65
|
+
(do-the-thing a b c d e))
|
66
|
+
nil))
|
67
|
+
nil)))
|
68
|
+
|
58
69
|
|
59
70
|
("nested improper arguments"
|
60
71
|
(let (a (b c . d) e) (list "A" (list "B" "C" "D0" "D1" "D2") "E")
|
@@ -66,12 +77,12 @@
|
|
66
77
|
(do (without-hooks 'warnings/new
|
67
78
|
λ(on-err nil
|
68
79
|
(pre-compile '(fun (aif (and or) . when)
|
69
|
-
|
80
|
+
ignore))))
|
70
81
|
warnings/list)
|
71
|
-
((arg-shadows-macro "arg " when " shadows macro " when " in arg list " (aif (and or) . when))
|
72
|
-
(arg-shadows-macro "arg "
|
73
|
-
(arg-shadows-macro "arg "
|
74
|
-
(arg-shadows-macro "arg "
|
82
|
+
((arg-shadows-macro "arg " when " shadows macro " when " in arg list " (aif (and or) . when) " and body " (ignore) )
|
83
|
+
(arg-shadows-macro "arg " or " shadows macro " or " in arg list " (aif (and or) . when) " and body " (ignore) )
|
84
|
+
(arg-shadows-macro "arg " and " shadows macro " and " in arg list " (aif (and or) . when) " and body " (ignore) )
|
85
|
+
(arg-shadows-macro "arg " aif " shadows macro " aif " in arg list " (aif (and or) . when) " and body " (ignore) )))
|
75
86
|
|
76
87
|
("implicit in 'let and 'with"
|
77
88
|
(with ((a b) (list "h" "e")
|
@@ -79,3 +90,24 @@
|
|
79
90
|
(let (g (h (i j) k)) (list "w" (list "o" (list "r" "l") "d"))
|
80
91
|
(string-pieces a b c d e f g h i j k)))
|
81
92
|
"hello world"))
|
93
|
+
|
94
|
+
(examples-for =
|
95
|
+
("destructures LHS"
|
96
|
+
(let a 1
|
97
|
+
(let b 2
|
98
|
+
(let c 3
|
99
|
+
(let d 4
|
100
|
+
(let e 5
|
101
|
+
(= (a (b e) c . d) (list 'this '(that those) 'another 11 22 33))
|
102
|
+
(list a b c d e))))))
|
103
|
+
(this that another (11 22 33) those)))
|
104
|
+
|
105
|
+
(examples-for with
|
106
|
+
("destructures its args, also allows references to earlier args"
|
107
|
+
(with ((a (b . c) d . e) '(1 (2 3 4 5) 6 7 8 9)
|
108
|
+
x a
|
109
|
+
y c
|
110
|
+
z (fn (n) (if (eq? n 1) 1 (* n (z (- n 1)))))
|
111
|
+
g (z 6))
|
112
|
+
(list a b c d e x y g))
|
113
|
+
(1 2 (3 4 5) 6 (7 8 9) 1 (3 4 5) 720)))
|
@@ -26,6 +26,18 @@
|
|
26
26
|
"zz")
|
27
27
|
nil)
|
28
28
|
|
29
|
+
("empty list"
|
30
|
+
(detect present? nil)
|
31
|
+
nil)
|
32
|
+
|
33
|
+
("present? for list of empty things"
|
34
|
+
(detect present? (list "" nil {} ()))
|
35
|
+
nil)
|
36
|
+
|
37
|
+
("present? for mostly empty things"
|
38
|
+
(detect present? (list "" nil 42 {} ()))
|
39
|
+
42)
|
40
|
+
|
29
41
|
("nil for nil"
|
30
42
|
(detect nil nil)
|
31
43
|
nil)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
(examples-for dp
|
2
|
+
("returns nil for nil"
|
3
|
+
(dp)
|
4
|
+
nil)
|
5
|
+
|
6
|
+
("returns nil when everything is empty"
|
7
|
+
(dp "" nil {} ())
|
8
|
+
nil)
|
9
|
+
|
10
|
+
("returns the first item if not empty"
|
11
|
+
(dp 'a "" {} ())
|
12
|
+
a)
|
13
|
+
|
14
|
+
("returns the second item if not empty"
|
15
|
+
(dp "" 'b "" {} ())
|
16
|
+
b)
|
17
|
+
|
18
|
+
("returns the third item if not empty"
|
19
|
+
(dp "" {} 'c "" {} ())
|
20
|
+
c)
|
21
|
+
|
22
|
+
("returns the last item if not empty"
|
23
|
+
(dp "" {} () 'd)
|
24
|
+
d))
|