[plt-scheme] Macro is misbehaving...

From: Ryan Culpepper (ryan_sml at yahoo.com)
Date: Mon Jun 12 11:27:04 EDT 2006

--- "Paulo J. Matos" <pocmatos at gmail.com> wrote:

> Hi all,
> I'm having a macro that's giving me the creeps. I've oversimplified
> it, but the error is still there so don't worry if it really
> doesn't
> make sense, what matters is why this is happening:
> foo.scm
> (module foo mzscheme
>   (require (prefix slide: (lib "slide.ss" "slideshow"))
>            (lib "class.ss"))
>   (define obj%
>     (class object%
>       (define/public (get-pict s)
>         (slide:inset 10 10))
>       (super-new)))
>   (define obj (make-object obj%))
>   (define-syntax slide/foo
>     (syntax-rules ()
>       ((_ obj s ...)
>        (slide:slide
>         (if (symbol? s)
>             s
>             (send* obj s))
>         ...))))
>   (provide slide/foo)
>   )
> bar.scm
> (module bar (lib "slideshow.ss" "slideshow")
>   (require "foo.scm")
>   (slide/foo
>    (t "Hello")
>    'next
>    (t "Bye"))
> )
> I get:
> expand: unbound variable in module in: next

(slide/foo (t "Hello") (quote next) (t "Bye"))
  (if (symbol? (quote next))
      (quote next)
      (send* (t "Hello")
        (quote next))))

You are producing a send* expression that tries to call the "quote"
method with the single argument "next". That's why you're getting the
error about "next" being unbound.

You are also duplicating the evaluation of "s"---you shouldn't do
that either.

> wierder is that if I change send* to send I get:
> send: method name is not an identifier in: (quote next)

Yes, because in that case you have

  (send (t "Hello") (quote next))

so it's trying to interpret "(quote next)" as the name of the method
to call.

> Problem is, I need to send an the argument of slide/foo to an
> object unless this argument is 'next, 'alt, generally speaking:
> a symbol. I'm not being able to do this. Any ideas?

Do you mean to always call the "get-pict" method if it isn't a
symbol? That's missing from your macro.

My hunch is you want the else branch of the if expression to be

  (send obj get-pict s)


> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.