[plt-scheme] Transformer environment and identifier-binding: revisited
--- Robby Findler <robby at cs.uchicago.edu> wrote:
> Probably you want to use require-for-template (I think that's new
> since then, but I'm not sure).
>
> Robby
Here's an example program that might help:
(module ct mzscheme
(require-for-template mzscheme) ;; <===
(provide arith-op?)
(define (arith-op? id)
(or (module-identifier=? id #'+)
(module-identifier=? id #'-)
(module-identifier=? id #'*)
(module-identifier=? id #'/))))
(module m mzscheme
(require-for-syntax ct)
;; (only-arith Expression)
;; Restricts the expression to only arithmetic
;; operations on numbers and variables.
(define-syntax (only-arith stx)
(syntax-case stx ()
[(only-arith (op arg ...))
(begin
(unless (arith-op? #'op)
(raise-syntax-error #f "non-arithmetic operator" #'op))
#'(op (only-arith arg) ...))]
[(only-arith var)
(identifier? #'var)
#'var]
[(only-arith number)
(number? (syntax-e #'number))
#'number]))
(define (f x) (+ x 1))
(define pi (* 4 (atan 1)))
(only-arith (+ 1 2))
(only-arith (+ (* 1 3) (/ 4 2)))
(only-arith (* pi 5 5))
(only-arith (f 2)))
Ryan
> At Fri, 11 Aug 2006 10:25:27 -0700, Casey Klein wrote:
> > I think I've run into an issue similar to the one discussed a
> couple years
> > ago
>
(http://list.cs.brown.edu/pipermail/plt-scheme/2004-March/004911.html),
> > in which `require-for-syntax' shifts runtime bindings to the
> transformer
> > level, complicating `module-identifier=?' matches to constants.
> >
> > My problem does not involve `syntax-case' -- I simply need to
> know if a
> > given identifier is one of the built-in arithmetic operators
> (e.g. `+').
> > Can I instead accomplish this by checking the `source-mod' and
> 'source-id'
> > fields of the list produced by `identifier-binding' for
> module-defined
> > identifiers?
> >
> > Is passing a suitable binding into the required-for-syntax module
> still
> > the best general solution?
> >
> > -Casey
> > _________________________________________________
> > For list-related administrative tasks:
> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>