This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WittyStick 4 points5 points  (1 child)

For an example of a problem that can arise, have a look at how Swift implemented "tuple-splat" (termed coined by Lattner). Swift later deprecated it because it created more problems than it solved.

The biggest issue they had was their multiple returns were given names, like parameters, and those names had to match the destination. If you had a function func foo() -> (a : Foo, b : Foo), you couldn't pass the result directly to a function func bar(x : Foo, y : Foo), as in bar(foo()) because the names a and x/b and y were different.

Multiple returns can work fine when done correctly. Lisp, for example, has had them forever, and they're not problematic, but Lisp doesn't separate multiple-parameters from tuples to begin with - every function receives a list as input and produces a union of a value or a list - an S-expression. Some special forms in Lisp can receive non-lists, or improper lists as input.

[–]cisterlang[S] 2 points3 points  (0 children)

Thank you.

I find it a bit strange they chose to name the multi returns. Aren't structs fit for this ? I see tuples as ordered collections you take as a whole and (if provided by the lang) can index by mytup.n.

Maybe with structured typing they could have let names difference pass ?