Skip to content

Commit

Permalink
doseq errors
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 17, 2024
1 parent 50f97f7 commit dff3864
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 18 additions & 9 deletions src/sci/impl/doseq_macro.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
(defn expand-doseq
[expr _ seq-exprs & body]
(assert-args seq-exprs body)
(let [step (fn step [recform exprs]
(let [loc (meta expr)
step (fn step [recform exprs]
(if-not exprs
[true `(~'do ~@body)]
(let [k (first exprs)
Expand Down Expand Up @@ -48,19 +49,27 @@
steppair-chunk (step recform-chunk (nnext exprs))
subform-chunk (steppair-chunk 1)]
[true
`(~allowed-loop [~seq- (seq ~v), ~chunk- nil,
`(~allowed-loop [~seq- ~(with-meta `(seq ~v)
loc) ~chunk- nil,
~count- 0, ~i- 0]
(if (< ~i- ~count-)
(let [~k (nth ~chunk- ~i-)]
~subform-chunk
~@(when needrec [recform-chunk]))
~(with-meta
`(let [~k (nth ~chunk- ~i-)]
~subform-chunk
~@(when needrec [recform-chunk]))
loc)
(let [~seq- (seq ~seq-)]
(~'when ~seq-
(if (chunked-seq? ~seq-)
(let [c# (chunk-first ~seq-)]
(~allowed-recur (chunk-rest ~seq-) c#
(int (count c#)) (int 0)))
(let [~k (first ~seq-)]
~subform
~@(when needrec [recform])))))))])))))]
(nth (step nil (seq seq-exprs)) 1)))

~(with-meta
`(let [~k (first ~seq-)]
~subform
~@(when needrec [recform]))
loc))))))])))))
ret (nth (step nil (seq seq-exprs)) 1)]
;; (prn :ret ret)
ret))
6 changes: 4 additions & 2 deletions test/sci/error_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
(is (let [res @(future (invoke-ex-fn f))]
(is (= {:line 1 :column 13} (select-keys res [:line :column])))))))))

(deftest let-test
(deftest destructure-test
(doseq [[snippet [line col]]
[["(str (let [[a] 1] a))" [1 6]]
["(str (for [[a] [0]] :foo))" [1 6]]
Expand All @@ -189,7 +189,9 @@
["(str (if-let [[a] 0] a))" [1 6]]
["(str (when-let [[a] 0] a))" [1 6]]
["(str (if-some [[a] 0] a))" [1 6]]
["(str (when-some [[a] 0] a))" [1 6]]]]
["(str (when-some [[a] 0] a))" [1 6]]
["(str (doseq [a 0] a))" [1 6]]
["(str (doseq [[a] [0]] a))" [1 6]]]]
(try
(sci.core/eval-string snippet)
(is false)
Expand Down

0 comments on commit dff3864

Please sign in to comment.