[Scheme-reports] Multiple values in BEGIN Ian Price 06 May 2011 13:09 UTC

Hello,

Perhaps I have missed something in the report, but what is the behaviour
of multiple values returned to a non-final expression in a BEGIN form?
i.e. what does the following expression do?

(let ((modified? 'no))
     (begin (and (set! modified? 'yes)
                 (values 'yes 'yes))
            modified?))

The current wordings for BEGIN, and implicit BEGINS like LAMBDA and COND
say nothing about this possibility, and so I'm assuming that it falls
back to

"Except for continuations created by the call-with-values procedure, all
continuations take exactly one value. The effect of passing no value or
more than one value to continuations that were created by
CALL-WITH-VALUES is unspecified".

I think this is unfortunate, as returning multiple values behaves
consistently across all the Schemes that I tried (it returned 'yes for
Chicken, Racket, Ypsilon, Mosh, Ikarus, Stklos, MIT/GNU Scheme, Guile,
Chibi and Scheme48), but the report leaves it unportable. The R6RS is
slightly better than the current situation, saying

"The continuations of all non-final expressions within a sequence of
expressions, such as in lambda, begin, let, let*, letrec, letrec*,
let-values, let*-values, case, and cond forms, usually take an
arbitrary number of values."

Would it be possible to add similar language to the report, perhaps
replacing "usually" with "may"? The definition of BEGIN in section 7.3
would also need to change to

(define-syntax begin
  (syntax-rules ()
    ((begin exp)
     exp)
    ((begin exp1 exp2 ...)
     (call-with-values
         (lambda () exp1)
       (lambda args
         (begin exp2 ...))))))

Regards,
Ian

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports