[plt-scheme] transformer environment and identifier-binding

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed May 5 11:26:48 EDT 2004

At Mon, 3 May 2004 23:42:52 -0400, Doug Orleans wrote:
> Matthew Flatt writes:
>  > This is a common problem. When an imported function needs to compare
>  > identifiers to some constant, one option is to pass the constant into
>  > the helper function (because the caller has a suitable binding).
> I was thinking about doing this, but doesn't this mean I can't use
> `syntax-case'?  It requires the constant identifiers to be provided
> inline.  I think what I really need is something like
> `module-identifier=module-transformer-identifier?' but I have no idea
> how to write it...

You could rely on a symbolic connection between pattern keywords and
the supplied identifier list.

Here's an example to illustrate:

 (define (m stx literals)
   (let-values ([(a b c) (values 1 2 3)])
     (syntax-case* stx (a b c) 
                   (lambda (stx-id pattern-id)
                     (ormap (lambda (lit-id)
                              (and (eq? (syntax-e pattern-id)
                                        (syntax-e lit-id))
                                   (module-identifier=? stx-id lit-id)))
       [(a x ...) 'a]
       [(b x ...) 'b]
       [(c x ...) 'c]
       [_else 'other])))

 (m #'(b) (list #'a #'b #'c)) ; => 'b

 ; If you replace the `syntax-case*' in `m' with `syntax-case', then
 ; the result of the `m' call is 'other.


Posted on the users mailing list.