<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body 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).<br>
<br>
On 01/17/2012 12:06 AM, Veer Singh wrote:
<blockquote
cite="mid:CANiex7oK-6n+94OZ_8FEpu3NJn8XMfaHnrvJ2JyVFJiZd13mbA@mail.gmail.com"
type="cite">
<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 class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">____________________
Racket Users list:
<a class="moz-txt-link-freetext" href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a>
</pre>
</blockquote>
<br>
</body>
</html>