Add handling for (for []). Nice catch, @olasd.
This commit is contained in:
parent
abd0669911
commit
0f74b1ddf3
@ -46,6 +46,8 @@
|
|||||||
(if (empty? body)
|
(if (empty? body)
|
||||||
(macro-error None "`for' requires a body to evaluate"))
|
(macro-error None "`for' requires a body to evaluate"))
|
||||||
|
|
||||||
|
(if (empty? args)
|
||||||
|
`(do ~@body)
|
||||||
(if (= (len args) 2)
|
(if (= (len args) 2)
|
||||||
; basecase, let's just slip right in.
|
; basecase, let's just slip right in.
|
||||||
`(for* [~@args] ~@body)
|
`(for* [~@args] ~@body)
|
||||||
@ -56,7 +58,7 @@
|
|||||||
[ilist (list-comp (get x 1) [x az])]]
|
[ilist (list-comp (get x 1) [x az])]]
|
||||||
`(do
|
`(do
|
||||||
(import itertools)
|
(import itertools)
|
||||||
(for* [(, ~@alist) (itertools.product ~@ilist)] ~@body)))))
|
(for* [(, ~@alist) (itertools.product ~@ilist)] ~@body))))))
|
||||||
|
|
||||||
|
|
||||||
(defmacro with [args &rest body]
|
(defmacro with [args &rest body]
|
||||||
|
@ -45,6 +45,11 @@
|
|||||||
"NATIVE: test nesting for loops harder"
|
"NATIVE: test nesting for loops harder"
|
||||||
;; This test and feature is dedicated to @nedbat.
|
;; This test and feature is dedicated to @nedbat.
|
||||||
|
|
||||||
|
;; let's ensure empty iterating is an implicit do
|
||||||
|
(setv t 0)
|
||||||
|
(for [] (setv t 1))
|
||||||
|
(assert (= t 1))
|
||||||
|
|
||||||
;; OK. This first test will ensure that the else is hooked up to the
|
;; OK. This first test will ensure that the else is hooked up to the
|
||||||
;; for when we break out of it.
|
;; for when we break out of it.
|
||||||
(for [x (range 2)
|
(for [x (range 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user