1 ;; Testing trivial macros
2 (defmacro! one (fn* () 1))
5 (defmacro! two (fn* () 2))
9 ;; Testing unless macros
10 (defmacro! unless (fn* (pred a b) `(if ~pred ~b ~a)))
15 (defmacro! unless2 (fn* (pred a b) (list 'if (list 'not pred) a b)))
21 ;; Testing macroexpand
24 (macroexpand (unless PRED A B))
26 (macroexpand (unless2 PRED A B))
27 ;=>(if (not PRED) A B)
28 (macroexpand (unless2 2 3 4))
31 ;; Testing evaluation of macro result
32 (defmacro! identity (fn* (x) x))
33 (let* (a 123) (macroexpand (identity a)))
35 (let* (a 123) (identity a))
38 ;; Test that macros do not break empty list
42 ;; Test that macros do not break quasiquote
48 ;; -------- Deferrable Functionality --------
50 ;; Testing non-macro function
53 ;;; This should fail if it is a macro
57 ;; Testing nth, first and rest functions
63 (nth (list 1 2 nil) 2)
66 (def! x (nth (list 1 2) 2))
91 (macroexpand (cond X Y))
97 (macroexpand (cond X Y Z T))
98 ;=>(if X Y (cond Z T))
101 (cond false 7 true 8)
103 (cond false 7 false 8 "else" 9)
105 (cond false 7 (= 2 2) 8 "else" 9)
107 (cond false 7 false 8 false 9)
110 ;; Testing EVAL in let*
112 (let* (x (cond false "no" true "yes")) x)
116 ;; Testing nth, first, rest with vectors
125 (def! x (nth [1 2] 2))
145 (rest (cons 10 [11 12]))
148 ;; Testing EVAL in vector let*
150 (let* [x (cond false "no" true "yes")] x)
156 ;; ------- Optional Functionality --------------
157 ;; ------- (Not needed for self-hosting) -------
159 ;; Test that macros use closures
161 (defmacro! a (fn* [] x))