unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
To: Josef Wolf <jw@raven.inka.de>
Cc: guile-user@gnu.org
Subject: Re: Need help with a macro
Date: Sun, 15 Nov 2009 20:26:58 +0000	[thread overview]
Message-ID: <87lji7h6ul.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <20091115163303.GD29831@raven.wolf.lan> (Josef Wolf's message of "Sun, 15 Nov 2009 17:33:03 +0100")

Josef Wolf <jw@raven.inka.de> 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




  parent reply	other threads:[~2009-11-15 20:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-15 16:33 Need help with a macro Josef Wolf
2009-11-15 18:18 ` Andy Wingo
2009-11-16 17:40   ` Josef Wolf
2009-11-15 20:26 ` Neil Jerram [this message]
2009-11-16 17:20   ` Josef Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lji7h6ul.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    --cc=jw@raven.inka.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).