Marcin 'Qrczak' Kowalczyk wrote:
> Per Bothner <per_at_bothner.com> writes:
> [mutiple values] can't be fully first-class.
>
> (call-with-values (lambda () x) (lambda (y) y))
>
> This currently succeeds for any value of x, it doesn't even look inside it.
> This would stop working for x being the multiple-values value.
If the variable x is bound to multiple values (zero or more than one),
the this code would be erroneous. But this is "currently" not possible.
So I don't understand your comment.
>
>> E.g. you can assign an expression whose result is multiple values to
>> a variable, or pass it as a function parameter.
>
> How many values is (values (values 1 2 3) (values 4 5 6))?
> What about (values (values 1 2 3))? Here lies madness.
No, it is quite consistent (and useful).
(values (values 1 2 3) (values 4 5 6)) == (values 1 2 3 4 5 6)
(values (values 1 2 3)) == (values 1 2 3)
That assume "values" has "append-values" semantics.
>> Assume one views a declaration as an expression that evaluates to
>> no values. A "body" is a compound expression that can contain
>> declarations and expressions in any order, and whose result is the
>> "concatenation" of the results of each sub-expression.
>
> This would break tail calls or would require code duplication.
I don't believe so. A suggested implementation model is "producer
and consumer". (let () exp1 ... (proc arg ...)) is equivalent to
(values exp1 ... (proc arg ...)). First each exp1 ... is evaluated
with the passed-in consumer, and any values that exp1 produces are
"written" to the consumer. Then proc and arg ... are evaluated,
and proc is tail-called using those args - and the same consumer.
At top-level the outermost consumer is the read-eval-print loop, so
values are written directly as they are produced, in a nice functional
manner without needing display/write statements.
But note this this idea is a more radical change than I think is
feasible for R6RS. To get the full benefit would require new
syntax primitives, and so make most sense if designing a language
from scratch (as XQuery did). (One could design a Scheme-like
language based on combining multiple values, but you probably
wouldn't want to call it Scheme, even if you provide a fair
amount of backward compatibility.)
--
--Per Bothner
per_at_bothner.com http://per.bothner.com/
Received on Mon Oct 02 2006 - 14:27:08 UTC