[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

An alternate description of the multiple values proposal

As I said in my last message on this topic, I'm pretty unsatisfied with the
descriptions that have been circulated thus far.  Unfortunately, my
proposed description in that message seems to have been ignored, so I'll
repeat it here in the context of a complete proposed description of the
facility, including the write-ups of VALUES, CALL-WITH-VALUES, and

I like this wording much more than the others presented so far because it
seems much clearer to me.  The others have all been too vague or opaque for
my taste; in particular, none of them say anything about the legality of
returning other than one value to ``for effect'' context.  Some of the
earlier descriptions also use the wording ``a `with-values' form'' or ``a
`with-values' expression''; this is misleading, since WITH-VALUES (or
CALL-WITH-VALUES) is a procedure, not a syntactic keyword.

I would appreciate hearing any comments on the description below.



(VALUES obj ...)                                         [Procedure]

Returns all of the arguments, in the order given.  VALUES could be
implemented as follows:

    (define values
      (lambda args
           (lambda (k)
              (apply k args)))))

See the description of CALL-WITH-CURRENT-CONTINUATION for a discussion of
the number of values accepted by various contexts.

(CALL-WITH-VALUES producer consumer)                     [Procedure]

Producer should be a procedure of zero arguments and consumer should be a
procedure.  Consumer is applied to the value(s) returned by invoking
producer.  CALL-WITH-VALUES returns the result(s) of the invocation of

(CALL-WITH-CURRENT-CONTINUATION proc)                    [Procedure]

Proc must be a procedure of one argument.  The procedure
CALL-WITH-CURRENT-CONTINUATION packages up the current continuation as an
``escape procedure'' and passes it as an argument to proc.  The escape
procedure is a Scheme procedure that when applied, ignores the continuation
in effect at that time and instead gives its argument(s) to the
continuation that was in effect when the escape procedure was created.

The number of arguments accepted by an escape procedure depends upon the
continuation in effect when the escape procedure was created.  There are
six contexts in which continuations can be captured in Scheme:

   1. the operator position of a procedure call,
   2. an operand position of a procedure call,
   3. the test position of a conditional,
   4. the expression in an assignment,
   5. any but the last expression in the body of a lambda expression, and
   6. the invocation of the producer argument to CALL-WITH-VALUES.

Escape procedures created in any of the first four contexts accept at least
one argument; the effect of applying them to more than one value is
unspecified.  In some implementations, an error is signalled; in some
others, the extra values are ignored.

Escape procedures created in the fifth context above ignore any arguments
passed to them and so accept any number of values, including zero.

An escape procedure created in the final context above accepts exactly as
many arguments as are accepted by the consumer procedure in that invocation