4 (try* (abc 1 2) (catch* exc (prn "exc is:" exc))))
5 ; "exc is:" "'abc' not found"
8 ;;;TODO: fix so long lines don't trigger ANSI escape codes ;;;(try*
9 ;;;(try* (throw {"data" "foo"}) (catch* exc (do (prn "exc is:" exc) 7))) ;;;;
10 ;;;; "exc is:" {"data" "foo"} ;;;;=>7
13 (try* (throw {"data" "foo"}) (catch* exc (do (prn "err:" exc) 7)))
14 ; "err:" {"data" "foo"}
17 (try* (throw "my exception") (catch* exc (do (prn "exc:" exc) 7)))
18 ; "exc:" "my exception"
23 ;; Testing builtin functions
47 ;; Testing apply function
52 (apply prn (list 1 2 "3" (list)))
57 ;; Testing map function
58 (def! nums (list 1 2 3))
59 (def! double (fn* (a) (* 2 a)))
66 ;; Testing read-str and eval
67 (read-string "(1 2 (3 4) nil)")
70 (read-string "7 ;; comment")
73 ;;; Differing output, but make sure no fatal error
74 (read-string ";; comment")
77 (eval (read-string "(+ 4 5)"))
82 (readline "mal-user> ")
87 ;; -------- Optional Functionality --------
89 ;; Testing sequential? function
91 (sequential? (list 1 2 3))
95 (sequential? sequential?)
102 ;; Testing vector functions
111 ;; Testing conj function
118 (conj (list 2 3) 4 5 6)
120 (conj (list 1) (list 2 3))
148 (def! hm1 (hash-map))
167 (def! hm2 (assoc hm1 "a" 1))
188 (count (keys (assoc hm2 "b" 2 "c" 3)))
191 (def! hm3 (assoc hm2 "b" 2))
203 (dissoc hm3 "a" "b" "c")
218 (with-meta [1 2 3] {"a" 1})
221 (meta (with-meta [1 2 3] {"a" 1}))
224 (meta (with-meta [1 2 3] "abc"))
227 (meta (with-meta (list 1 2 3) {"a" 1}))
230 (meta (with-meta {"abc" 123} {"a" 1}))
233 ;;; Not actually supported by Clojure
234 ;;;(meta (with-meta (atom 7) {"a" 1}))
237 (def! l-wm (with-meta [4 5 6] {"b" 2}))
242 (meta (with-meta l-wm {"new_meta" 123}))
247 ;; Testing metadata on functions
248 (def! f-wm (with-meta (fn* [a] (+ 1 a)) {"abc" 1}))
252 (meta (with-meta f-wm {"new_meta" 123}))
258 (def! f-wm2 ^{"abc" 1} (fn* [a] (+ 1 a)))
262 ;; Testing metadata on builtin functions
265 (def! f-wm3 ^{"def" 2} +)
272 ;; Make sure closures and metadata co-exist
273 (def! gen-plusX (fn* (x) (with-meta (fn* (b) (+ x b)) {"meta" 1})))
274 (def! plus7 (gen-plusX 7))
275 (def! plus8 (gen-plusX 8))
282 (meta (with-meta plus7 {"meta" 2}))
291 (def! inc3 (fn* (a) (+ 3 a)))
317 (swap! a (fn* (a) a))
320 (swap! a (fn* (a) (* 2 a)))
323 (swap! a (fn* (a b) (* a b)) 10)
329 ;; Testing swap!/closure interaction
330 (def! inc-it (fn* (a) (+ 1 a)))
332 (def! f (fn* [] (swap! atm inc-it)))