Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hai prog: multiple return values

Name: Anonymous 2009-10-02 19:31

Hello

I know one can use pass-by-reference for getting multiple values back from a function, but is there a language that allows you to actually define multiple outputs seperate from the parameter list for super neatness.

I was thinking it would be super-cool to have an auto-defined struct based on the function return values. so in some pseudo-language it would be like...


def splitstring  string<s char<sep string>a string>b

s = "hello world"

splitstring s ' '

printf(splitstring.a)
printf(splitstring.b)


would that be totally kawaii aewsome?

obviously each thread would have its only instances of these auto-structs.

Name: Anonymous 2009-10-05 7:54

>>34
I have some interesting facts for you.

>>> def f(): return (1, 2), "valid python code"
...
>>> f()
((1, 2), 'valid python code')
>>> t = f()
>>> t
((1, 2), 'valid python code')
>>> x, y = f()
>>> x, y
((1, 2), 'valid python code')
>>> f()
((1, 2), 'valid python code')
>>> (a, b), c = f()
>>> a, b, c
(1, 2, 'valid python code')
>>> def dot((x1, y1), (x2, y2)): return x1 * x2 + y1 * y2
...
>>> p1, p2 = (1, 0), (0, 1)
>>> dot(p1, p2)
0
>>> lst = x, [y, z] = [1, (2, 3)]
>>> lst
[1, (2, 3)]
>>> x, y, z
(1, 2, 3)


As you do indeed resemble the invisible poster in certain respects, I feel I'd save everyone's time by explaining up front: Python has fully functional destructuring bind built in and it works in assignments, on function calls, everywhere. By the way, RHS can be any iterable, not just tuple or list.

There are three differences from the lithtth protheththing language:

1. It's somewhat less powerful -- there are no named/rest arguments. Actually "*xs, x = (1, 2, 3)" works in Py3K, but on the other hand they pulled automatic destructuring in lambda arguments or something because Guido hates lithp weenies and wants to drive them away, no matter the cost.

2. You never need to actually call some macro to have it. It just works.

3. Excessive parentheses do not make you want to gouge your eyes out with a soup ladle.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List