On Wed, Sep 15, 2010 at 15:19, Robby Findler <ro...@eecs.northwestern.edu>wrote:
> The class exists at runtime, not at compile time, so you can't just > take an identifier like that and get the names of the methods back. > (This is a fundamental difference between our class system and ones > like in Java. See > http://www.eecs.northwestern.edu/~robby/pubs/papers/aplas2006-fff.pdf<http://www.eecs.northwestern.edu/%7Erobby/pubs/papers/aplas2006-fff.pdf> > for more info about the high level properties of the class system.) > > At least not with the current class system. You can, however, define a > macro, something like: > > (define-class <name> <class-expr>) > > and then have define-class inspect the class-expr to find the method > names (note you'll have to use local-expand to make this work) and put > that information into <name> at compile time. > Or maybe I can define a% in a separate module and require it for-syntax either? So here is where I am right now: #lang racket (require "a.rkt" (for-syntax "a.rkt")) (define-syntax-rule (define-singleton-sender fun obj meth) (define-syntax-rule (fun args (... ...)) (send (obj) meth args (... ...)))) (define-syntax (class->singleton stx) (syntax-case stx () [(_ cl obj) (with-syntax ([(name ...) (interface->method-names (class->interface a%))]) ; *** #'(begin (define-singleton-sender name obj name) ...))])) (define current-a (make-parameter (new a% [a 3]))) (class->singleton a% current-a) This works for class a%, but only for this one, as I don't know how to pass a% as an argument to the macro (note the a% on line ***). How can I do that? > > hth, > Robby > > On Wed, Sep 15, 2010 at 7:50 AM, Laurent <laurent.ors...@gmail.com> wrote: > > Dear all, > > > > Apparently I still don't have my macro writing licence. > > I'm stuck somewhere around syntax-case and with-syntax. > > > > Here is my problem. > > Suppose something like this: > > > > (define-syntax (class->singleton stx) > > (syntax-case stx () > > [(_ cl) > > (with-syntax ([(name ...) > > (interface->method-names (class->interface #'cl))]) ; > > *** > > #'(begin (define-something name) > > ...))])) > > > > (class->singleton a%) > > > > On line *** I want to match (name ...) with the list of method-names of > > the given class (here a%). > > Obviously, this is wrong, since #'cl is just a syntaxed identifier IIUC, > > but should be the class itself. > > datum->syntax and syntax->datum don't help either, so what should I do? > > Any hint (even an RTFM link) would be appreciated. > > > > Thanks, > > Laurent > > > > > > > > _________________________________________________ > > For list-related administrative tasks: > > http://lists.racket-lang.org/listinfo/users > > >
_________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users