4 (try* 123 (catch* e 456))
7 (try* (abc 1 2) (catch* exc (prn "exc is:" exc)))
8 ; "exc is:" "'abc' not found"
11 ;;;TODO: fix so long lines don't trigger ANSI escape codes ;;;(try*
12 ;;;(try* (throw ["data" "foo"]) (catch* exc (do (prn "exc is:" exc) 7))) ;;;;
13 ;;;; "exc is:" ["data" "foo"] ;;;;=>7
16 (try* (throw (list 1 2 3)) (catch* exc (do (prn "err:" exc) 7)))
20 (try* (throw "my exception") (catch* exc (do (prn "exc:" exc) 7)))
21 ; "exc:" "my exception"
24 ;;; Test that throw is a function:
25 (try* (map throw (list 7)) (catch* exc exc))
30 ;; Testing builtin functions
54 ;; Testing apply function with core functions
59 (apply prn (list 1 2 "3" (list)))
61 (apply prn 1 2 (list "3" (list)))
64 ;; Testing apply function with user functions
65 (apply (fn* (a b) (+ a b)) (list 2 3))
67 (apply (fn* (a b) (+ a b)) 4 (list 5))
70 ;; Testing map function
71 (def! nums (list 1 2 3))
72 (def! double (fn* (a) (* 2 a)))
77 (map (fn* (x) (symbol? x)) (list 1 (symbol "two") "three"))
81 ;; ------- Optional Functionality ----------
82 ;; ------- (Needed for self-hosting) -------
84 ;; Testing symbol and keyword functions
91 (symbol? (symbol "abc"))
99 (keyword? (keyword "abc"))
104 ;;;TODO: all implementations should suppport this too
110 ;; Testing sequential? function
112 (sequential? (list 1 2 3))
116 (sequential? sequential?)
123 ;; Testing apply function with core functions and arguments in vector
126 (apply prn 1 2 ["3" 4])
129 ;; Testing apply function with user functions and arguments in vector
130 (apply (fn* (a b) (+ a b)) [2 3])
132 (apply (fn* (a b) (+ a b)) 4 [5])
136 ;; Testing map function with vectors
137 (map (fn* (a) (* 2 a)) [1 2 3])
140 ;; Testing vector functions
171 (get (assoc (assoc {"a" 1 } "b" 2) "c" 3) "a")
174 (def! hm1 (hash-map))
193 (def! hm2 (assoc hm1 "a" 1))
209 ;;; TODO: fix. Clojure returns nil but this breaks mal impl
216 ;;; TODO: fix. Clojure returns nil but this breaks mal impl
223 (count (keys (assoc hm2 "b" 2 "c" 3)))
226 (def! hm3 (assoc hm2 "b" 2))
238 (dissoc hm3 "a" "b" "c")
244 ;; Testing keywords as hash-map keys
245 (get {:abc 123} :abc)
247 (contains? {:abc 123} :abc)
249 (contains? {:abcd 123} :abc)
253 (dissoc {:cde 345 :fgh 456} :cde)
255 (keyword? (nth (keys {:abc 123 :def 456}) 0))
257 ;;; TODO: support : in strings in make impl
258 ;;;(keyword? (nth (keys {":abc" 123 ":def" 456}) 0))
260 (keyword? (nth (vals {"a" :abc "b" :def}) 0))