If you have an object at compile time, then you have it at compile time and not 
at runtime. If you have an object at runtime, you don't have it at compile 
time. Your example fails because it tries to use a compile time object at 
runtime.

The `for-syntax`, `define-for-syntax`, and `begin-for-syntax` forms are to make 
the separation between compile time and runtime explicit. 

Compile time macros can expand into runtime code, which can do stuff at 
runtime, but if you try to pass in something that's not a normal syntax object, 
like a racket/class object, the runtime won't know what to do with it because 
of the separation of compile time and runtime.

Others could probably give you better explanations of how this works. 

You might be interested in this talk by Matthew Flatt about this:
Video:
http://www.infoq.com/presentations/racket 
<http://www.infoq.com/presentations/racket>
Slides:
http://res.infoq.com/downloads/pdfdownloads/presentations/ClojureWest2013-MatthewFlatt-MetaprogrammingTime.pdf?Expires=1449586134&Signature=LeIHxglNRKsnGCVSilgMpFoFbDGlZcmd8Z~WDnvaJ94~G4sp7Kpj18rYLsSKM~BM4g4vz6VZQD5~LyQ~OGS0SMUyicrGacoeOJh7DIN5WmK-0KY3CG~sY4vFX6VtnLZ3WfLR~yvsF-32YiDTbAGOzNZjrhG7RtXb3BEEXSqzRYw_&Key-Pair-Id=APKAIMZVI7QH4C5YKH6Q
 
<http://res.infoq.com/downloads/pdfdownloads/presentations/ClojureWest2013-MatthewFlatt-MetaprogrammingTime.pdf?Expires=1449586134&Signature=LeIHxglNRKsnGCVSilgMpFoFbDGlZcmd8Z~WDnvaJ94~G4sp7Kpj18rYLsSKM~BM4g4vz6VZQD5~LyQ~OGS0SMUyicrGacoeOJh7DIN5WmK-0KY3CG~sY4vFX6VtnLZ3WfLR~yvsF-32YiDTbAGOzNZjrhG7RtXb3BEEXSqzRYw_&Key-Pair-Id=APKAIMZVI7QH4C5YKH6Q>

Alex Knauth

> On Dec 8, 2015, at 8:48 AM, Guilherme Ferreira <guilhermef...@gmail.com> 
> wrote:
> 
> Thank you Alex for your help. Considering the second example,
> in the reply, what if I need to return the object itself, for example:
> 
>> #lang racket
>> (require (for-syntax racket/class))
>> (define-for-syntax foo-class%
>>   (class object%
>>     (super-new)
>>     (define/public (get-foo) "foo")))
>> (define-syntax foo-object (new foo-class%))
>> (define-syntax (say-hello stx)
>>  (syntax-case stx ()
>>    [(_ foo)
>>     (begin
>>       ;; prints at compile time
>>       (display (string-append "Hello " (send (syntax-local-value #'foo) 
>> get-foo)))
>        #`'#,(syntax-local-value #'foo))]))
> 
> This will print the foo-object:
> 
>> (say-hello foo-object) 
> Hello foo
> (object:foo-class% ...)
> 
> However, if I call the foo method it gives this error:
> 
> (send (say-hello foo-object) get-foo)
> Hello foo
> . . send: target is not an object
>  target: (object:foo-class% ...)
>  method name: get-foo
> 
> Is there another way to do that?
> 
> Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to