From: Ken Raeburn <raeburn@raeburn.org>
To: Josef Wolf <jw@raven.inka.de>
Cc: guile-user@gnu.org
Subject: Re: Need help to understand a macro
Date: Fri, 19 Mar 2010 08:54:02 -0400 [thread overview]
Message-ID: <8E63698F-D6FF-4E42-8B6A-D2DE697C3E98@raeburn.org> (raw)
In-Reply-To: <20100319085701.GA31143@raven.wolf.lan>
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.
Ken
next prev parent reply other threads:[~2010-03-19 12:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-19 8:57 Need help to understand a macro Josef Wolf
2010-03-19 12:54 ` Ken Raeburn [this message]
2010-03-22 19:25 ` Josef Wolf
2010-03-22 20:16 ` Andy Wingo
2010-03-22 20:54 ` Josef Wolf
2010-03-19 14:28 ` Andy Wingo
2010-03-19 16:15 ` Andreas Rottmann
2010-03-22 19:55 ` Josef Wolf
2010-03-22 21:50 ` Andreas Rottmann
2010-03-22 19:50 ` Josef Wolf
2010-03-22 20:36 ` Andy Wingo
2010-03-22 21:01 ` Josef Wolf
2010-03-23 0:50 ` Neil Jerram
2010-03-20 14:13 ` szgyg
2010-03-22 21:06 ` 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=8E63698F-D6FF-4E42-8B6A-D2DE697C3E98@raeburn.org \
--to=raeburn@raeburn.org \
--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).