From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: Need help with a macro Date: Sun, 15 Nov 2009 20:26:58 +0000 Message-ID: <87lji7h6ul.fsf@ossau.uklinux.net> References: <20091115163303.GD29831@raven.wolf.lan> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1258316893 2458 80.91.229.12 (15 Nov 2009 20:28:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 15 Nov 2009 20:28:13 +0000 (UTC) Cc: guile-user@gnu.org To: Josef Wolf Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Nov 15 21:28:06 2009 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N9lhb-0007Uj-PE for guile-user@m.gmane.org; Sun, 15 Nov 2009 21:28:04 +0100 Original-Received: from localhost ([127.0.0.1]:41766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N9lhb-0003dH-BO for guile-user@m.gmane.org; Sun, 15 Nov 2009 15:28:03 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N9lhL-0003b9-Ao for guile-user@gnu.org; Sun, 15 Nov 2009 15:27:47 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N9lhG-0003UE-Ak for guile-user@gnu.org; Sun, 15 Nov 2009 15:27:46 -0500 Original-Received: from [199.232.76.173] (port=45990 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N9lhG-0003Tp-0R for guile-user@gnu.org; Sun, 15 Nov 2009 15:27:42 -0500 Original-Received: from mail3.uklinux.net ([80.84.72.33]:40048) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N9lhF-0006gm-L5 for guile-user@gnu.org; Sun, 15 Nov 2009 15:27:41 -0500 Original-Received: from arudy (host86-145-153-90.range86-145.btcentralplus.com [86.145.153.90]) by mail3.uklinux.net (Postfix) with ESMTP id E7C851F6B13; Sun, 15 Nov 2009 20:27:02 +0000 (GMT) Original-Received: from arudy (arudy [127.0.0.1]) by arudy (Postfix) with ESMTP id DE11138024; Sun, 15 Nov 2009 20:26:58 +0000 (GMT) In-Reply-To: <20091115163303.GD29831@raven.wolf.lan> (Josef Wolf's message of "Sun, 15 Nov 2009 17:33:03 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7482 Archived-At: Josef Wolf 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