[plt-scheme] Multiple values

From: hufflen jean-michel (hufflen at lifc.univ-fcomte.fr)
Date: Tue Feb 21 11:40:13 EST 2006

>From robby at cs.uchicago.edu  Tue Feb 21 16:47:41 2006

>The whole point of values is they are not that. (FWIW, this isn't PLT
>Scheme's choice. R5RS specifies it.)

   Where?  I did not see that in the description of "values" and

>They introduce a lot of new errors that were not there before. For
>example, the test position in an if has to check the number of values,
>applications have to check the function and arg positions for the
>number of values, let and letrec have to check their right-hand sides
>for a single value, set! has to check its expression positions is a
>single value ... every non-tail position in the language has to add
>this check.

   Personally, my "history" with multiple values has begun with Common Lisp. I
thought the concept was interesting, but I noticed that:

(multiple-value-call #'+ (values 1 2))

(let ((v (values 1 2)))
  (multiple-value-call #'+ v))

did not produce the same result, which I found strange. Then multiple values
have been incorporated into MIT Scheme, but a result of "values" is never
equivalent to... a single value (this was the case in Common Lisp):

(+ (values 1) 2) causes an error. This is probably due to a raw
implementation, like:

(define (values . arg-list)
  (lambda (f) (apply f arg-list)))

   Further implementations make the use of "values" with one argument
equivalent to the same argument without "values", something like:

(define values
  (let ((*marker* (cons #f #f)))
    (lambda arg-list
      (if (and (not (null? arg-list)) (null? (cdr arg-list)))
          (car arg-list)
          (cons *marker* (lambda (f) (apply f arg-list)))))))

   That seems to me to be satisfying... if values other than "#f" are viewed
as true.  I recognize that something like:

(if (values #f #f) ... ...)

may be shocking, but why do we tolerate:

(if (vector #f) ... ...)

(if (list #f) ... ...)

   In addition, such a choice makes the "values" function equivalent to the
identity function when used with one argument.  Let us remark that this
"trick" is very used in some SRFIs programmed by Olin Shivers.

   Yours sincerely,

			       J.-M. H.

Posted on the users mailing list.