[racket] "variadic"nested for?
You can do this without a macro:
-> (let loop ([depth 3] [l '()])
(if (zero? depth)
(printf "~s\n" (reverse l))
(for ([i 2])
(loop (sub1 depth) (cons i l)))))
(0 0 0)
(0 0 1)
(0 1 0)
(0 1 1)
(1 0 0)
(1 0 1)
(1 1 0)
(1 1 1)
Or to get a list of the results:
-> (let loop ([depth 3] [l '()])
(if (zero? depth)
(list (reverse l))
(append* (for/list ([i 2])
(loop (sub1 depth) (cons i l))))))
'((0 0 0) (0 0 1) (0 1 0) (0 1 1) (1 0 0) (1 0 1) (1 1 0) (1 1 1))
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!