guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help with a macro


From: Neil Jerram
Subject: Re: Need help with a macro
Date: Sun, 15 Nov 2009 20:26:58 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Josef Wolf <address@hidden> writes:

> Hello,
>
> I am trying to work through the little schemer book. In order to make it
> easier to go through the examples, I've come up with the following macro:
>
>   ;;; Helper to visualize
>
>   (define-macro (disp exp)
>     (display exp)   (newline)
>     `(display ,exp)
>   ;  (newline)  (newline)
>   )
>
> This works great, except that when I uncomment the (newline) expressions,
> the result of the evaluation is omitted:
>
>   guile> (define-macro (disp exp)
>   ...   (display exp)   (newline)
>   ...   `(display ,exp)
>   ... ;  (newline)  (newline)
>   ... )
>   guile> (disp (+ 3 4)) (newline)
>   (+ 3 4)
>   7
>   guile> (define-macro (disp exp)
>   ...   (display exp)   (newline)
>   ...   `(display ,exp)
>   ...   (newline)  (newline)
>   ... )
>   guile> (disp (+ 3 4)) (newline)
>   (+ 3 4)
>   
>   
>   
>   guile>
>
> Any hints?

The body of a define-macro definition is supposed to return the code
that should be substituted in place of the original macro call.  With
the newlines there, the body returns *unspecified*, because that is what
(newline) returns.

Do you want those newlines to happen at macro-expansion time or eval
time?  If the latter (which I would guess), the code that you want is

(define-macro (disp exp)
  (display exp)   (newline)
  `(begin
     (display ,exp)
     (newline)  (newline)))

Regards,
        Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]