forked from kanaka/mal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step3_env.mal
107 lines (95 loc) · 1.61 KB
/
step3_env.mal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
;; Testing REPL_ENV
(+ 1 2)
;=>3
(/ (- (+ 5 (* 2 3)) 3) 4)
;=>2
;; Testing def!
(def! x 3)
;=>3
x
;=>3
(def! x 4)
;=>4
x
;=>4
(def! y (+ 1 7))
;=>8
y
;=>8
;; Verifying symbols are case-sensitive
(def! mynum 111)
;=>111
(def! MYNUM 222)
;=>222
mynum
;=>111
MYNUM
;=>222
;; Check env lookup non-fatal error
(abc 1 2 3)
;/.*'?abc'? not found.*
;; Check that error aborts def!
(def! w 123)
(def! w (abc))
w
;=>123
;; Testing let*
(let* (z 9) z)
;=>9
(let* (x 9) x)
;=>9
x
;=>4
(let* (z (+ 2 3)) (+ 1 z))
;=>6
(let* (p (+ 2 3) q (+ 2 p)) (+ p q))
;=>12
(def! y (let* (z 7) z))
y
;=>7
;; Testing outer environment
(def! a 4)
;=>4
(let* (q 9) q)
;=>9
(let* (q 9) a)
;=>4
(let* (z 2) (let* (q 9) a))
;=>4
;>>> deferrable=True
;;
;; -------- Deferrable Functionality --------
;; Testing let* with vector bindings
(let* [z 9] z)
;=>9
(let* [p (+ 2 3) q (+ 2 p)] (+ p q))
;=>12
;; Testing vector evaluation
(let* (a 5 b 6) [3 4 a [b 7] 8])
;=>[3 4 5 [6 7] 8]
;>>> soft=True
;>>> optional=True
;;
;; -------- Optional Functionality --------
;; Check that last assignment takes priority
(let* (x 2 x 3) x)
;=>3
;; Check DEBUG-EVAL
(let* (DEBUG-EVAL false) (- 3 1))
;=>2
(let* (DEBUG-EVAL nil) (- 3 1))
;=>2
;;; Some implementations avoid a recursive EVAL when the first element
;;; is a symbol or when map(EVAL, list) encounters a number.
(let* (a 3 b 2 DEBUG-EVAL true) (- a b))
;/EVAL: \(- a b\).*\n1
;; Check the readably pretty-printing option
(let* (DEBUG-EVAL 1) "a")
;/EVAL: "a".*\n"a"
;; Usually false values
(let* (a 3 DEBUG-EVAL ()) a)
;/EVAL: a.*\n3
(let* (a 3 DEBUG-EVAL 0) a)
;/EVAL: a.*\n3
(let* (a 3 DEBUG-EVAL "") a)
;/EVAL: a.*\n3