unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Hans Aberg <haberg-1@telia.com>
Cc: bug-guile <bug-guile@gnu.org>
Subject: Re: (+ (values 1 2)) should be 1
Date: Tue, 24 May 2011 20:25:59 -0400	[thread overview]
Message-ID: <87ei3nk4mg.fsf@netris.org> (raw)
In-Reply-To: <D7C42BC5-8A80-48F4-BE98-FFA8BB424AA4@telia.com> (Hans Aberg's message of "Tue, 24 May 2011 18:13:48 +0200")

Hans Aberg <haberg-1@telia.com> writes:
> Right, but as the result is unspecified according to the standard, the
> Guile manual suggests that the value SCM_UNSPECIFIED as an
> interpretation of that. I merely say that I think it would be a good
> idea.

Although Guile often returns SCM_UNSPECIFIED when the standards say the
value would be unspecified, it does not do this in _every_ case.  To do
so would be very inefficient in some cases, would violate the standards
in other cases, and is in general impossible.

For example, the R5RS says that the result of (eq? '(a) '(a)) is
unspecified.  That's because some implementations are clever enough to
combine the two '(a) immutable list literals into a single object, in
which case #t is returned.  Other implementations make two distinct
copies of '(a), in which case #f is returned.  Of course, efficiency
requires that `eq?' be implemented as a simple pointer comparison.  The
"unspecified" cases are there to allow `eq?' to be implemented
efficiently.

The R5RS gives these examples:

  (eq? 2 2)        ==>  _unspecified_
  (eq? #\A #\A)    ==>  _unspecified_

and also says:

  `Eq?''s behavior on numbers and characters is
  implementation-dependent, but it will always return either true or
  false, [...]

If we were to make (eq? 2 2) return SCM_UNSPECIFIED, we would violate
the requirement above.

Whether `eqv?' should return SCM_UNSPECIFIED when applied to procedures
is undecidable.  The R5RS requires that the result is true when the
procedures' location tags are equal (i.e. when they have the same
identity), and requires that the result is false when the procedures
would "behave differently (return different value(s) or have different
side effects) for some arguments".  The results in all other cases are
unspecified.  The R5RS gives the following example:

  (eqv? (lambda (x) x)
        (lambda (y) y))  ==>  _unspecified_

Here we would need to determine whether two distinct procedures are
equivalent in the sense of always returning the same values and
producing the same side effects.  For such procedures, we should return
SCM_UNSPECIFIED.  Unfortunately, this is undecidable in the general
case.  If we could decide this, we could also decide the halting
problem.

Having said all this, one could still make the case that we should
attempt to return SCM_UNSPECIFIED from expressions whose values are
unspecified by the standards whenever _practical_.  However, doing this
would prevent us from implementing extensions to many aspects of the
standard.

For example, within string literals, the R5RS "does not specify the
effect of a backslash within a string that is not followed by a
doublequote or backslash."  If we were to follow your suggestion, we
should make "foo\n" return SCM_UNSPECIFIED.  In other words, we would be
unable to add our own implementation-specific backslash escapes.

Let's always keep in mind these two common rationales for unspecified
behavior in language specifications:

* to allow more efficient implementation
* to allow extensions to the standard

    Best,
     Mark



  reply	other threads:[~2011-05-25  0:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-22 14:02 (+ (values 1 2)) should be 1 Andy Wingo
2011-05-23 13:34 ` Hans Aberg
2011-05-23 13:49   ` Andy Wingo
2011-05-23 13:58     ` Hans Aberg
2011-05-24 10:35     ` Hans Aberg
2011-05-24 13:11       ` Andy Wingo
2011-05-24 13:48         ` Hans Aberg
2011-05-24 15:07           ` Andy Wingo
2011-05-24 16:13             ` Hans Aberg
2011-05-25  0:25               ` Mark H Weaver [this message]
2011-05-25  8:41                 ` Hans Aberg
2011-05-25 16:54                   ` Mark H Weaver
2011-05-25 17:10                     ` Hans Aberg
2011-06-17 17:43 ` Andy Wingo

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=87ei3nk4mg.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=bug-guile@gnu.org \
    --cc=haberg-1@telia.com \
    /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).