<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>myfor is 'dynamic' in that it expands to the desired depth but yes, I need to know the number at compile time.&nbsp;</div><div><br></div><div>The advantage is that I get a variable list of my choice&nbsp;</div><div><br></div><br><div><div>On Mar 13, 2012, at 10:00 PM, rob cook wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">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.<br>
<br>What a great user group!<br><br>Thanks again,<br>Rob<br><br><div class="gmail_quote">On Tue, Mar 13, 2012 at 5:09 PM, Matthias Felleisen <span dir="ltr">&lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
May I propose a slightly more useful macro instead:<br>
<br>
#lang racket<br>
<br>
(define-syntax (myfor stx)<br>
 &nbsp;(syntax-case stx ()<br>
 &nbsp; &nbsp;[(_ (i ...) for-clause todo ...)<br>
 &nbsp; &nbsp; #'(for* ([i for-clause] ...) todo ...)]))<br>
<div class="im"><br>
(define (nestfortest . args) (displayln args))<br>
<br>
</div>(myfor (a b c) '(1 2)<br>
 &nbsp; &nbsp; &nbsp; (displayln `(,a ,b ,c)))<br>
<div><div class="h5"><br>
<br>
<br>
<br>
On Mar 13, 2012, at 8:02 PM, rob cook wrote:<br>
<br>
&gt; To add to prior query - here's what I did, but I just think there *must* be a more elegant solution.<br>
&gt;<br>
&gt; (define (nestfor depth forclause todo)<br>
&gt; &nbsp; (define (nf depth forclause todo resultant)<br>
&gt; &nbsp; &nbsp; (for ((x forclause))<br>
&gt; &nbsp; &nbsp; &nbsp; (if (= depth 1)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (apply todo (append (list x) resultant))<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (nf (- depth 1) forclause todo (append (list x) resultant)))))<br>
&gt; &nbsp; (nf depth forclause todo empty))<br>
&gt;<br>
&gt; (define (nestfortest . args) (displayln args))<br>
&gt;<br>
&gt; (nestfor 3 '(1 2) nestfortest)<br>
</div></div>&gt; ____________________<br>
&gt; &nbsp;Racket Users list:<br>
&gt; &nbsp;<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</blockquote></div><br>
____________________<br> &nbsp;Racket Users list:<br> &nbsp;<a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>