Nim: step8
[jackhill/mal.git] / tests / step7_quote.mal
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
11 ;; Testing concat function
12 (concat)
13 ;=>()
14 (concat (list 1 2))
15 ;=>(1 2)
16 (concat (list 1 2) (list 3 4))
17 ;=>(1 2 3 4)
18 (concat (list 1 2) (list 3 4) (list 5 6))
19 ;=>(1 2 3 4 5 6)
20 (concat (concat))
21 ;=>()
22
23
24 ;; Testing regular quote
25 (quote 7)
26 ;=>7
27 '7
28 ;=>7
29 (quote (1 2 3))
30 ;=>(1 2 3)
31 '(1 2 3)
32 ;=>(1 2 3)
33 (quote (1 2 (3 4)))
34 ;=>(1 2 (3 4))
35 '(1 2 (3 4))
36 ;=>(1 2 (3 4))
37
38
39 ;; Testing simple quasiquote
40 (quasiquote 7)
41 ;=>7
42 `7
43 ;=>7
44 (quasiquote (1 2 3))
45 ;=>(1 2 3)
46 `(1 2 3)
47 ;=>(1 2 3)
48 (quasiquote (1 2 (3 4)))
49 ;=>(1 2 (3 4))
50 `(1 2 (3 4))
51 ;=>(1 2 (3 4))
52
53
54 ;; Testing unquote
55 `~7
56 ;=>7
57 (def! a 8)
58 ;=>8
59 `a
60 ;=>a
61 `~a
62 ;=>8
63 `(1 a 3)
64 ;=>(1 a 3)
65 `(1 ~a 3)
66 ;=>(1 8 3)
67 (def! b '(1 "b" "d"))
68 ;=>(1 "b" "d")
69 `(1 b 3)
70 ;=>(1 b 3)
71 `(1 ~b 3)
72 ;=>(1 (1 "b" "d") 3)
73
74
75 ;; Testing splice-unquote
76 (def! c '(1 "b" "d"))
77 ;=>(1 "b" "d")
78 `(1 c 3)
79 ;=>(1 c 3)
80 `(1 ~@c 3)
81 ;=>(1 1 "b" "d" 3)
82
83
84 ;; Testing symbol equality
85 (= 'abc 'abc)
86 ;=>true
87 (= 'abc 'abcd)
88 ;=>false
89 (= 'abc "abc")
90 ;=>false
91 (= "abc" 'abc)
92 ;=>false
93
94 ;;;;; Test quine
95 ;;; TODO: needs expect line length fix
96 ;;;((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
97 ;;;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
98
99 ;;
100 ;; -------- Optional Functionality --------
101
102 ;; Testing cons, concat, first, rest with vectors
103
104 (cons [1] [2 3])
105 ;=>([1] 2 3)
106 (cons 1 [2 3])
107 ;=>(1 2 3)
108 (concat [1 2] (list 3 4) [5 6])
109 ;=>(1 2 3 4 5 6)
110
111 ;; Testing unquote with vectors
112 (def! a 8)
113 ;=>8
114 `[1 a 3]
115 ;=>(1 a 3)
116 ;;; TODO: fix this
117 ;;;;=>[1 a 3]
118
119 ;; Testing splice-unquote with vectors
120 (def! c '(1 "b" "d"))
121 ;=>(1 "b" "d")
122 `[1 ~@c 3]
123 ;=>(1 1 "b" "d" 3)
124 ;;; TODO: fix this
125 ;;;;=>[1 1 "b" "d" 3]
126