[gambit-list] Newbie: define-macro question

Adam Langley alangley at gmail.com
Thu Aug 18 07:16:14 EDT 2005


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

-- 
Adam Langley                                      agl at imperialviolet.org
http://www.imperialviolet.org                       (+44) (0)7906 332512
PGP: 9113   256A   CC0F   71A6   4C84   5087   CDA5   52DF   2CB6   3D60



More information about the Gambit-list mailing list