guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

multiple return values


From: Marius Vollmer
Subject: multiple return values
Date: 03 Aug 2001 01:05:25 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102

Hi,

reading a article by William Clinger on comp.lang.scheme just
enlightened me about how to efficiently and correctly implement
multiple return values.

With that technique (see below), we can efficiently ignore superflous
return values in places that don't expect them.  Would you like to
have this behavior?  I.e.

    (define (mfloor x)
      (let ((f (floor x)))
        (values f (- x f))))

could be used in places where only a single value is expected, and the
remainder would be ignored.

Currently, we have the incorrect behavior that

    (define f (mfloor 3.5))

will bind f to multiple values!  I.e.

    guile> f
    3.0
    0.5

The question is now, do we want to allow ignoring superflous values,
or should that be an error.  I'm in favour of allowing them to be
ignored.

- - - -

Here is how I plan to re-implement multiple values:

We define a new `multival' for use by `call-with-values' and `values'.
This fluid is normally `#f'.  When `values' is invoked and multival is
#f, only the first value is returned (or #<unspecified> if there are
no values), or alternativly an error is signalled when there is not
exactly one value.

When multival is #t, the values are returned as a list, and multival
is reset to #f before returning.

call-with-values sets multival to #t, invokes the producer, and then
checks the fluid.  If it is still #t, it is reset to #f, and it is
noted that a single value has been produced.  If it is #f, a list of
values has been returned.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]