[racket] define-syntax vs let-syntax

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Tue Nov 16 14:45:38 EST 2010

`define-syntax' has different behavior from `let-syntax' when the
transformer operates on top-level bindings in the transformer environment.

(define-for-syntax foo 1)

(define-syntax (x1 stx)
  (printf "z: foo is ~a\n" foo)
  (set! foo (add1 foo))
  (printf "z: foo is ~a\n" foo)
  #'1)

(x1)

#;
(let-syntax ([x1 (lambda (stx)
                   (printf "z: foo is ~a\n" foo)
                   (set! foo (add1 foo))
                   (printf "z: foo is ~a\n" foo)
                   #'1)])
  (x1))

With `define-syntax' I see
z: foo is 1
z: foo is 2

But with `let-syntax' I see
z: foo is 1
z: foo is 1

Is this a bug or am I missing something?


Posted on the users mailing list.