[racket] Compile-time vs. Runtime Calls to the Same Macro

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Feb 27 08:13:18 EST 2011


  (require (for-template racket))

to dispatch.rkt/check.rkt (I think there's a typo below and that those
two files are supposed to be the same) and you will not get an error
anymore in the program below.

There are no reserved words in Racket, in the same was as in other
languages, anyways. The identifiers public and private are bound by
the require of racket and syntax-case uses that binding information
when it compares identifiers.


On Sat, Feb 26, 2011 at 10:51 PM, Sina K. Heshmati <sina at khakbaz.com> wrote:
> Hello Robby,
> "Robby Findler" <robby at eecs.northwestern.edu> said:
>> I didn't try to understand your code in any detail (if this comment
>> isn't helpful and no one else takes you up on this, try making a
>> smaller example),
> Thank you, Robby for your comment.
> While trying to reproduce the issue with a simpler sequence of instructions, I noticed that the issue is caused by the presence of special keywords such as 'private' and 'public' as literal-ids in a syntax-case form.
> Here's a simpler demonstration of the issue:
> -------------------------------------- dispatch.rkt
> #lang racket
> (provide (for-syntax (all-defined-out)) (all-defined-out))
> (define-syntax (dispatch stx)
>  (syntax-case stx ()
>    ((dispatch form)
>     #'(syntax-case form (public private)
>         ((public name val)
>          (λ () (displayln "I'm dispatched for public")))
>         ((private name val)
>          (λ () (displayln "I'm dispatched for private")))))))
> ------------------------------------ test-dispatch.rkt
> #lang racket
> (require "check.rkt" (for-syntax "check.rkt"))
> (define public-p2 (dispatch #'(public x 1)))     ;; OK
> (define private-p2 (dispatch #'(private x 1)))   ;; OK
> (define-for-syntax public-p1 (dispatch #'(public x 1)))   ;; KO
> (define-for-syntax private-p1 (dispatch #'(public x 1)))  ;; KO
> -------------------------------------------------------
> If we replace 'public' and 'private' with e.g. 'foo' and 'bar', then phase-1 calls will also succeed.
> I presume that keywords such as 'public' and 'private' are reserved by the Racket object system. Now, is there a way to work around this issue, so that I can make use of those keywords in my object system?
>>  but do you know about
>>   (require (for-template ...))
> I didn't know about it but it doesn't seem to be applicable here.
> Kind regards,
> Sina K. Heshmati

Posted on the users mailing list.