[racket] Help with phases

From: Veer Singh (veer.chah at gmail.com)
Date: Tue Jan 17 02:06:39 EST 2012

Why macro call (phases) produces '(1 0) and not '(1 2) ?

(module mod1 racket
(require (for-syntax syntax/parse))
(require (for-syntax
          (for-syntax syntax/parse racket )))
(provide set-compile phases)

  ;For phase 1
    (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

                 ; in "cnt" in phase 1 cnt=1
                 (store! 1)
                   ; in "cnt" in phase 2 cnt=2
                   (store! 2)))

  ;;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])

    (syntax-parse stx
      [(_) (with-syntax ([p1 cnt]
                         [p2 (phase2)])
             #'(list p1 p2))]))

  ;produces (list 1 0), but why not (list 1 2)


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

Posted on the users mailing list.