Thanks , I think I understand it now , so roughly following steps happens(apology for incorrect terminology) :<div><br><div>1. bind the identifier 'phases' to some val(a syntax transformer) in phase 1</div><div><br>
</div><div> i) during the above step id 'phase2' is bound to some val i.e syntax transformer in phase 2 </div><div><br></div><div> ii) (phase2) is expanded i.e it is looked up in phase 2 and it's syntax transformer applied , which returns the syntax object which is basically #'0 </div>
<div> since cnt was 0 at the time of application of transformer.</div><div><br></div><div> iii) step 1 done.</div><div><br></div><div><br></div><div><br></div><div>2. encounters macro call (set-compile) and expansion takes place and set cnt=1(phase 1) , cnt=2(phase 2).</div>
<div><br></div><div>3. encounters macro call (phases) looks up in phase 1 and its transformer is applied and we get (list 1 0) , since</div><div> (p1 cnt=1) and (p2 0).</div><div> </div><div><br><br><div class="gmail_quote">
On Tue, Jan 17, 2012 at 12:51 PM, Jon Rafkind <span dir="ltr"><<a href="mailto:rafkind@cs.utah.edu">rafkind@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
I'm guessing a little bit but I think its because the `phases' macro
is expanded at phase 2 before `set-compile' is called. If you put
(set-compile) before the definition of `phases' then you get '(1 2).<div><div class="h5"><br>
<br>
On 01/17/2012 12:06 AM, Veer Singh wrote:
</div></div><blockquote type="cite"><div><div class="h5">
<div><br>
</div>
<div>
<div>Why macro call (phases) produces '(1 0) and not '(1 2) ?</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>(module mod1 racket</div>
<div>(require (for-syntax syntax/parse))</div>
<div> ;"mod-compile.rkt"))</div>
<div>(require (for-syntax </div>
<div> (for-syntax syntax/parse racket )))</div>
<div> ;"mod-compile.rkt")))</div>
<div>(provide set-compile phases)</div>
<div><br>
</div>
<div> ;For phase 1</div>
<div> (begin-for-syntax</div>
<div> (define cnt 0)</div>
<div> </div>
<div> (define (store! v)</div>
<div> (set! cnt v)))</div>
<div> </div>
<div> ;For phase 2</div>
<div> (begin-for-syntax (begin-for-syntax</div>
<div>
(define cnt 0)</div>
<div> </div>
<div> (define (store! v)</div>
<div> (set! cnt v))))</div>
<div> </div>
<div> ;;set the value of "cnt" in phase1 and phase2</div>
<div> (define-syntax (set-compile stx)</div>
<div> (syntax-parse stx</div>
<div> [(_) #'(begin</div>
<div> </div>
<div> (begin-for-syntax</div>
<div> ; in "cnt" in phase 1 cnt=1</div>
<div> (store! 1) </div>
<div> (begin-for-syntax</div>
<div> ; in "cnt" in phase 2 cnt=2</div>
<div> (store! 2)))</div>
<div> 'done)]))</div>
<div> </div>
<div><br>
</div>
<div> ;;return the value of cnt in phase1 and phase2</div>
<div> (define-syntax (phases stx)</div>
<div> </div>
<div> ;phase2 ???</div>
<div> (define-syntax (phase2 stx) </div>
<div> (syntax-parse stx</div>
<div> [(_) (with-syntax ([p cnt])</div>
<div> #'p)]))</div>
<div> </div>
<div> </div>
<div> ;phase1 </div>
<div> (syntax-parse stx</div>
<div> [(_) (with-syntax ([p1 cnt]</div>
<div> [p2 (phase2)])</div>
<div> #'(list p1 p2))]))</div>
<div> </div>
<div> (set-compile)</div>
<div> (phases)</div>
<div> ;produces (list 1 0), but why not (list 1 2) </div>
<div> </div>
<div>)</div>
<div><br>
</div>
</div>
<div><br>
</div>
<div>Thanks</div>
<div><br>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>____________________
Racket Users list:
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a>
</pre>
</blockquote>
<br>
</div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div></div>