From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Josef Wolf Newsgroups: gmane.lisp.guile.user Subject: Need help to understand a macro Date: Fri, 19 Mar 2010 09:57:01 +0100 Message-ID: <20100319085701.GA31143@raven.wolf.lan> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1268989233 9958 80.91.229.12 (19 Mar 2010 09:00:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 19 Mar 2010 09:00:33 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Mar 19 10:00:26 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 1NsY47-0005AL-J9 for guile-user@m.gmane.org; Fri, 19 Mar 2010 10:00:23 +0100 Original-Received: from localhost ([127.0.0.1]:35823 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NsY46-0001qk-WF for guile-user@m.gmane.org; Fri, 19 Mar 2010 05:00:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NsY41-0001qT-Fv for guile-user@gnu.org; Fri, 19 Mar 2010 05:00:17 -0400 Original-Received: from [140.186.70.92] (port=56396 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NsY3z-0001qL-Vf for guile-user@gnu.org; Fri, 19 Mar 2010 05:00:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NsY3y-0003XK-G7 for guile-user@gnu.org; Fri, 19 Mar 2010 05:00:15 -0400 Original-Received: from quechua.inka.de ([193.197.184.2]:52034 helo=mail.inka.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NsY3y-0003XA-9a for guile-user@gnu.org; Fri, 19 Mar 2010 05:00:14 -0400 Original-Received: from raven.inka.de (uucp@[127.0.0.1]) by mail.inka.de with uucp (rmailwrap 0.5) id 1NsY3v-0000Ov-J2; Fri, 19 Mar 2010 10:00:11 +0100 Original-Received: by raven.inka.de (Postfix, from userid 1000) id C7051760AF; Fri, 19 Mar 2010 09:57:01 +0100 (CET) Mail-Followup-To: Josef Wolf , guile-user@gnu.org Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.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:7678 Archived-At: Hello, 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 ... ] Of course this is possible. After all, code is data and data is code. My next question is more related to the defstruct macro. In line 11, defstruct stores the default initializers into the vv vector: (if (pair? f) (cadr f) '(if #f #f))) So if the field is a pair, the initializer is stored in vv. That's easy. But if it is not a pair, '(if #f #f) is stored. What is this good for? This 'if' would evaluate the 'else' part, which does not exist. So we would get #f as a result. So why not storing #f in the first place? Why is not (if (pair? f) (cadr f) #f)) used here?