nydp 0.4.0 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -0
- data/lib/lisp/core-010-precompile.nydp +13 -16
- data/lib/lisp/core-012-utils.nydp +21 -6
- data/lib/lisp/core-015-documentation.nydp +60 -19
- data/lib/lisp/core-017-builtin-dox.nydp +50 -39
- data/lib/lisp/core-020-utils.nydp +5 -5
- data/lib/lisp/core-030-syntax.nydp +103 -61
- data/lib/lisp/core-035-flow-control.nydp +18 -9
- data/lib/lisp/core-037-list-utils.nydp +36 -14
- data/lib/lisp/core-039-module.nydp +24 -0
- data/lib/lisp/core-040-utils.nydp +41 -23
- data/lib/lisp/core-041-string-utils.nydp +37 -9
- data/lib/lisp/core-042-date-utils.nydp +21 -1
- data/lib/lisp/core-043-list-utils.nydp +93 -67
- data/lib/lisp/core-045-dox-utils.nydp +5 -0
- data/lib/lisp/core-080-pretty-print.nydp +55 -17
- data/lib/lisp/core-090-hook.nydp +35 -1
- data/lib/lisp/core-100-utils.nydp +130 -28
- data/lib/lisp/core-110-hash-utils.nydp +61 -0
- data/lib/lisp/core-120-settings.nydp +46 -0
- data/lib/lisp/core-130-validations.nydp +51 -0
- data/lib/lisp/{core-060-benchmarking.nydp → core-900-benchmarking.nydp} +108 -5
- 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/cdr-set-examples.nydp +6 -0
- data/lib/lisp/tests/date-examples.nydp +56 -1
- data/lib/lisp/tests/destructuring-examples.nydp +5 -5
- data/lib/lisp/tests/detect-examples.nydp +12 -0
- data/lib/lisp/tests/dp-examples.nydp +24 -0
- data/lib/lisp/tests/empty-examples.nydp +1 -1
- data/lib/lisp/tests/error-tests.nydp +4 -4
- data/lib/lisp/tests/filter-forms-examples.nydp +30 -0
- data/lib/lisp/tests/foundation-test.nydp +12 -0
- data/lib/lisp/tests/hash-examples.nydp +26 -2
- 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/mapreduce-examples.nydp +10 -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 +21 -0
- data/lib/lisp/tests/pretty-print-tests.nydp +16 -13
- data/lib/lisp/tests/set-difference-examples.nydp +8 -0
- data/lib/lisp/tests/set-intersection-examples.nydp +32 -0
- data/lib/lisp/tests/set-union-examples.nydp +24 -0
- data/lib/lisp/tests/settings-examples.nydp +40 -0
- data/lib/lisp/tests/sort-examples.nydp +8 -0
- data/lib/lisp/tests/string-tests.nydp +61 -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/lisp/tests/zap-examples.nydp +12 -0
- data/lib/nydp.rb +13 -7
- 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/cdr_set.rb +1 -6
- data/lib/nydp/builtin/date.rb +15 -1
- data/lib/nydp/builtin/error.rb +1 -1
- data/lib/nydp/builtin/handle_error.rb +1 -1
- data/lib/nydp/builtin/hash.rb +27 -45
- data/lib/nydp/builtin/inspect.rb +1 -1
- data/lib/nydp/builtin/plus.rb +10 -2
- data/lib/nydp/builtin/rand.rb +18 -0
- data/lib/nydp/builtin/random_string.rb +2 -2
- data/lib/nydp/builtin/ruby_wrap.rb +72 -0
- data/lib/nydp/builtin/set_intersection.rb +8 -0
- data/lib/nydp/builtin/set_union.rb +8 -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 +1 -1
- data/lib/nydp/builtin/string_split.rb +1 -2
- 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 +45 -33
- data/lib/nydp/core_ext.rb +54 -0
- data/lib/nydp/date.rb +37 -31
- data/lib/nydp/function_invocation.rb +34 -26
- data/lib/nydp/hash.rb +5 -6
- data/lib/nydp/helper.rb +41 -25
- data/lib/nydp/interpreted_function.rb +68 -40
- data/lib/nydp/literal.rb +1 -1
- data/lib/nydp/pair.rb +25 -9
- data/lib/nydp/parser.rb +8 -6
- data/lib/nydp/string_atom.rb +16 -22
- data/lib/nydp/symbol.rb +40 -27
- data/lib/nydp/symbol_lookup.rb +7 -7
- data/lib/nydp/tokeniser.rb +2 -2
- data/lib/nydp/truth.rb +17 -10
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp/vm.rb +7 -2
- data/nydp.gemspec +2 -4
- data/spec/date_spec.rb +115 -22
- 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/parser_spec.rb +27 -16
- data/spec/rand_spec.rb +45 -0
- data/spec/spec_helper.rb +13 -1
- data/spec/symbol_spec.rb +31 -0
- data/spec/time_spec.rb +1 -1
- metadata +38 -37
- data/lib/nydp/builtin/car.rb +0 -7
- data/lib/nydp/builtin/cdr.rb +0 -7
- data/lib/nydp/builtin/cons.rb +0 -9
@@ -0,0 +1,51 @@
|
|
1
|
+
(chapter-start 'validations "utilities to record and run validation routines")
|
2
|
+
|
3
|
+
(let validations {}
|
4
|
+
(def validate/reset ()
|
5
|
+
(= validations {}))
|
6
|
+
(def validate/fns (thing context)
|
7
|
+
(hash-get validations (list (type-of thing) context)))
|
8
|
+
(def validate/fn+ (type context f)
|
9
|
+
(hash-cons validations (list type context) f)))
|
10
|
+
|
11
|
+
;;
|
12
|
+
;; returns a hash of error-name to list of error messages
|
13
|
+
;;
|
14
|
+
;; An empty return value signifies an error-free 'thing
|
15
|
+
;;
|
16
|
+
(def validate (thing context)
|
17
|
+
(returnlet msgs {}
|
18
|
+
(let msgf λem(hash-cons msgs e m)
|
19
|
+
(eachl λv(v thing context msgf)
|
20
|
+
(validate/fns thing context)))))
|
21
|
+
|
22
|
+
;; declare a validation routine for type 'type in context 'context
|
23
|
+
;;
|
24
|
+
;; 'type must be a symbol
|
25
|
+
;; 'context must be a symbol
|
26
|
+
;; 'body is one or more nydp expressions.
|
27
|
+
;;
|
28
|
+
;; 'body will be embedded in a function with access to the following variables :
|
29
|
+
;;
|
30
|
+
;; * the value of the 'type argument
|
31
|
+
;; * ctx
|
32
|
+
;; * mf
|
33
|
+
;;
|
34
|
+
;; 'mf ("message function") is a function that takes two arguments and is used to store
|
35
|
+
;; the validation error message
|
36
|
+
;; example: (mf "Last name" "Last name must not be empty")
|
37
|
+
;;
|
38
|
+
;; example usage:
|
39
|
+
;;
|
40
|
+
;; (validate/def invoice issue
|
41
|
+
;; (if (no invoice.account)
|
42
|
+
;; (mf "Account" "Account must be a client account"))
|
43
|
+
;; (if (!> invoice.total 0)
|
44
|
+
;; (mf "Amount" "Amount must be greater than zero"))
|
45
|
+
;; (if (any? !&group invoice.invoice-items)
|
46
|
+
;; (mf "Group" "Each line must be assigned to a group")))
|
47
|
+
;;
|
48
|
+
;; if your routine makes no call to 'mf then 'validate will return an empty hash, which should be
|
49
|
+
;; interpreted as signifying that the object in question is error free in the given context.
|
50
|
+
(mac validate/def (type context . body)
|
51
|
+
`(validate/fn+ ',type ',context (fn (,type ctx mf) ,@body)))
|
@@ -159,10 +159,104 @@
|
|
159
159
|
;; (= h.ca v1) (= h.cb v2) (= h.cc v3) (= h.ca v4) (= h.cb v5) (= h.cc v6)
|
160
160
|
;; (= h.da v1) (= h.db v2) (= h.dc v3) (= h.da v4) (= h.db v5) (= h.dc v6)))
|
161
161
|
|
162
|
-
(def bm-
|
163
|
-
(
|
164
|
-
(
|
165
|
-
(
|
162
|
+
;; (def bm-acc ()
|
163
|
+
;; (accum z
|
164
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
165
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
166
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
167
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
168
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
169
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
170
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
171
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
172
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)))
|
173
|
+
|
174
|
+
;; (def bm-facc ()
|
175
|
+
;; (faccum z
|
176
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
177
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
178
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
179
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
180
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
181
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
182
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
183
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)
|
184
|
+
;; (z 0) (z 1) (z 2) (z 3) (z 4) (z 5) (z 6) (z 7) (z 8) (z 9)))
|
185
|
+
|
186
|
+
(in-private
|
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)))
|
166
260
|
|
167
261
|
(def bm-repeat (f n)
|
168
262
|
; used in benchmarking
|
@@ -182,9 +276,18 @@
|
|
182
276
|
(p "================================================\n")
|
183
277
|
"~desc : total ~(just times), average ~(/ times repeats) per run"))
|
184
278
|
|
279
|
+
|
280
|
+
|
185
281
|
(def rbs (name)
|
186
282
|
(let summary nil
|
187
|
-
(push (bm "
|
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)
|
286
|
+
;; (push (bm "accum " bm-acc 10 500) summary)
|
287
|
+
;; (push (bm "accum " bm-facc 10 500) summary)
|
288
|
+
;; (push (bm "mapsum " bm-mapsum 10 100) summary)
|
289
|
+
;; (push (bm "mapreduce " bm-mapreduce 10 100) summary)
|
290
|
+
;; (push (bm "cond with OR " bm-faster-or 10 40000) summary)
|
188
291
|
;; (push (bm "cond with OR " bm-cond-9 10 40000) summary)
|
189
292
|
;; (push (bm "cond with OR " bm-cond-9 10 100000) summary)
|
190
293
|
;; (push (bm "cond with OR " bm-cond-lex-lit-lit 10 100000) 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,11 @@
|
|
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
|
+
|
24
|
+
("parses string" (let d (date "2004-03-12") (list d.year d.month d.day)) (2004 3 12))
|
25
|
+
|
21
26
|
("can act as hash key"
|
22
27
|
(with (h {} d (date 2015 11 8))
|
23
28
|
(hash-set h d "on this day")
|
@@ -45,4 +50,54 @@
|
|
45
50
|
("adds days" (let d (date 2015 11 8) (to-string (+ d 1))) "2015-11-09")
|
46
51
|
("adds more days" (let d (date 2015 11 8) (to-string (+ d 10))) "2015-11-18")
|
47
52
|
("subtracts a day" (let d (date 2015 11 18) (to-string (- d 1))) "2015-11-17")
|
48
|
-
("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
|
+
)
|
@@ -66,12 +66,12 @@
|
|
66
66
|
(do (without-hooks 'warnings/new
|
67
67
|
λ(on-err nil
|
68
68
|
(pre-compile '(fun (aif (and or) . when)
|
69
|
-
|
69
|
+
ignore))))
|
70
70
|
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 "
|
71
|
+
((arg-shadows-macro "arg " when " shadows macro " when " in arg list " (aif (and or) . when) " and body " (ignore) )
|
72
|
+
(arg-shadows-macro "arg " or " shadows macro " or " in arg list " (aif (and or) . when) " and body " (ignore) )
|
73
|
+
(arg-shadows-macro "arg " and " shadows macro " and " in arg list " (aif (and or) . when) " and body " (ignore) )
|
74
|
+
(arg-shadows-macro "arg " aif " shadows macro " aif " in arg list " (aif (and or) . when) " and body " (ignore) )))
|
75
75
|
|
76
76
|
("implicit in 'let and 'with"
|
77
77
|
(with ((a b) (list "h" "e")
|
@@ -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))
|