From 4546b4ab1db7d4af6326fe8c09eaac900bae6b9b Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 1 Nov 2019 15:41:25 +0100 Subject: [PATCH] [#140] fix for --- resources/SCI_VERSION | 2 +- src/sci/impl/for_macro.cljc | 6 +++--- test/sci/core_test.cljc | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/SCI_VERSION b/resources/SCI_VERSION index 84716fef..9f3693e4 100644 --- a/resources/SCI_VERSION +++ b/resources/SCI_VERSION @@ -1 +1 @@ -0.0.11-alpha.5 +0.0.11-alpha.6 diff --git a/src/sci/impl/for_macro.cljc b/src/sci/impl/for_macro.cljc index 2ac660db..384649bb 100644 --- a/src/sci/impl/for_macro.cljc +++ b/src/sci/impl/for_macro.cljc @@ -11,6 +11,7 @@ (throw (new #?(:clj IllegalArgumentException :cljs js/Error) "for requires an even number of forms in binding vector")))) +;; see clojurescript core.cljc defmacro for (defn expand-for [_ [_ seq-exprs body-expr]] (assert-args seq-exprs body-expr) @@ -47,9 +48,8 @@ `(fn ~giter [~gxs] (lazy-seq (loop [~gxs ~gxs] - (let [~bind (~'first ~gxs)] - (~'when ~bind - ~(do-mod mod-pairs)))))) + (when-first [~bind ~gxs] + ~(do-mod mod-pairs))))) #_"inner-most loop" (let [gi (gensym "i__") gb (gensym "b__") diff --git a/test/sci/core_test.cljc b/test/sci/core_test.cljc index 0f3c88b3..0592c961 100644 --- a/test/sci/core_test.cljc +++ b/test/sci/core_test.cljc @@ -366,6 +366,8 @@ (deftest for-test (is (= '([1 4] [1 6]) (eval* "(for [i [1 2 3] :while (< i 2) j [4 5 6] :when (even? j)] [i j])"))) + (is (= (for [[_ counts] [[1 [1 2 3]] [3 [1 2 3]]] c counts] c) + (eval* "(for [[_ counts] [[1 [1 2 3]] [3 [1 2 3]]] c counts] c)"))) (is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"vector" (eval* "(for 1 [i j])")))