[comp.lang.misc] Returning multiple values

gary@left.soe.clarkson.edu (Gary Levin) (03/08/88)

References from previous articles are below my follow-up.

SETL has always permitted assignments to tuples (its name for lists),
and functions can return tuples.  The assignment
    [x,y] := [y,x];
provides swap, for instance.

SETL was developed at the Courant Institute.  See Schwartz et al.
Programming with sets: An introduction to SETL.  Springer-Verlag, 1986.

Those interested in trying SETL can write to me.  I have developed an
interactive version of SETL, called ISETL.  It is highly portable,
written in C, and available for MS-DOS (256K min), Mac, Vax (Unix and
VMS), Suns.  Source is available for those wishing to compile for
other machines.  If you get it electronically, there is no fee.  $10
for printed documentation, $10 per media shipped.


===== Original ====
In article <700@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes:
>In article <25284@cca.CCA.COM>, g-rh@cca.CCA.COM (Richard Harter) writes:
>			........
>>                But how do I get stuff back.  I can pass one thing back
>> via the return statement.  To pass more than one thing I have to play
>> games.   ...
>
>No, what is needed is to abandon the mistaken notion that a function
>returns a single result.  From day one, lists should have been allowed
>to the left of the replacement sign--this is not just for functions,
>but even for direct operators.  For example, ...

---
Gary Levin / Clarkson Univ / Potsdam, NY 13676 (315) 268-2384
gary@clutx.bitnet, gary@clutx.clarkson.edu
-- 
Gary Levin / Clarkson Univ / Potsdam, NY 13676 (315) 268-2384
gary@clutx.bitnet, gary@clutx.clarkson.edu

kers@otter.hple.hp.com (Christopher Dollin) (03/08/88)

And of course Pop11 (and it's predecessors Pop-2, Pop-10) have always had 
multiple return values, by virtue of the open stack (like Forth, although that
gives almost, but not quite, entirely the wrong impression ....)

To swop x and y:

    x, y -> x -> y          (not as transparent as x, y -> y, x, alas)

You can also play nice games; for example if _f_ takes 1 arg and delivers 2
results, _g_ takes 2 args and delivers 1 result, then

    g(f(x))                 does the "right" thing

(ie _g_ is applied to the two results coming back from _f_). Makes functional
composition dead easy to define!




Regards,
Kers                                    | "Why Lisp if you can talk Poperly?"