[racket] "variadic"nested for?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Mar 13 20:09:04 EDT 2012

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



Posted on the users mailing list.