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: Re: Need help to understand a macro Date: Mon, 22 Mar 2010 20:25:56 +0100 Message-ID: <20100322192556.GB31143@raven.wolf.lan> References: <20100319085701.GA31143@raven.wolf.lan> <8E63698F-D6FF-4E42-8B6A-D2DE697C3E98@raeburn.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1269286231 1939 80.91.229.12 (22 Mar 2010 19:30:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 22 Mar 2010 19:30:31 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Mar 22 20:30:27 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 1NtnKT-0001Eo-QQ for guile-user@m.gmane.org; Mon, 22 Mar 2010 20:30:26 +0100 Original-Received: from localhost ([127.0.0.1]:59029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NtnKR-0003aY-8u for guile-user@m.gmane.org; Mon, 22 Mar 2010 15:30:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NtnKN-0003a0-81 for guile-user@gnu.org; Mon, 22 Mar 2010 15:30:19 -0400 Original-Received: from [140.186.70.92] (port=53252 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NtnKL-0003Zm-UD for guile-user@gnu.org; Mon, 22 Mar 2010 15:30:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NtnKK-0007SW-MY for guile-user@gnu.org; Mon, 22 Mar 2010 15:30:17 -0400 Original-Received: from quechua.inka.de ([193.197.184.2]:53890 helo=mail.inka.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NtnKK-0007SN-H7 for guile-user@gnu.org; Mon, 22 Mar 2010 15:30:16 -0400 Original-Received: from raven.inka.de (uucp@[127.0.0.1]) by mail.inka.de with uucp (rmailwrap 0.5) id 1NtnKH-0006U8-Ov; Mon, 22 Mar 2010 20:30:13 +0100 Original-Received: by raven.inka.de (Postfix, from userid 1000) id 8AD90760B1; Mon, 22 Mar 2010 20:25:56 +0100 (CET) Mail-Followup-To: Josef Wolf , guile-user@gnu.org Content-Disposition: inline In-Reply-To: <8E63698F-D6FF-4E42-8B6A-D2DE697C3E98@raeburn.org> 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:7700 Archived-At: On Fri, Mar 19, 2010 at 08:54:02AM -0400, Ken Raeburn wrote: > On Mar 19, 2010, at 04:57, Josef Wolf wrote: > > 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? > > The result of (if #f #f) is unspecified, not #f, according to r5rs. That means an implementation can produce whatever value it wants. > > Guile has a special "unspecified" value which is distinct from #f and other values, for use when a function's return value is unspecified; in some ways this is probably better than picking something like #f, as it doesn't cause people unfamiliar with the distinction between a language specification and a language implementation to start assuming that #f (or whatever) is the value that Scheme always requires in that case. Among other things, the unspecified value causes the REPL to not print a result: > > guile> (if #f #f #f) > #f > guile> (if #f #f) > guile> > > Using (if #f #f) here is basically saying, "the initial value is unspecified", instead of defaulting to #f or #t or 0 or '() or any other particular normal value. I think I like this type of "unspecified". Much better than the "undefined behavior" definition in C. Thanks for the explanation, Ken!