<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>