[gambit-list] Newbie: define-macro question
Kevin Smith
kevin at electricanvil.com
Thu Aug 18 13:41:45 EDT 2005
Adam Langley wrote:
> On 8/18/05, Kevin Smith <kevin at electricanvil.com> wrote:
>
>>(define-macro (print-line msg)
>> (list `(display ,msg) `(newline)))
>>
>>When I try to use the macro from the repl I get the error message:
>>
>>(print-line "hi")
>>hi
>>***ERROR in (console)@38.1 -- Operator is not a PROCEDURE
>
>
> Consider the expansion of the macro:
> (print-line "hi") ->
> ((display "hi") (newline))
>
> Therefore (display "hi") is evaluated (causing the side-effect of
> printing "hi") and then we have:
> (<result of display> (newline))
>
> Now I believe that (newline) will be evaluated giving:
> (<result of display> <result of void>)
>
> and gambit complains that <result of display> isn't a function which
> can be called. Which is fair enough since it's the value #!void (aka
> NULL).
>
> If I were writing that macro I would do something like:
> (define-macro (print-line msg)
> `(begin (display ,msg) (newline))
>
>
> Hope that helps.
>
>
> AGL
>
Aha! I was overlooking the return value of the call display and how it
interacted with the remaining expression. I've been referencing several
Lisp/Scheme books and somehow missed it.
Thanks for the analysis and suggested macro def. It definitely helped.
--Kevin
More information about the Gambit-list
mailing list