[racket] Help: Passing a class to a macro and not an identifier

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Sep 16 07:35:42 EDT 2010

On Thu, Sep 16, 2010 at 4:38 AM, Laurent <laurent.orseau at gmail.com> wrote:
>
>
> On Wed, Sep 15, 2010 at 19:35, Matthias Felleisen <matthias at ccs.neu.edu>
> wrote:
>>
>> On Sep 15, 2010, at 1:33 PM, Laurent wrote:
>>
>> >
>> > This hack will have limitations,
>> >
>> > Do you have specific ones in mind?
>> >
>> > but you could take this one step
>> > further by having the argument to your macro be an identifier and then
>> > taking the symbolic name of the identifier and passing that to
>> > dynamic-require (at compile time) to get the actual class you want.
>> >
>> > That is a nice idea, I'll try that.
>>
>> How else do you ensure that the object is an instance of the class? But
>> yes, I am stumped and surprised.
>
> Without that, I don't, that's right, though no more than does `send'.
> I could had a check before the call to class->singleton or instead
> of asking for an expression that generates an object of class%,
> I could only ask for the arguments to `new', but this would be too
> restrictive I think.
>
> But I'm wondering if multiple calls to define-class->singleton would
> then cause multiple calls to dynamic-require, which would take too
> much time... ?

You can lift expressions to the top-level and then use those to avoid
multiple dynamic-require's.  Search for lift in
collects/racket/contract/private/provide.rkt for an example (this is
the code that avoids creating multiple wrapper functions for contracts
when the contracts are put on with provide/contract).

Robby


Posted on the users mailing list.