[racket] "variadic"nested for?

From: rob cook (heycarnut at gmail.com)
Date: Tue Mar 13 22:00:27 EDT 2012

Thanks - did not post reply properly - this is very useful, as is the prior
example in a different way (yours does not seem to allow the list of
iteration variables to be provided dynamically, e.g., as a list, the prior
has no such list, but I can index into the values). Both can fit my needs
though.

What a great user group!

Thanks again,
Rob

On Tue, Mar 13, 2012 at 5:09 PM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:

>
> May I propose a slightly more useful macro instead:
>
> #lang racket
>
> (define-syntax (myfor stx)
>  (syntax-case stx ()
>    [(_ (i ...) for-clause todo ...)
>     #'(for* ([i for-clause] ...) todo ...)]))
>
> (define (nestfortest . args) (displayln args))
>
> (myfor (a b c) '(1 2)
>       (displayln `(,a ,b ,c)))
>
>
>
>
> On Mar 13, 2012, at 8:02 PM, rob cook wrote:
>
> > To add to prior query - here's what I did, but I just think there *must*
> be a more elegant solution.
> >
> > (define (nestfor depth forclause todo)
> >   (define (nf depth forclause todo resultant)
> >     (for ((x forclause))
> >       (if (= depth 1)
> >           (apply todo (append (list x) resultant))
> >           (nf (- depth 1) forclause todo (append (list x) resultant)))))
> >   (nf depth forclause todo empty))
> >
> > (define (nestfortest . args) (displayln args))
> >
> > (nestfor 3 '(1 2) nestfortest)
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120313/f72a0e2a/attachment.html>

Posted on the users mailing list.