From a632d477f3a561017aa08df81e33db1759ffd04c Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 17 Oct 2024 14:19:33 +0200 Subject: [PATCH] wip --- src/sci/impl/for_macro.cljc | 41 +++++++++++++++++++------------------ test/sci/error_test.cljc | 5 +++-- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/sci/impl/for_macro.cljc b/src/sci/impl/for_macro.cljc index 8feb81cc..0158a7bd 100644 --- a/src/sci/impl/for_macro.cljc +++ b/src/sci/impl/for_macro.cljc @@ -76,26 +76,27 @@ c-sym (gensym "c")] `(fn ~giter [~gxs] (lazy-seq - (~allowed-loop [~gxs ~gxs] - (let [~gxs (seq ~gxs)] - (when ~gxs - (if (chunked-seq? ~gxs) - (let [~c-sym (chunk-first ~gxs) - size# (int (count ~c-sym)) - ~gb (chunk-buffer size#)] - (if (~allowed-loop [~gi (int 0)] - (if (< ~gi size#) - ~(with-meta - `(let [~bind (nth ~c-sym ~gi)] - ~(do-cmod mod-pairs)) - loc) - true)) - (chunk-cons - (chunk ~gb) - (~giter (chunk-rest ~gxs))) - (chunk-cons (chunk ~gb) nil))) - (let [~bind (first ~gxs)] - ~(do-mod mod-pairs))))))))))))] + (~allowed-loop [~gxs ~gxs] + (let [~gxs ~(with-meta `(seq ~gxs) + loc)] + (when ~gxs + (if (chunked-seq? ~gxs) + (let [~c-sym (chunk-first ~gxs) + size# (int (count ~c-sym)) + ~gb (chunk-buffer size#)] + (if (~allowed-loop [~gi (int 0)] + (if (< ~gi size#) + ~(with-meta + `(let [~bind (nth ~c-sym ~gi)] + ~(do-cmod mod-pairs)) + loc) + true)) + (chunk-cons + (chunk ~gb) + (~giter (chunk-rest ~gxs))) + (chunk-cons (chunk ~gb) nil))) + (let [~bind (first ~gxs)] + ~(do-mod mod-pairs))))))))))))] `(let [iter# ~(emit-bind (to-groups seq-exprs))] (iter# ~(second seq-exprs))) )) diff --git a/test/sci/error_test.cljc b/test/sci/error_test.cljc index b12fa601..d7d8b4ee 100644 --- a/test/sci/error_test.cljc +++ b/test/sci/error_test.cljc @@ -182,8 +182,9 @@ (deftest let-test (doseq [[snippet [line col]] - [["(str (let [[a] 1] a))" [1 6]] - ["(str (for [[a] [0]] :foo))" [1 6]]]] + [["(str (let [[a] 1] a))" [1 6]] + ["(str (for [[a] [0]] :foo))" [1 6]] + ["(str (for [[a] 1] (/ 1 a)))" [1 6]]]] (try (sci.core/eval-string snippet) (is false)