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 | ||
33 | ||
34 | ;; Testing nth, first and rest functions | |
35 | ||
36 | (nth '(1) 0) | |
37 | ;=>1 | |
38 | (nth '(1 2) 1) | |
39 | ;=>2 | |
40 | (def! x "x") | |
41 | (def! x (nth '(1 2) 2)) | |
42 | x | |
43 | ;=>"x" | |
44 | ||
45 | (first '()) | |
46 | ;=>nil | |
47 | (first '(6)) | |
48 | ;=>6 | |
49 | (first '(7 8 9)) | |
50 | ;=>7 | |
51 | ||
52 | (rest '()) | |
53 | ;=>() | |
54 | (rest '(6)) | |
55 | ;=>() | |
56 | (rest '(7 8 9)) | |
57 | ;=>(8 9) | |
58 | ||
59 | ||
77b2da6c JM |
60 | ;; Testing or macro |
61 | (or) | |
62 | ;=>nil | |
63 | (or 1) | |
64 | ;=>1 | |
65 | (or 1 2 3 4) | |
66 | ;=>1 | |
67 | (or false 2) | |
68 | ;=>2 | |
69 | (or false nil 3) | |
70 | ;=>3 | |
71 | (or false nil false false nil 4) | |
72 | ;=>4 | |
73 | (or false nil 3 false nil 4) | |
74 | ;=>3 | |
758933f2 JM |
75 | (or (or false 4)) |
76 | ;=>4 | |
77b2da6c JM |
77 | |
78 | ;; Testing cond macro | |
79 | ||
80 | (cond) | |
81 | ;=>nil | |
82 | (cond true 7) | |
83 | ;=>7 | |
84 | (cond true 7 true 8) | |
85 | ;=>7 | |
86 | (cond false 7 true 8) | |
87 | ;=>8 | |
88 | (cond false 7 false 8 "else" 9) | |
89 | ;=>9 | |
90 | (cond false 7 (= 2 2) 8 "else" 9) | |
91 | ;=>8 | |
92 | (cond false 7 false 8 false 9) | |
93 | ;=>nil | |
94 | ||
31690700 JM |
95 | ;; |
96 | ;; Loading core.mal | |
97 | (load-file "../core.mal") | |
98 | ||
99 | ;; Testing and macro | |
100 | (and) | |
101 | ;=>true | |
102 | (and 1) | |
103 | ;=>1 | |
104 | (and 1 2) | |
105 | ;=>2 | |
106 | (and 1 2 3) | |
107 | ;=>3 | |
108 | (and 1 2 3 4) | |
109 | ;=>4 | |
110 | (and 1 2 3 4 false) | |
111 | ;=>false | |
112 | (and 1 2 3 4 false 5) | |
113 | ;=>false | |
114 | ||
31690700 JM |
115 | ;; Testing -> macro |
116 | ||
117 | (-> 7) | |
118 | ;=>7 | |
119 | (-> (list 7 8 9) first) | |
120 | ;=>7 | |
121 | (-> (list 7 8 9) (first)) | |
122 | ;=>7 | |
123 | (-> (list 7 8 9) first (+ 7)) | |
124 | ;=>14 | |
125 | (-> (list 7 8 9) rest (rest) first (+ 7)) | |
126 | ;=>16 | |
127 | ||
9af8aee6 JM |
128 | ;; Testing EVAL in let* |
129 | ||
130 | (let* (x (or nil "yes")) x) | |
131 | ;=>"yes" | |
132 | ||
133 | ;; | |
134 | ;; -------- Optional Functionality -------- | |
135 | ||
8128c69a JM |
136 | ;; Testing nth, first, rest with vectors |
137 | ||
8128c69a JM |
138 | (nth [1] 0) |
139 | ;=>1 | |
140 | (nth [1 2] 1) | |
141 | ;=>2 | |
b8ee29b2 JM |
142 | (def! x "x") |
143 | (def! x (nth [1 2] 2)) | |
144 | x | |
145 | ;=>"x" | |
8128c69a | 146 | |
9af8aee6 JM |
147 | (first []) |
148 | ;=>nil | |
149 | (first [10]) | |
150 | ;=>10 | |
151 | (first [10 11 12]) | |
152 | ;=>10 | |
153 | (rest []) | |
154 | ;=>() | |
155 | (rest [10]) | |
156 | ;=>() | |
157 | (rest [10 11 12]) | |
158 | ;=>(11 12) | |
159 | ||
160 | ;; Testing EVAL in vector let* | |
161 | ||
31690700 JM |
162 | (let* [x (or nil "yes")] x) |
163 | ;=>"yes" | |
164 |