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