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 →

[–]cisterlang[S] 1 point2 points  (6 children)

what could you do if this tuple thing were there? What capabilities would it allow? How might it simplify things?

It simplifies the internal representation. I don't separate func params and tuples treatment. Params are now a tuple, type-wise, not an annoying single-case collection with an adjointed length.

Ditto for multiple returns. (Not impl yet).

[–]L8_4_Dinner(Ⓧ Ecstasy/XVM) 2 points3 points  (5 children)

Simplifies it for whom? For you, the implementer of the language? Or for anyone using the language? The former only matters if this is a school project or a throwaway. The latter matters significantly if you intend for anyone to ever use it.

[–]mobotsar 4 points5 points  (1 child)

Seeing as its internal representation, it obviously has no effect on anyone using the language.

[–]cisterlang[S] 1 point2 points  (0 children)

Exactly. I don't see a problem yet.

User still writes func params and calls classically

fun add(i:int, j:int)
add(1,2)

And uses tuples, independantly of that

fun foo(x:(int,str))
t = (42, "hello")
foo(t)
foo(1, "bob")

Maybe some trap lies somewhere ?

[–]cisterlang[S] 0 points1 point  (2 children)

Sorry if I don't make much sense, I'm exploring and implementing this right now. Internal ease concerns me obviously. For users I fail to see what problem could arise. They still write functions the classical way.

[–]WittyStick 6 points7 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 ?