[racket] Help with phases

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Tue Jan 17 02:21:08 EST 2012

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

On 01/17/2012 12:06 AM, Veer Singh wrote:
>
> Why macro call (phases) produces '(1 0) and not '(1 2) ?
>
>
> (module mod1 racket
> (require (for-syntax syntax/parse))
>                      ;"mod-compile.rkt"))
> (require (for-syntax 
>           (for-syntax syntax/parse racket )))
>                       ;"mod-compile.rkt")))
> (provide set-compile phases)
>
>   ;For phase 1
>   (begin-for-syntax
>     (define cnt 0)
>     
>   (define (store! v)
>     (set! cnt v)))
>   
>   ;For phase 2
>   (begin-for-syntax (begin-for-syntax
>     (define cnt 0)
>     
>   (define (store! v)
>     (set! cnt v))))
>   
>   ;;set the value of "cnt" in phase1 and phase2
>   (define-syntax (set-compile stx)
>     (syntax-parse stx
>       [(_) #'(begin
>                
>                (begin-for-syntax
>                  ; in "cnt" in phase 1 cnt=1
>                  (store! 1) 
>                  (begin-for-syntax
>                    ; in "cnt" in phase 2 cnt=2
>                    (store! 2)))
>                'done)]))
>   
>
>   ;;return the value of cnt in phase1 and phase2
>   (define-syntax (phases stx)
>     
>     ;phase2 ???
>     (define-syntax (phase2 stx)              
>       (syntax-parse stx
>         [(_) (with-syntax ([p cnt])
>                #'p)]))
>                  
>                  
>     ;phase1    
>     (syntax-parse stx
>       [(_) (with-syntax ([p1 cnt]
>                          [p2 (phase2)])
>              #'(list p1 p2))]))
>   
>   (set-compile)
>   (phases)
>   ;produces (list 1 0), but why not (list 1 2) 
>   
> )
>
>
> Thanks
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120117/ec037ff6/attachment.html>

Posted on the users mailing list.