bug-guile
[Top][All Lists]
Advanced

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

Re: GIT version: values


From: Andy Wingo
Subject: Re: GIT version: values
Date: Wed, 26 Jan 2011 21:51:08 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hi Hans,

Thanks for porting to the 1.9 development series!

On Wed 19 Jan 2011 15:44, Hans Åberg <address@hidden> writes:

> It seems it is not only 'values' writing, but the new behavior seems to
> be to strip trailing values quietly:
>   (define a (values 2 3 4))
>   (call-with-values (lambda () a) (lambda x x))
> in Guile 1.9.14.68-a7d8a computes to
>   $1 = (2)
>
> By contrast, in guile-1.8.8, it computes to
>   (2 3 4)

Indeed.  This and a (hopefully small) number of other differences are
noted in the NEWS.  In this case:

    ** Returning multiple values to compiled code will silently truncate the
       values to the expected number

    For example, the interpreter would raise an error evaluating the form,
    `(+ (values 1 2) (values 3 4))', because it would see the operands as
    being two compound "values" objects, to which `+' does not apply.

    The compiler, on the other hand, receives multiple values on the stack,
    not as a compound object. Given that it must check the number of values
    anyway, if too many values are provided for a continuation, it chooses
    to truncate those values, effectively evaluating `(+ 1 3)' instead.

    The idea is that the semantics that the compiler implements is more
    intuitive, and the use of the interpreter will fade out with time.
    This behavior is allowed both by the R5RS and the R6RS.

    ** Multiple values in compiled code are not represented by compound
       objects

    This change may manifest itself in the following situation:

      (let ((val (foo))) (do-something) val)

    In the interpreter, if `foo' returns multiple values, multiple values
    are produced from the `let' expression. In the compiler, those values
    are truncated to the first value, and that first value is returned. In
    the compiler, if `foo' returns no values, an error will be raised, while
    the interpreter would proceed.

    Both of these behaviors are allowed by R5RS and R6RS. The compiler's
    behavior is more correct, however. If you wish to preserve a potentially
    multiply-valued return, you will need to set up a multiple-value
    continuation, using `call-with-values'.

There is no tuple with multiple-valued returns: they are returned on the
stack.

Regards,

Andy
-- 
http://wingolog.org/



reply via email to

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