[gambit-list] strange results using values

Marc Feeley feeley at iro.umontreal.ca
Sun Sep 21 19:35:59 EDT 2008


On 21-Sep-08, at 3:25 PM, Arthur Smyles wrote:

> (if (values #f) #t #f)
>
> => #f
>
> (if (values #f #f) #t #f)
>
> => #t
>
> I was surprised to discover this. Although technically not a bug  
> since the scheme spec considers this situation unspecified, it makes  
> using multiple-values unreliable.

In what way is it "unreliable"?  The situation is defined as an error  
by the Scheme standard, which means a user cannot expect any specific  
behavior.

Gambit handles multiple values by treating the "values" procedure as a  
data structure constructor (just like "vector" except with a different  
type tag).  The exception is that when it is given a single argument  
it behaves like the identity function, so (values 123) = 123 .  This  
explains why (if (values #f #f) 11 22) gives 11, just like (if (vector  
#f #f) 11 22) gives 11, but (if (values #f) 11 22) = (if #f 11 22) =  
22 .

> This affects pp as well
>
> (pp (values #f #f))
>
> => #<unknown>

What would you expect this to give?  I'm not sure this is related to  
what you want to do, but these operations are available:

 > (##values? (values 11 22))
#t
 > (##vector->list (values 11 22))
(11 22)
 > (for-each pp (##vector->list (values 11 22)))
11
22

Marc



More information about the Gambit-list mailing list