This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Multiple Values in Kawa
- From: Nigel Dolby <nigel_dolby at acm dot org>
- To: 'Kawa List' <kawa at sources dot redhat dot com>
- Date: Fri, 13 Jan 2006 08:16:34 -0600
- Subject: Multiple Values in Kawa
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. A standard Common Lisp way to use
multiple values is to make the first return-value from a function a
"primary" value, and to treat other return-values essentially as
optional. In Common Lisp it is possible to call a function that returns
multiple values as if it returned a single value (the primary one),
which allows the function to be called without making any provision for
return-values after the first (i.e. without using multiple-value-bind).
In Kawa all values appear to be concatenated to form a single value if
this is done.
Question 1. Exactly what is the type of this value in Kawa, and how can
it be decomposed to obtain the first return-value by itself?
Question 2. Why does Kawa not follow the Common Lisp convention? This
functionality is valuable for at least two reasons. (1) I have a
function that reads lines from a text file and therefore returns as its
first value the next line of text from the file. But some files can be
interactively edited, which may involve deleting the line by overwriting
its first character. The function therefore returns as its second value
the position of the first character of the line within the file. Many
uses of the function do not need this value and therefore ignore it,
treating the function as if it returned a single value; for those that
need it, it is available to be explicitly captured. (2) One of the great
benefits of Lisp systems is their support for interactive prototyping of
ill-understood problems. It not infrequently happens that what starts
out as a simple function returning a single value, mutates as the
problem becomes better understood so that it needs to return additional
information (my line-read function initially just returned the line of
text). As long as additional return-values are ignored if not explicitly
captured, then the function can be modified to return more values and
these values can be used where needed in new code, but all previously
existing calls on the function will continue to work with no changes to
the old code. When exploring application functionality this is very
effective, even if the code ultimately needs to be cleaned up (which was
not the case with my line-read function).
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).
Nigel Dolby.