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

Re: [Scheme-reports] [scheme-reports-wg1] Re: Proposed compromise on #68 "unspecified value(s)"

Per Bothner scripsit:

> How should zero or multiple values be handled in a single-value
> context such as function arguments?  I.e. what is the best behavior
> of: (list (values 3 4) 10) I see 3 plausible options:
> (A) Multiple values are real data values that can be passes as
> arguments and stores in variables.  They're basically a "tuple" type,
> in that (values x) is equivalent to plain x, and so they're like a
> non-nestable list. [...]
> (B) Multiple values are "spliced" in the argument list, thus (list
> (values 3 4) 10) is the same as (list 3 4 10).  I've long been
> attracted to this functionality, but I'm now concerned that it may be
> both too error-prone (too easy to write hard-to-catch bugs) as well
> has being difficult to optimize, I'm now thinking an explicit splicing
> operator (possibly @ for consistency with quasi-quoting) is probably
> better.
> (C) Multiple values in argument position (or assigned to a variable)
> is an error.  This can help catch what are likely to be errors.

For zero values, Gauche, MIT, Gambit, Chicken, Bigloo, Kawa, SISC,
Chibi, Larceny, Ypsilon, Mosh, IronScheme, STklos, KSi use option A:
sometimes the value is the same as the magic undefined value, sometimes
it isn't.  For more than one value where one value is expected: MIT,
Gambit, Kawa, SISC, Ypsilon, KSi return a tuple; Chicken, Bigloo,
Larceny, STklos return the first value, the same as CL.  Mosh is not
consistent: (list (values 1 2)) returns two values, (1) and 2, but (+
(values 1 2) 3) returns 4.

No Scheme uses option B.  In addition to the objections you raise,
there is the fact that if cons is known to be bound to the usual value, 
"(cons (x))" can be rejected by a compiler under options A and C, but
might be valid under option B.

Racket, Scheme48/scsh, Chez, SCM, Ikarus, SigScheme use option C.

> I just checked in a fix to do the same for the producer (though I
> can't imagine anyone wanting that ...).

If you are invoking a library procedure that returns multiple values,
you can get them as a list with (call-with-values (lib-proc) list).
I do this routinely in test code.

> >> Kawa doesn't complain about (define x (set! y 32)) but it probably
> >> should.
> >
> > A warning might be appropriate, but not an error, as x should be
> > bound to something (in this case #!void) in accordance with R5RS.
> But R5RS doesn't allow these to return zero values, so conformance
> with R5RS is moot.

In Kawa and in the other zero-values-option-A Schemes above, returning
zero values is the same as returning an object, though the two may or
may not be distinguishable through the use of call-with-values: in
Kawa they are not, in other Schemes they are.  For example, in Chicken
(call-with-values void list) returns a list of length 1, because void
returns the unspecified object, but (call-with-values values list)
returns the empty list.

Verbogeny is one of the pleasurettes    John Cowan <cowan@x>
of a creatific thinkerizer.             http://www.ccil.org/~cowan
   --Peter da Silva

Scheme-reports mailing list