In step1, test non-numbers starting with a dash.
[jackhill/mal.git] / tests / step7_quote.mal
CommitLineData
c30efef4
JM
1;; Testing cons function
2(cons 1 (list))
3;=>(1)
4(cons 1 (list 2))
5;=>(1 2)
6(cons 1 (list 2 3))
7;=>(1 2 3)
8(cons (list 1) (list 2 3))
9;=>((1) 2 3)
10
05ad2bf6
DM
11(def! a (list 2 3))
12(cons 1 a)
13;=>(1 2 3)
14a
15;=>(2 3)
16
c30efef4
JM
17;; Testing concat function
18(concat)
19;=>()
20(concat (list 1 2))
21;=>(1 2)
22(concat (list 1 2) (list 3 4))
23;=>(1 2 3 4)
24(concat (list 1 2) (list 3 4) (list 5 6))
25;=>(1 2 3 4 5 6)
26(concat (concat))
27;=>()
40eb57d6
BD
28(concat (list) (list))
29;=>()
c30efef4 30
05ad2bf6
DM
31(def! a (list 1 2))
32(def! b (list 3 4))
33(concat a b (list 5 6))
34;=>(1 2 3 4 5 6)
35a
36;=>(1 2)
37b
38;=>(3 4)
c30efef4 39
31690700
JM
40;; Testing regular quote
41(quote 7)
42;=>7
31690700
JM
43(quote (1 2 3))
44;=>(1 2 3)
31690700
JM
45(quote (1 2 (3 4)))
46;=>(1 2 (3 4))
31690700
JM
47
48;; Testing simple quasiquote
49(quasiquote 7)
50;=>7
31690700
JM
51(quasiquote (1 2 3))
52;=>(1 2 3)
31690700
JM
53(quasiquote (1 2 (3 4)))
54;=>(1 2 (3 4))
3dcaa6ce
DM
55(quasiquote (nil))
56;=>(nil)
31690700
JM
57
58;; Testing unquote
46e25689 59(quasiquote (unquote 7))
31690700
JM
60;=>7
61(def! a 8)
62;=>8
46e25689 63(quasiquote a)
31690700 64;=>a
46e25689 65(quasiquote (unquote a))
31690700 66;=>8
46e25689 67(quasiquote (1 a 3))
31690700 68;=>(1 a 3)
46e25689 69(quasiquote (1 (unquote a) 3))
31690700 70;=>(1 8 3)
46e25689 71(def! b (quote (1 "b" "d")))
31690700 72;=>(1 "b" "d")
46e25689 73(quasiquote (1 b 3))
31690700 74;=>(1 b 3)
46e25689 75(quasiquote (1 (unquote b) 3))
31690700 76;=>(1 (1 "b" "d") 3)
89f7cef6
BD
77(quasiquote ((unquote 1) (unquote 2)))
78;=>(1 2)
31690700
JM
79
80;; Testing splice-unquote
46e25689 81(def! c (quote (1 "b" "d")))
31690700 82;=>(1 "b" "d")
46e25689 83(quasiquote (1 c 3))
31690700 84;=>(1 c 3)
46e25689 85(quasiquote (1 (splice-unquote c) 3))
31690700
JM
86;=>(1 1 "b" "d" 3)
87
88
89;; Testing symbol equality
46e25689 90(= (quote abc) (quote abc))
31690700 91;=>true
46e25689 92(= (quote abc) (quote abcd))
31690700 93;=>false
46e25689 94(= (quote abc) "abc")
31690700 95;=>false
46e25689 96(= "abc" (quote abc))
31690700 97;=>false
46e25689 98(= "abc" (str (quote abc)))
a16bb08f 99;=>true
46e25689 100(= (quote abc) nil)
17946efb 101;=>false
46e25689 102(= nil (quote abc))
17946efb 103;=>false
1771ab50
JM
104
105;;;;; Test quine
106;;; TODO: needs expect line length fix
107;;;((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
108;;;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
b554fd4e 109
a1eb30fc 110;>>> deferrable=True
46e25689 111;;
a1eb30fc 112;; -------- Deferrable Functionality --------
46e25689
JM
113
114;; Testing ' (quote) reader macro
115'7
116;=>7
117'(1 2 3)
118;=>(1 2 3)
119'(1 2 (3 4))
120;=>(1 2 (3 4))
121
122;; Testing ` (quasiquote) reader macro
123`7
124;=>7
125`(1 2 3)
126;=>(1 2 3)
127`(1 2 (3 4))
128;=>(1 2 (3 4))
129`(nil)
130;=>(nil)
131
132;; Testing ~ (unquote) reader macro
133`~7
134;=>7
135(def! a 8)
136;=>8
137`(1 ~a 3)
138;=>(1 8 3)
139(def! b '(1 "b" "d"))
140;=>(1 "b" "d")
141`(1 b 3)
142;=>(1 b 3)
143`(1 ~b 3)
144;=>(1 (1 "b" "d") 3)
145
146;; Testing ~@ (splice-unquote) reader macro
147(def! c '(1 "b" "d"))
148;=>(1 "b" "d")
149`(1 c 3)
150;=>(1 c 3)
151`(1 ~@c 3)
152;=>(1 1 "b" "d" 3)
153
154
155;>>> optional=True
b554fd4e
JM
156;;
157;; -------- Optional Functionality --------
158
8128c69a
JM
159;; Testing cons, concat, first, rest with vectors
160
161(cons [1] [2 3])
162;=>([1] 2 3)
163(cons 1 [2 3])
164;=>(1 2 3)
165(concat [1 2] (list 3 4) [5 6])
166;=>(1 2 3 4 5 6)
167
b554fd4e
JM
168;; Testing unquote with vectors
169(def! a 8)
170;=>8
171`[1 a 3]
172;=>(1 a 3)
173;;; TODO: fix this
174;;;;=>[1 a 3]
175
176;; Testing splice-unquote with vectors
177(def! c '(1 "b" "d"))
178;=>(1 "b" "d")
179`[1 ~@c 3]
180;=>(1 1 "b" "d" 3)
181;;; TODO: fix this
182;;;;=>[1 1 "b" "d" 3]
8128c69a 183