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

Multiple values

I essentially support the current multiple-values proposal, but I have a
few comments and suggested clarifications.

-- At BASH, we decided that what has been called WITH-VALUES would be
better named CALL-WITH-VALUES, to be consistent with CALL-WITH-INPUT-FILE.
I still agree with this, but wouldn't hold up progress if others were
strongly opposed to this name.

-- I am unhappy with the current description of VALUES, in particular with
the special casing of the single-argument case.  Why not simply say that
VALUES returns all of its arguments?  Alternatively, could we simply give
the simple implementation of VALUES in terms of CALL/CC?

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

This seems a lot more clear than what's there now.

-- I am similarly unhappy with the way in which the arity of continuations
is described.  Allow me to suggest the following:


There are six contexts in which continuations can be captured in Scheme:

   * the operator position of a procedure call,
   * an operand position of a procedure call,
   * the test position of a conditional,
   * the ``right-hand side'' of an assignment,
   * any but the last expression in the body of a lambda expression, and
   * the application of the first argument to CALL-WITH-VALUES.

The first four contexts are normally thought of as accepting exactly one
value; the effect of passing extra values to such continuations is

The fifth context above ignores any values it receives and so accepts any
number of values, including zero.

In the final context above, the given values are supplied as arguments to
the second argument in the call to CALL-WITH-VALUES.  Correspondingly, the
arity of the continuation is precisely that of the second argument.

The point of the above is to clarify what we intend.  In particular, I
wanted to make it clear exactly what was unspecified and to completely
specify the arity of the ``for-effect'' context.  I also believe that this
description may satisfy Morry's concern about the arity of continuations
created by CALL-WITH-VALUES.

-- Next, I don't think I agree with John that Alan's cheapo implementation
of multiple values is correct.  In particular, I think that the
implementation of VALUES given ought to work; that is, I think that I
should be able to make multiple-argument calls on continuations when I know
their arity.  In Alan's implementation, all continuations take exactly one

As an example of why I think this is important, consider using CALL/CC for
an escape function from a loop.  When I want to escape returning multiple
values, I have to jump through hoops in Alan's implementation, whereas I
can do the obvious thing in a correct one.

-- Finally, as a side note, perhaps we could take this opportunity to
further unspecify the returned values of SET! expressions and the various
side-effecting primitives.  As it is, we say that they return a single
unspecified value.  Could we go a bit further and say that they return an
unspecified number of unspecified values?  I'd like to be able to implement
them as returning zero values in Scheme Xerox.