strange results using values
(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. This affects pp as well (pp (values #f #f)) => #<unknown> Arthur
Afficher les réponses par date
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
"Arthur" == Arthur Smyles <atsmyles@earthlink.net> writes:
Arthur> (if (values #f) #t #f) Arthur> => #f Arthur> (if (values #f #f) #t #f) Arthur> => #t Arthur> I was surprised to discover this. I look at it this way: only #f is false; (values #f) => #f is false, whereas (values #f #f) is something that is not #f, and therefore true ;) Seems simple, but I'm always having to remind myself that it works that way. Joel -- Joel J. Adamson University of North Carolina at Chapel Hill CB #3280, Coker Hall Chapel Hill, NC 27599-3280 Before you reply to this email, please read http://www.unc.edu/~adamsonj/email-howto.html
participants (3)
-
Arthur Smyles -
Joel J. Adamson <adamsonj@email.unc.edu> -
Marc Feeley