[racket] "variadic"nested for?
What, like this?
(define-syntax-rule (myfor bindings (arity rhs) body)
(let ([bindings (make-vector arity)])
(let theloop ([i arity])
(cond [(zero? i) body]
[else
(for ([a rhs])
(vector-set! bindings (- arity i) a)
(theloop (sub1 i)))]))))
>(myfor blah (3 '(0 1))
(printf "~a" blah))
#(0 0 0)#(0 0 1)#(0 1 0)#(0 1 1)#(1 0 0)#(1 0 1)#(1 1 0)#(1 1 1)
----- Original Message -----
From: "rob cook" <heycarnut at gmail.com>
To: users at racket-lang.org
Sent: Tuesday, March 13, 2012 7:19:25 PM GMT -05:00 US/Canada Eastern
Subject: [racket] "variadic"nested for?
I'd like to be able to create a nested for where the depth of nesting is determined dynamically.
For example, instead of
(for* ((a '(0 1)) (b '(0 1))) (printf "~v~v " a b))
I could just say
(myfor (2 '(0 1)) <body with some means of extracting nested values>).
such that the above as (myfor (3 '(0 1)) <body with some means of extracting nested values>). would allow me to effect the result:
((for* ((a '(0 1)) (b '(0 1)) (c '(0 1))) (printf "~v~v~v " a b c))
Thanks!
Rob
____________________
Racket Users list:
http://lists.racket-lang.org/users