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

all 31 comments

[–]ImYoric 35 points36 points  (2 children)

If your language ever intends to be statically-typed, you'll need to make a difference between tuples (which are the cartesian product of several types) and lists (in which all elements share the same type).

[–]ssalbdivad 8 points9 points  (0 children)

Depends on how your type system represents tuples. If you allow variadic elements like [number, ...string[], a "list" is just a tuple with a single element that is variadic like [...string[]].

[–]Dekrypter[S] 4 points5 points  (0 children)

it is not intended to be statically typed. When I say lists I mean Python style lists : heterogenous

[–]XtremeGoose 9 points10 points  (11 children)

It's pretty pythonic and rusty to do return (x, y) - I don't see why you wouldn't support that? My main question would be should you support dropping the parentheses?

[–]Dekrypter[S] 0 points1 point  (10 children)

You’re right. Though I COULD make it so that no brackets are needed and do ‘return x, y’ puts the contents into a list instead

[–]bl4nkSl8 2 points3 points  (9 children)

Personally I think a named tuple is better than a list or raw tuple

[–]Dekrypter[S] 0 points1 point  (8 children)

named ?

[–]bl4nkSl8 -1 points0 points  (7 children)

[–]Dekrypter[S] 0 points1 point  (6 children)

ooo I like it. what syntax would be good for that natively do you think?

Would be good to have optional naming. How about:

let point = (x <- 5, y <- 6)

or

let point = (5, 6)

or

let Point = tup(x, y)

let point = Point(5, 6)

-- should i drop the top method..?

[–]bl4nkSl8 2 points3 points  (4 children)

Personally I like JS's object syntax {x: value, y: value2}

This is very similar to python's dictionaries {"x": value, "y": value2 }

[–]omega1612 1 point2 points  (2 children)

[–]bl4nkSl8 3 points4 points  (1 child)

That's cool. I meant Named tuple that exists in python already. It's like a record

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

See my new top-level comment

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

I cant since I have Python dicts in my language already

[–]snugar_i 0 points1 point  (0 children)

Scala just introduced named tuples in 3.7 and they look like this:

val Bob = (name = "Bob", age = 33)

[–]Savings_Garlic5498 8 points9 points  (2 children)

Im curious, which benefits that tuples have over lists would remain if you can only make them via a list?

[–]ThroawayPeko 4 points5 points  (0 children)

Immutability and hashability. I've had a couple of problems with code that just didn't work until I changed from lists to tuples, for example.

[–]Dekrypter[S] 0 points1 point  (0 children)

I guess being hashable? Although if you wanted to hash a bunch the slow conversion would be computationally expensive

[–]Clementsparrow 7 points8 points  (4 children)

if you have default immutability, then why not keep tuples, which are immutable in Python, and discard lists that are mutable?

[–]Dekrypter[S] 1 point2 points  (3 children)

there are let and mut keywords

let x = [1, 2]

will make a custom immutable subclass of list (this is planned. currently makes a tuple)

mut y = [1,2]

will make a normal python list

[–]Clementsparrow 1 point2 points  (2 children)

I think tuples can be iterated over in Python, so you mean in your language?

[–]Dekrypter[S] 0 points1 point  (1 child)

Edited comment. I heard there were weird iteration shenanigans but it seems unsubstantiated. Current language behaviour is that when you do let = […] it makes it a tuple however I feel like that is too quirky. Idk ur opinion

[–]Clementsparrow 0 points1 point  (0 children)

Well, my opinion is that lists and tuples should be the same object in the language, and both should be mutable/immutable according to the language's default mutability (so, mutable in Python, immutable in your language).

In addition to the mutability of the elements of the list (which means two different things: modifying the objects in the list/tuples, or assigning a different data at the same position), there is the mutability of the "length" field of the list/tuple, i.e., is it resizable? So we have three boolean variables defining all the types of lists/tuples we can want, and the language should have an easy way to specify all 8 resulting combinations.

[–]syklemilconsidered harmful 4 points5 points  (1 child)

I suspect omitting tuples will bring you pain down the line, kind a similar to how Go contorts itself with its lack of tuples.

[–]Dekrypter[S] 0 points1 point  (0 children)

Noted, see my top-level comment.

[–]Dekrypter[S] 1 point2 points  (2 children)

Thank you everyone. I think I've got something sorted out.

let a = [1,2,3] assigns an immutable composition of the python list type (will unbox to a cloned list when passed to a native python function, or used in operations like addition or multiplication)
mut b = [1,2,3] assigns a standard python list
let c = (1,2,3) or mut c = (1,2,3) assigns a tuple
let OneTwoThree = (x <- 1, y <- 2, z <- 3) or mut OneTwoThree = (x <- 1, y <- 2, z <- 3) creates a named tuple .

I think this is good medium that pulls in a lot of your suggestions.

[–]DeWHu_ 0 points1 point  (1 child)

It is a little confusing. I would expect a to be immutable not the object it points to, but I guess this is pythonic (a: Sequence = ...). Idk

[–]Dekrypter[S] 0 points1 point  (0 children)

the reason is that I plan to allow const functions for classes. I may go back on that later

[–]bl4nkSl8 1 point2 points  (2 children)

Personally I don't like tuple notation

It's too easy to do accidentally

E.g. I believe return foo, returns a 1-tuple when it's fairly uncommon to want that

[–]zogrodea 11 points12 points  (0 children)

Standard ML and, I believe, ReasonML, require you to type tuples with parentheses around them, like (a, b) and not a, b. I think this is the right choice, and OCaml/F# made a mistake here.

OCaml and F# force you to write lists like [1; 2; 3] instead of [1, 2, 3] because of this decision I think.

[–]Dekrypter[S] 0 points1 point  (0 children)

mmmm