macros.glisp 454 B

1234567891011121314151617181920
  1. (def l '(1 2 3))
  2. (def b 4)
  3. (assert (= `(0 ~@l ~b) '(0 1 2 3 4)))
  4. (defmac when [predicate & body]
  5. `(cond ~predicate
  6. (begin
  7. ~@body) '()))
  8. (assert (null? (when false 'c)))
  9. (assert (= 'a (when true 'c 'b 'a)))
  10. (assert (=
  11. '(cond false (begin (quote c)) (quote ()))
  12. (macexpand (when false 'c))))
  13. (assert (=
  14. '(cond true (begin (quote c) (quote b) (quote a)) (quote ()))
  15. (macexpand (when true 'c 'b 'a))))