From a34b02006527d28db5df5c6553be804770b81f79 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 9 Apr 2014 23:58:27 -0500 Subject: 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. --- tests/stepA_more.mal | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'tests') 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 -- cgit v1.2.3