>From your example I suspect that you want a macro that expands to a method 
>call:

#lang racket
(define foo-class%
 (class object%
   (super-new)
   (define/public (get-foo) "foo")))
(define-syntax (say-hello stx)
 (syntax-case stx ()
   [(_ foo)
    #'(display (string-append "Hello " (send foo get-foo)))]))
(say-hello (new foo-class%)) ; Hello foo

But if you do want to call a method inside a macro, you will have to use 
define-for-syntax instead of define for the class, like this:

#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)))
      #'(void))]))
(say-hello foo-object) ; Hello foo at compile time

The (define-for-syntax foo-class% ...) creates class that exists at compile 
time.

The (define-syntax foo-object ...) creates a compile time binding that can be 
accessed with syntax-local-value.

Alex Knauth


> On Dec 5, 2015, at 12:20 PM, Guilherme Ferreira <guilhermef...@gmail.com> 
> wrote:
> 
> Hello everyone,
> 
> Consider this example:
> 
> (define foo-class%
>  (class object%
>    (define/public (get-foo) "foo")))
> 
> 
> (define-syntax (say-hello stx)
>  (syntax-case stx ()
>    [(_ foo)
>     (with-syntax ((foo-name (send #'foo get-foo)))
>       #'(display (string-append "Hello " foo-name)))]))
> 
> When the macro is called:
> 
>> (say-hello (make-object foo-class%))
> . . send: target is not an object
>  target: #<syntax:3:13 (make-object foo-class%)>
>  method name: get-foo
> 
> Does anyone know how can I call "get-foo" inside the macro?
> 
> Thanks.
> 
> -- 
> 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.

-- 
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