This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Multiple Values in Kawa


Nigel Dolby wrote:
In porting some Common Lisp code to Kawa I have converted a function that returns multiple values, but I find differences between Kawa's treatment of multiple values and Common Lisp's. The differences do not seem to be discussed in SRFI11.

Multiple values as part of standard Scheme, since R5RS, which you can check out in: http://schemers.org/Documents/Standards/R5RS/

Question 1. Exactly what is the type of this value in Kawa,

gnu.mapping.Values.


and how can it be decomposed to obtain the first return-value by itself?

(let-values (((a . rest) (values 1 2 3 4))) a)


This doesn't work for zero values, though.

Question 2. Why does Kawa not follow the Common Lisp convention?

R5RS does not define what happens if you provide multiple values to a context that expects a single value. An implementation can signal an error in that context, drop all but the first (as is done in Common Lisp), or pass all the values as a bundle (as Kawa does).

Kawa does also attempt to also implement (a subset of) Common Lisp.
So in "Common Lisp mode" Kawa needs to follow the Common Lisp
specification.  It does not, so this is a bug in Kawa.  However, Kawa
Common Lisp is experimental and unsupported, so this bug is not urgent.

Another factor is XQuery - http://www.w3.org/TR/xquery/
The data model of XQuery is based on "sequences" which consist
of "items".  An XQuery sequence is different from the usual
concept: There is no difference between a sequence of a single item
and the item itself.  As a consequence, you cannot nest sequences.
These properties match the Lisp/Scheme concept of "multiple values"
so it was tempting to use the same implementation for both.

There are difference in usage, of course: An XQuery sequence may be
very long, while Lisp/Scheme multiple values have just a few values,.
(The Common Lisp specification does not require an implementation to
support more than 20 values.)  Most importantly, in XQuery variable
maybe bound to a sequence, while in Common Lisp and portable Scheme
it can only be bound to a single value.

The XQuery concept turns out to be quite elegant and useful.  It allows
us to integrate "statements" and "expressions".  A "statement" is an
expression that returns zero values.  A loop is an expression that
returns many values.  The expressions in a <body>, or a "statement
sequence" as written 'statement1;statement2' in many languages is
multiple-value-concatenation.

This model may not be appropriate for something that claims to be
Scheme, so it is not the default.  However, it is used in the
KRL language (http://www.gnu.org/software/kawa/KRL.html),
which is an experimental variation of the BRL web language.
Also, the even-more-experimental Q2 language is based on sequences
http://www.gnu.org/software/kawa/q2/

So I'm convinced the Common Lisp model of truncating extra values
is not as useful as one which keeps them.  However, if we want to
support Common Lisp, we have to implement the Common Lisp model,
at least when the language is Common Lisp.  It is not clear which
model should be the default for "plain Kawa Scheme" if we view
that as an implementation of Scheme with extensions.  We may want
to see if R6RS has anything to say on it.  But in terms of "this
is how I should think a programming language "should be like" then
the Common Lisp model is definitely not it.

Kawa does need support for the Common Lisp model.  The trick is how
to do this efficiently, and how this integrates (if it does) with
the "sequence" support for XQuery, KRL, and Q2.  I think this needs
to wait until we tackle continuations - which I expect will finally
happen this year.  (I am working in it, in the background.)

Question 3. I think I had problems with trying to return multiple values from a method on an object created with define-simple-class. Does this work in Kawa? (It does in CLOS).

Yes, I believe it does. Try it. -- --Per Bothner per@bothner.com http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]