Multiple Values 
Author Message
 Multiple Values

Quote:
John Burger writes:
> Somebody (sorry again) continues:

>   What does this return?
>     (object-class (values 1 2 3))

> This is equivalent to (OBJECT-CLASS (VALUES 1)), or (OBJECT-CLASS 1),
> and thus returns <INTEGER>.


>   I would say: an error. values does not return an object. It returns
>   multiple values, that can be used IMMEDIATLY by forms able to use
>   more than one value.  object-class requires 1 argument, and you give
>   it 3.  This is an error.  Your code is equivalent to:
>     (apply object-class (list 1 2 3 ))

> This is incorrect.  VALUES is an ordinary function, and does return an
> object, in fact any number of them.  You are right that there are
> "forms able to use more than one value", such as BIND and other syntax
> forms.  However, with ordinary functions, the first of multiple values
> is used, and the rest are discarded.  Thus

>   (+ (VALUES 1 2 3) (VALUES 4 5 6))
>   == (+ 1 4)
>   => 5

> Thus, in the above example, OBJECT-CLASS is passed 1, the first value
> of (VALUES 1 2 3), and so returns <INTEGER>.

> The Dylan book does lack for examples of the use of multiple values,
> and people unfamiliar with their use in other Lisps are going to be
> confused.  A major hole that I see is what the "default" value is if
> an expression returns no values.  For example, is the following an
> error, and if not, what is its value?

>   (IDENTITY (VALUES))

> By analogy to CommonLisp, as well as BIND, I would imagine this ought
> to return #F, but it's not made clear.

Then:

        (PRINT (VALUES 1 2 3))

would print:

        1

right?

But (on p. 30):

        (VALUES 1 2 3)

prints:

        1
        2
        3

Does this mean that the "READ-EVAL-PRINT" loop in Dylan has built-in knowlege
of how to print multiple values?  This would imply that the REV loop could not
be written in Dylan wouldn't it?

Regards,
{*filter*}
----
        Richard W. (Dick) Kreutzer

Voice:  +1(801)571-2446                                 FAX:    +1(801)571-2448
Mail:   Integra Software Corp.; 1378 Jasmine Avenue; Sandy, UT 84092 (USA)



Fri, 08 Dec 1995 21:07:38 GMT  
 Multiple Values
|> > This is incorrect.  VALUES is an ordinary function, and does return an
|> > object, in fact any number of them.  You are right that there are
|> > "forms able to use more than one value", such as BIND and other syntax
|> > forms.  However, with ordinary functions, the first of multiple values
|> > is used, and the rest are discarded.  Thus
|> >
|> >   (+ (VALUES 1 2 3) (VALUES 4 5 6))
|> >   == (+ 1 4)
|> >   => 5

Yes indeed, you are right. I was thinking about another way to use VALUES. But
the way you say (equivalent to CommonLisp I guess) is better, because functions
can return multiple values that can be used or not, depending on what the
receiver needs.

But, except for form able to deal with and whose implementation is hidden, you
will probably need another operator: RECEIVE-VALUES.
Is this point specified in Dylan Book?

Regards,
        Antoine



Sat, 09 Dec 1995 15:48:42 GMT  
 Multiple Values

Quote:
> Yes indeed, you are right. I was thinking about another way to use VALUES. But
> the way you say (equivalent to CommonLisp I guess) is better, because functions
> can return multiple values that can be used or not, depending on what the
> receiver needs.

> But, except for form able to deal with and whose implementation is hidden, you
> will probably need another operator: RECEIVE-VALUES.
> Is this point specified in Dylan Book?

BIND allows you to get the additional values.

  (bind ((a b c (values 1 2 3)))
    (list a b c))
  => (1 2 3)

  (bind ((#rest x (values 1 2 3)))
    (apply list x))
  => (1 2 3)

  (bind ((a #rest x (values 1 2 3)))
    (apply list a x))
  => (1 2 3)



Fri, 15 Dec 1995 23:59:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. (values (multiple-value-form)) whats the point?

2. Multiple-value-list with no values.

3. return multiple values from an awk function?

4. multiple values in a return from function

5. Multiple values [was:] Re: scanf() type function

6. Setter Variables and Re: Multiple Values

7. Multiple Values (Correction)

8. multiple values

9. Multiple values in R5RS Scheme

10. multiple values

11. interfaces (was Re: multiple values)

 

 
Powered by phpBB® Forum Software