Closes #573, restores 0.9.12 for loop behavior (and everyone wins!)
This commit is contained in:
parent
e57047289a
commit
5c9a8f8975
@ -52,11 +52,8 @@
|
|||||||
; basecase, let's just slip right in.
|
; basecase, let's just slip right in.
|
||||||
`(for* [~@args] ~@body)
|
`(for* [~@args] ~@body)
|
||||||
; otherwise, let's do some legit handling.
|
; otherwise, let's do some legit handling.
|
||||||
(let [[alist (slice args 0 nil 2)]
|
(let [[alist (slice args 0 nil 2)]]
|
||||||
[ilist (slice args 1 nil 2)]]
|
`(for* [(, ~@alist) (genexpr (, ~@alist) [~@args])] ~@body)))))
|
||||||
`(do
|
|
||||||
(import itertools)
|
|
||||||
(for* [(, ~@alist) (itertools.product ~@ilist)] ~@body))))))
|
|
||||||
|
|
||||||
|
|
||||||
(defmacro with [args &rest body]
|
(defmacro with [args &rest body]
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn test-for-loop []
|
(defn test-for-loop []
|
||||||
"NATIVE: test for loops?"
|
"NATIVE: test for loops"
|
||||||
(setv count 0)
|
(setv count 0)
|
||||||
(for [x [1 2 3 4 5]]
|
(for [x [1 2 3 4 5]]
|
||||||
(setv count (+ count x)))
|
(setv count (+ count x)))
|
||||||
@ -38,7 +38,11 @@
|
|||||||
(for [x [1 2 3 4 5]
|
(for [x [1 2 3 4 5]
|
||||||
y [1 2 3 4 5]]
|
y [1 2 3 4 5]]
|
||||||
(setv count (+ count x y)))
|
(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 []
|
(defn test-nasty-for-nesting []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user