[plt-scheme] 205.8 addition - syntax-id-rules

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Dec 4 17:11:26 EST 2003

I've just exp-tagged an addition to v205.8.

The `syntax-id-rules' form is like `syntax-rules', except that it
creates a transformer that is invoked whenever its binding identifier
is used in an expression position (not just the application position)
and whenever it is used as a `set!' target. In other words,
`syntax-id-rules' is the `make-set!-transformer' version of

I'm not sure that this form useful in practice (compared to using
`syntax-case' and `make-set!-transformer'), but it helps for writing a
certain kind of tutorial.

  (define-syntax pwd
    (syntax-id-rules (set!)
      [(set! pwd expr) (current-directory expr)]
      [(clock expr ...) ((current-directory) expr ...)]
      [clock (current-directory)]))
  (set! pwd "/tmp") ; sets current-directory parameter
  pwd ; => "/tmp"
  (current-directory) ; => "/tmp"
  (current-directory "/usr/tmp")
  pwd ; => "/usr/tmp"


Posted on the users mailing list.