From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: szgyg Newsgroups: gmane.lisp.guile.user Subject: Re: Need help to understand a macro Date: Sat, 20 Mar 2010 15:13:45 +0100 Message-ID: <4BA4D819.6020508@ludens.elte.hu> References: <20100319085701.GA31143@raven.wolf.lan> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1269094429 31283 80.91.229.12 (20 Mar 2010 14:13:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 20 Mar 2010 14:13:49 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Mar 20 15:13:45 2010 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.69) (envelope-from ) id 1NszQt-0008D6-3N for guile-user@m.gmane.org; Sat, 20 Mar 2010 15:13:43 +0100 Original-Received: from localhost ([127.0.0.1]:33211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NszQs-0003RQ-1p for guile-user@m.gmane.org; Sat, 20 Mar 2010 10:13:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NszQn-0003RL-1S for guile-user@gnu.org; Sat, 20 Mar 2010 10:13:37 -0400 Original-Received: from [140.186.70.92] (port=47416 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NszQk-0003R4-76 for guile-user@gnu.org; Sat, 20 Mar 2010 10:13:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NszQi-0007qM-IV for guile-user@gnu.org; Sat, 20 Mar 2010 10:13:34 -0400 Original-Received: from mx3.mail.elte.hu ([157.181.1.138]:33864) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NszQi-0007q7-Bu for guile-user@gnu.org; Sat, 20 Mar 2010 10:13:32 -0400 Original-Received: from mailbox1.caesar.elte.hu ([157.181.151.157]) by mx3.mail.elte.hu with esmtp (Exim) id 1NszQe-0001Zw-Um from for ; Sat, 20 Mar 2010 15:13:29 +0100 Original-Received: (Authenticated sender: szgyg) by mailbox1.caesar.elte.hu with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NszQe-0006Oa-Dn for guile-user@gnu.org; Sat, 20 Mar 2010 15:13:28 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; hu; rv:1.9.1.8) Gecko/20100227 Lightning/1.0b1 Thunderbird/2.0 ThunderBrowse/3.2.8.1 In-Reply-To: <20100319085701.GA31143@raven.wolf.lan> X-ELTE-SpamScore: -8.8 X-ELTE-SpamLevel: X-ELTE-SpamCheck: no X-ELTE-SpamVersion: ELTE 2.0 X-ELTE-SpamCheck-Details: score=-8.8 required=5.9 tests=ALL_TRUSTED, BAYES_00, L_AUTH autolearn=ham SpamAssassin version=3.2.5 -1.8 ALL_TRUSTED Passed through trusted hosts only via SMTP -5.0 L_AUTH Caesar auth -2.0 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:7682 Archived-At: Josef Wolf wrote: > I am trying to understand the defstruct macro from the "teach yourself > scheme in fixnum days" tutorial, which can be found in chapter 9 at > http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-11.html#node_chap_9 > > My first question is of a more generic type. For a better understanding > how macros work, I'd like to have a way to show what expansion a macro > would generate when it would be used. E.g., I'd like to do something > like > > (show-expansion (defstruct tree height girth age leaf-shape leaf-color)) > > and get what the expansion of this macro would produce: > > (begin > (define make-tree > (lambda fvfv > [ ... and so on ... ] Use the trick from the inexplicable JRM's Syntax-rules Primer for the Merely Eccentric[1], wrap the output with quote: ... (let ((ff (map (lambda (f) (if (pair? f) (car f) f)) ff))) `'(begin ; ^ (define ,(string->symbol (string-append "make-" s-s)) ... [1] http://www.xs4all.nl/~hipster/lib/scheme/gauche/define-syntax-primer.txt