lib/lisp/tests/destructuring-examples.nydp in nydp-0.4.6 vs lib/lisp/tests/destructuring-examples.nydp in nydp-0.5.0
- old
+ new
@@ -18,46 +18,57 @@
g (nth 3 xxx)
h (nthcdr 4 xxx))))
(examples-for destructure/build
("with no args"
- (destructure/build nil nil '(x))
+ (destructure/build nil nil '(x) (fn (a b) `(fn ,a ,@b)))
(fn nil x))
("with one arg"
- (destructure/build '(a) nil '(x))
+ (destructure/build '(a) nil '(x) (fn (a b) `(fn ,a ,@b)))
(fn (a) x))
("with one rest-arg"
- (destructure/build 'args nil '(x))
+ (destructure/build 'args nil '(x) (fn (a b) `(fn ,a ,@b)))
(fn args x))
("with one destructuring arg"
(do (reset-uniq-counter)
- (destructure/build '((a b)) nil '(x)))
+ (destructure/build '((a b)) nil '(x) (fn (a b) `(fn ,a ,@b))))
(fn (destructure-1) (with (a (nth 0 destructure-1) b (nth 1 destructure-1)) x)))
("with complex args"
(do (reset-uniq-counter)
- (destructure/build '(a (b c) (d (e f)) g . h) nil '(x)))
+ (destructure/build '(a (b c) (d (e f)) g . h) nil '(x) (fn (a b) `(fn ,a ,@b))))
(fn (a destructure-1 destructure-2 g . h)
(with (d (nth 0 destructure-2)
(e f) (nth 1 destructure-2))
(with (b (nth 0 destructure-1)
c (nth 1 destructure-1))
x)))))
(examples-for fun
("complete expansion, handles recursive destructures"
(do (reset-uniq-counter)
- (pre-compile '(fun ((a (b c)) d . e) x)))
+ (pre-compile '(fun ((a (b c)) d . e) (do-the-thing a b c d e))))
(fn (destructure-1 d . e)
((fn (a destructure-2)
- ((fn (b c) x)
- (nth 0 destructure-2)
- (nth 1 destructure-2))) (nth 0 destructure-1) (nth 1 destructure-1))))
+ ((fn (b c)
+ ((fn nil
+ (assign b (nth 0 destructure-2))
+ (assign c (nth 1 destructure-2))))
+ ((fn nil
+ (assign a (nth 0 destructure-1))
+ ((fn (destructuring-assign-3)
+ (assign b (car destructuring-assign-3))
+ (assign c (car (cdr destructuring-assign-3))))
+ (nth 1 destructure-1))))
+ (do-the-thing a b c d e))
+ nil))
+ nil)))
+
("nested improper arguments"
(let (a (b c . d) e) (list "A" (list "B" "C" "D0" "D1" "D2") "E")
(string-pieces a b c d e))
"ABCD0D1D2E")
@@ -77,5 +88,26 @@
(with ((a b) (list "h" "e")
(c (d e f)) (list "l" (list "l" "o" " ")))
(let (g (h (i j) k)) (list "w" (list "o" (list "r" "l") "d"))
(string-pieces a b c d e f g h i j k)))
"hello world"))
+
+(examples-for =
+ ("destructures LHS"
+ (let a 1
+ (let b 2
+ (let c 3
+ (let d 4
+ (let e 5
+ (= (a (b e) c . d) (list 'this '(that those) 'another 11 22 33))
+ (list a b c d e))))))
+ (this that another (11 22 33) those)))
+
+(examples-for with
+ ("destructures its args, also allows references to earlier args"
+ (with ((a (b . c) d . e) '(1 (2 3 4 5) 6 7 8 9)
+ x a
+ y c
+ z (fn (n) (if (eq? n 1) 1 (* n (z (- n 1)))))
+ g (z 6))
+ (list a b c d e x y g))
+ (1 2 (3 4 5) 6 (7 8 9) 1 (3 4 5) 720)))