[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Result of (defparameter *x* (values

Malice

3/11/2016 10:04:00 PM

My understanding might be flawed, but here it goes:

VALUES allows to return multiple values. (values a) returns A, (values a b) returns A and B, as multiple values.
(values) returns no values (which is kind of unusual in Lisp, afaik).

Now, let's say that we want to create a new special variable:

(defparameter *x* (values))
*x* => ?

In my implementation, SBCL sets *x* to NIL. Is this desired? If so, why?
3 Answers

Alan Bawden

3/11/2016 10:51:00 PM

0

Malice <gwmaniak@gmail.com> writes:

> (defparameter *x* (values))
> *x* => ?
> In my implementation, SBCL sets *x* to NIL. Is this desired? If so, why?

The general principle is that if you ask for more values than are
returned, you get NIL for the extra values. So this behavior is just a
special case of that: You asked for one value, but zero values were
returned, so you got a NIL.

The standard doesn't quite explain it this way, but this is what the
standard calls for. So the behavior is "desired" in the sense that an
implementation that does something else has a bug.

--
Alan Bawden

Teemu Likonen

3/12/2016 5:58:00 AM

0

Malice [2016-03-11 14:04:00-08] wrote:

> (defparameter *x* (values))
> *x* => ?
>
> In my implementation, SBCL sets *x* to NIL. Is this desired? If so,
> why?

According to the specification it works correctly:

[...] if the form produces zero values, then the caller receives nil
as a value.

http://www.lispworks.com/documentation/HyperSpec/Body...

--
/// Teemu Likonen - .-.. <https://github.com/tl... //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

Malice

3/12/2016 9:33:00 PM

0

On Saturday, 12 March 2016 06:58:18 UTC+1, Teemu Likonen wrote:
> According to the specification it works correctly:
>
> [...] if the form produces zero values, then the caller receives nil
> as a value.
>
> http://www.lispworks.com/documentation/HyperSpec/Body...

Thank you both, this makes sense. It didn't find this explanation in VALUES page, but now I see how it works. Thanks again!