Actually, Python returns a SINGLE value, which may be a
composite item like a tuple or a list. Python makes
assignment of the contained values by having0 a feature
called Tuple Unpacking - which is what makes both:
tuple = 1, 2
x, y = tuple
possible. Python ALSO has List Unpacking ( not as
ubiquitous or frequently used ):
>>> range( 3 )
[0, 1, 2]
>>> [a,b,c] = range(3)
>>> a
0
>>> b
1
>>> c
2
But this unpacking of a container is NOT quite the same thing that is
meant by multiple-value returns in Lisp. ( In John Nagle's quote above)
Lisp can also return lists of values, but Multiple return values are
a different animal. Two or more values are returned and all but the
first one are optional. ( And the painful syntax alluded to above, is
the method used to tell it that you want those other optional values. )
Python's divmod(), which returns a tuple pair of values is no
different from a Lisp function that returns a pair of values
as a list or a dotted pair. If you only want the first value
of the pair, you have to select it in some way. ( But I do
like the Python syntax for selecting it -
Python: a = f(x)[0] Lisp: ( setq a ( car ( f x )))
Both of which would generate an error if f(x) returned the
value "1" rather than a pair of values. )
But a Lisp function that returns multiple values only returns a
single value, UNLESS you use the special syntax to capture the
optional values.
Another related, but again, somewhat different concept/feature
is multiple return values Icon style - i.e. coroutine generators
that can supply a series of values, and return a different one
each time the generator function is called. Icon has an 'every'
to force the generator to yield all of it's values.
I don't mean to pick on you in particular: other comments in this
thread probably also missed the distinction, but since your
example was Python, it caught my attention more that the others.
- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics