Closes #573, restores 0.9.12 for loop behavior (and everyone wins!)

This commit is contained in:
Matthew Wampler-Doty 2014-04-22 08:56:44 -07:00
parent e57047289a
commit 5c9a8f8975
2 changed files with 8 additions and 7 deletions

View File

@ -52,11 +52,8 @@
; basecase, let's just slip right in.
`(for* [~@args] ~@body)
; otherwise, let's do some legit handling.
(let [[alist (slice args 0 nil 2)]
[ilist (slice args 1 nil 2)]]
`(do
(import itertools)
(for* [(, ~@alist) (itertools.product ~@ilist)] ~@body))))))
(let [[alist (slice args 0 nil 2)]]
`(for* [(, ~@alist) (genexpr (, ~@alist) [~@args])] ~@body)))))
(defmacro with [args &rest body]

View File

@ -29,7 +29,7 @@
(defn test-for-loop []
"NATIVE: test for loops?"
"NATIVE: test for loops"
(setv count 0)
(for [x [1 2 3 4 5]]
(setv count (+ count x)))
@ -38,7 +38,11 @@
(for [x [1 2 3 4 5]
y [1 2 3 4 5]]
(setv count (+ count x y)))
(assert (= count 150)))
(assert (= count 150))
(assert (= (list ((fn [] (for [x [[1] [2 3]] y x] (yield y)))))
(list-comp y [x [[1] [2 3]] y x])))
(assert (= (list ((fn [] (for [x [[1] [2 3]] y x z (range 5)] (yield z)))))
(list-comp z [x [[1] [2 3]] y x z (range 5)]))))
(defn test-nasty-for-nesting []