Crystal: Multiassign for single = multiple, elements should create a tuple

Created on 16 Jun 2016  路  4Comments  路  Source: crystal-lang/crystal

a = 1, 2, 3

Currently a is [1, 2, 3] now. I propose to change it so that it becomes {1, 2, 3}, that is instead of defining an implicit array, define an implicit tuple. I think that fits better into where we're going with Tuple and Array and the language in general. The proposal so far is about consistency, hence I didn't yet research motivating real-world usecases this would improve or break.

draft compiler

Most helpful comment

I thought about this too a couple of times, but we also have another option: give a syntax error in that case. I think writing

a = {1, 2, 3}

is much more explicit. Maybe in writing a = 1, 2 I forgot to mention the second variable and then I'll get an error because a tuple type will be created instead.

So, which one should we do? I vote for removing this "feature" and giving a syntax error.

All 4 comments

I thought about this too a couple of times, but we also have another option: give a syntax error in that case. I think writing

a = {1, 2, 3}

is much more explicit. Maybe in writing a = 1, 2 I forgot to mention the second variable and then I'll get an error because a tuple type will be created instead.

So, which one should we do? I vote for removing this "feature" and giving a syntax error.

I don't feel too strong about having it either, so either way is fine for me.

+1 for syntax error

I was about to fix this but it was already giving an error as discussed above.

It seems it was fixed in #4824 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lbguilherme picture lbguilherme  路  3Comments

oprypin picture oprypin  路  3Comments

relonger picture relonger  路  3Comments

will picture will  路  3Comments

Papierkorb picture Papierkorb  路  3Comments