Re: New version of C-like interpreter available

Steven D. Majewski (sdm7g@elvis.med.Virginia.EDU)
Mon, 4 Apr 1994 06:22:37 GMT

In article <2nieht$jtk@news.delphi.com>,
DAVEGOTTNER@DELPHI.COM <davegott@news.delphi.com> wrote:
>jholland@world.std.com (Jerome T Holland) writes:
>
>>In article <nagleCnGvqt.95x@netcom.com>, John Nagle <nagle@netcom.com> wrote:
>>>davis@pacific.mps.ohio-state.edu ("John E. Davis") writes:
>>>
>>> Multiple return values are syntactically difficult. Most attempts
>>>at a syntax are painful. Common LISP is the most popular language with
>>>this feature, and even there, it doesn't fit well with the rest of the
>>>language. Mesa, the old Xerox PARC language, had multiple returns done
>>>well, but the Mesa approach of treating a function call as a structure
>>>constructor followed by a one-argument function call returning a structure
>>>of return values never really caught on, mostly because it didn't match
>>>the type systems of C or Pascal.
>>>
>>> John Nagle
>In Python, it's trivial:
>
>A function can return multiple values:
>
> return a, b
>
>Then, you get the values the same way:
>
> x, y = foo()
>
>You can also just get a tuple of the return values:
>
> tup = foo() # tup[0] is a, tup[1] is b
>
>
>Very simple and conveinent.
>

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