X, y = 1, 2, 3 doesn't raise error? Neither does x, = 3

question

#1

x, y = 1, 2, 3 behaves the same as x, y = 1, 2

Also x, = 3 behaves the same as x = 3

Are they a feature?

In python both would trigger exceptions, which I think is better.


#2

Yes, this is a feature. Not sure which is better.


#3

One arguable benefit of this syntax is that one can easily discard unneeded function return values:

julia> f()=(1,2,3);
julia> x,=f();
julia> x
1

#4

x, = 3 works because numbers are iterable. There’s a concurrent discussion about that: Numbers as single-element collections


#5

I definitely see the current behavior as an advantage. It means, among other things, that I can add more outputs to an existing function, without breaking all code that calls that function.

I do this frequently in Matlab, and expect that it will happen with Julia too.


#6

Also see https://github.com/JuliaLang/julia/issues/18312.