aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-09 23:58:27 -0500
committerJoel Martin <github@martintribe.org>2014-04-09 23:58:27 -0500
commita34b02006527d28db5df5c6553be804770b81f79 (patch)
tree526fe400e5a8c34b32a3d93439197db09c7f84ad /tests
parentedc3b0640f1b773e185550448e2086279f7b1a7f (diff)
downloadmal-a34b02006527d28db5df5c6553be804770b81f79.tar.gz
mal-a34b02006527d28db5df5c6553be804770b81f79.zip
Fix metadata on functions.
- Don't use metadata to store ast, env, params data. - In Clojure, store metadata on the :meta key of the real metadata. This also allows using any datatype as metadata.
Diffstat (limited to 'tests')
-rw-r--r--tests/stepA_more.mal37
1 files changed, 33 insertions, 4 deletions
diff --git a/tests/stepA_more.mal b/tests/stepA_more.mal
index 456a092..54faa19 100644
--- a/tests/stepA_more.mal
+++ b/tests/stepA_more.mal
@@ -226,12 +226,18 @@
(meta [1 2 3])
;=>nil
+(meta (fn* (a) a))
+;=>nil
+
(with-meta [1 2 3] {"a" 1})
;=>[1 2 3]
(meta (with-meta [1 2 3] {"a" 1}))
;=>{"a" 1}
+(meta (with-meta [1 2 3] "abc"))
+;=>"abc"
+
(meta (with-meta (list 1 2 3) {"a" 1}))
;=>{"a" 1}
@@ -242,16 +248,23 @@
;;;(meta (with-meta (atom 7) {"a" 1}))
;;;;=>{"a" 1}
-(def! lst (with-meta [4 5 6] {"b" 2}))
+(def! l-wm (with-meta [4 5 6] {"b" 2}))
;=>[4 5 6]
+(meta l-wm)
+;=>{"b" 2}
+
+(meta (with-meta l-wm {"new_meta" 123}))
+;=>{"new_meta" 123}
+(meta l-wm)
+;=>{"b" 2}
+
(def! f-wm (with-meta (fn* [a] (+ 1 a)) {"abc" 1}))
(meta f-wm)
;=>{"abc" 1}
-(meta (with-meta f-wm "new_meta"))
-;=>"new_meta"
-
+(meta (with-meta f-wm {"new_meta" 123}))
+;=>{"new_meta" 123}
(meta f-wm)
;=>{"abc" 1}
@@ -260,6 +273,22 @@
(meta f-wm2)
;=>{"abc" 1}
+;;
+;; Make sure closures and metadata co-exist
+(def! gen-plusX (fn* (x) (with-meta (fn* (b) (+ x b)) {"meta" 1})))
+(def! plus7 (gen-plusX 7))
+(def! plus8 (gen-plusX 8))
+(plus7 8)
+;=>15
+(meta plus7)
+;=>{"meta" 1}
+(meta plus8)
+;=>{"meta" 1}
+(meta (with-meta plus7 {"meta" 2}))
+;=>{"meta" 2}
+(meta plus8)
+;=>{"meta" 1}
+
;;
;; Testing atoms