From 0027e8fed423a24ec93234a6bf0fb701c233d583 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Mon, 14 Apr 2014 22:46:54 -0500 Subject: PS: fix function closures. Self-hosted up to step7. --- tests/incB.mal | 3 +++ tests/step4_if_fn_do.mal | 3 +++ tests/stepA_more.mal | 15 +++++++++++++++ 3 files changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/incB.mal b/tests/incB.mal index ed28734..86960c5 100644 --- a/tests/incB.mal +++ b/tests/incB.mal @@ -12,3 +12,6 @@ (prn "incB.mal finished") "incB.mal return string" + +;; ending comment + diff --git a/tests/step4_if_fn_do.mal b/tests/step4_if_fn_do.mal index a4ce46f..4d41380 100644 --- a/tests/step4_if_fn_do.mal +++ b/tests/step4_if_fn_do.mal @@ -264,6 +264,9 @@ ( (fn* () 4) ) ;=>4 +( (fn* (f x) (f x)) (fn* (a) (+ 1 a)) 7) +;=>8 + ;; Testing closures ( ( (fn* (a) (fn* (b) (+ a b))) 5) 7) diff --git a/tests/stepA_more.mal b/tests/stepA_more.mal index f6b01f5..892b592 100644 --- a/tests/stepA_more.mal +++ b/tests/stepA_more.mal @@ -117,6 +117,9 @@ (map? []) ;=>false +(get nil "a") +;=>nil + (get hm1 "a") ;=>nil @@ -174,6 +177,9 @@ (meta (fn* (a) a)) ;=>nil +(meta +) +;=>nil + (with-meta [1 2 3] {"a" 1}) ;=>[1 2 3] @@ -276,6 +282,15 @@ (swap! a + 3) ;=>123 +;; Testing swap!/closure interaction +(def! inc-it (fn* (a) (+ 1 a))) +(def! atm (atom 7)) +(def! f (fn* [] (swap! atm inc-it))) +(f) +;=>8 +(f) +;=>9 + ;; ;; Testing read-str and eval (read-string "(1 2 (3 4) nil)") -- cgit v1.2.3