[racket] Help with phases
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120117/8be3b165/attachment.html>