Commit | Line | Data |
---|---|---|
31690700 JM |
1 | ;; Testing trivial macros |
2 | (defmacro! one (fn* () 1)) | |
3 | (one) | |
4 | ;=>1 | |
5 | (defmacro! two (fn* () 2)) | |
6 | (two) | |
7 | ;=>2 | |
8 | ||
9 | ;; Testing unless macros | |
10 | (defmacro! unless (fn* (pred a b) `(if ~pred ~b ~a))) | |
11 | (unless false 7 8) | |
12 | ;=>7 | |
13 | (unless true 7 8) | |
14 | ;=>8 | |
15 | (defmacro! unless2 (fn* (pred a b) `(if (not ~pred) ~a ~b))) | |
16 | (unless2 false 7 8) | |
17 | ;=>7 | |
18 | (unless2 true 7 8) | |
19 | ;=>8 | |
20 | ||
6b9eb18e JM |
21 | ;; Testing macroexpand |
22 | (macroexpand (unless2 2 3 4)) | |
23 | ;=>(if (not 2) 3 4) | |
24 | ||
9bca0b57 JM |
25 | ;; Testing evaluation of macro result |
26 | (defmacro! identity (fn* (x) x)) | |
27 | (let* (a 123) (identity a)) | |
28 | ;=>123 | |
29 | ||
6b9eb18e | 30 | |
a1eb30fc | 31 | ;>>> deferrable=True |
46e25689 | 32 | ;; |
a1eb30fc | 33 | ;; -------- Deferrable Functionality -------- |
46e25689 JM |
34 | |
35 | ;; Testing non-macro function | |
36 | (not (= 1 1)) | |
37 | ;=>false | |
38 | ;;; This should fail if it is a macro | |
39 | (not (= 1 2)) | |
40 | ;=>true | |
41 | ||
6b9eb18e JM |
42 | ;; Testing nth, first and rest functions |
43 | ||
46e25689 | 44 | (nth (list 1) 0) |
6b9eb18e | 45 | ;=>1 |
46e25689 | 46 | (nth (list 1 2) 1) |
6b9eb18e JM |
47 | ;=>2 |
48 | (def! x "x") | |
46e25689 | 49 | (def! x (nth (list 1 2) 2)) |
6b9eb18e JM |
50 | x |
51 | ;=>"x" | |
52 | ||
46e25689 | 53 | (first (list)) |
6b9eb18e | 54 | ;=>nil |
46e25689 | 55 | (first (list 6)) |
6b9eb18e | 56 | ;=>6 |
46e25689 | 57 | (first (list 7 8 9)) |
6b9eb18e JM |
58 | ;=>7 |
59 | ||
46e25689 | 60 | (rest (list)) |
6b9eb18e | 61 | ;=>() |
46e25689 | 62 | (rest (list 6)) |
6b9eb18e | 63 | ;=>() |
46e25689 | 64 | (rest (list 7 8 9)) |
6b9eb18e JM |
65 | ;=>(8 9) |
66 | ||
67 | ||
77b2da6c JM |
68 | ;; Testing or macro |
69 | (or) | |
70 | ;=>nil | |
71 | (or 1) | |
72 | ;=>1 | |
73 | (or 1 2 3 4) | |
74 | ;=>1 | |
75 | (or false 2) | |
76 | ;=>2 | |
77 | (or false nil 3) | |
78 | ;=>3 | |
79 | (or false nil false false nil 4) | |
80 | ;=>4 | |
81 | (or false nil 3 false nil 4) | |
82 | ;=>3 | |
758933f2 JM |
83 | (or (or false 4)) |
84 | ;=>4 | |
77b2da6c JM |
85 | |
86 | ;; Testing cond macro | |
87 | ||
88 | (cond) | |
89 | ;=>nil | |
90 | (cond true 7) | |
91 | ;=>7 | |
92 | (cond true 7 true 8) | |
93 | ;=>7 | |
94 | (cond false 7 true 8) | |
95 | ;=>8 | |
96 | (cond false 7 false 8 "else" 9) | |
97 | ;=>9 | |
98 | (cond false 7 (= 2 2) 8 "else" 9) | |
99 | ;=>8 | |
100 | (cond false 7 false 8 false 9) | |
101 | ;=>nil | |
102 | ||
9af8aee6 JM |
103 | ;; Testing EVAL in let* |
104 | ||
105 | (let* (x (or nil "yes")) x) | |
106 | ;=>"yes" | |
107 | ||
46e25689 JM |
108 | |
109 | ;>>> optional=True | |
9af8aee6 JM |
110 | ;; |
111 | ;; -------- Optional Functionality -------- | |
112 | ||
8128c69a JM |
113 | ;; Testing nth, first, rest with vectors |
114 | ||
8128c69a JM |
115 | (nth [1] 0) |
116 | ;=>1 | |
117 | (nth [1 2] 1) | |
118 | ;=>2 | |
b8ee29b2 JM |
119 | (def! x "x") |
120 | (def! x (nth [1 2] 2)) | |
121 | x | |
122 | ;=>"x" | |
8128c69a | 123 | |
9af8aee6 JM |
124 | (first []) |
125 | ;=>nil | |
4e284171 DM |
126 | (first nil) |
127 | ;=>nil | |
9af8aee6 JM |
128 | (first [10]) |
129 | ;=>10 | |
130 | (first [10 11 12]) | |
131 | ;=>10 | |
132 | (rest []) | |
133 | ;=>() | |
4e284171 DM |
134 | (rest nil) |
135 | ;=>() | |
9af8aee6 JM |
136 | (rest [10]) |
137 | ;=>() | |
138 | (rest [10 11 12]) | |
139 | ;=>(11 12) | |
140 | ||
141 | ;; Testing EVAL in vector let* | |
142 | ||
31690700 JM |
143 | (let* [x (or nil "yes")] x) |
144 | ;=>"yes" | |
145 | ||
a193b2c4 DM |
146 | ;; |
147 | ;; Loading core.mal | |
148 | (load-file "../core.mal") | |
149 | ||
150 | ;; Testing -> macro | |
151 | (-> 7) | |
152 | ;=>7 | |
153 | (-> (list 7 8 9) first) | |
154 | ;=>7 | |
155 | (-> (list 7 8 9) (first)) | |
156 | ;=>7 | |
157 | (-> (list 7 8 9) first (+ 7)) | |
158 | ;=>14 | |
159 | (-> (list 7 8 9) rest (rest) first (+ 7)) | |
160 | ;=>16 | |
161 | ||
162 | ;; Testing ->> macro | |
163 | (->> "L") | |
164 | ;=>"L" | |
165 | (->> "L" (str "A") (str "M")) | |
166 | ;=>"MAL" | |
167 | (->> [4] (concat [3]) (concat [2]) rest (concat [1])) | |
168 | ;=>(1 3 4) | |
169 |