diff --git a/hy/core/macros.hy b/hy/core/macros.hy index f20d0a7..6ae1cd7 100644 --- a/hy/core/macros.hy +++ b/hy/core/macros.hy @@ -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] diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index ccf81c5..c394891 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -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 []