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