Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature suggestion) tuple destructuring and ellipsis: (a, b...) = function() #39499

Closed
plut opened this issue Feb 3, 2021 · 1 comment
Closed

Comments

@plut
Copy link

plut commented Feb 3, 2021

All is in the title. Currently this syntax is not understood:

julia> (head, tail...) = (1,2,3,4,)

ERROR: syntax: invalid assignment location "b..." around REPL[1]:1

This would probably be quite easy to implement (just replace rvalue[2] by rvalue[2:end] whenever there is an ellipsis), very natural to understand, and does not overwrite any existing syntax. It also provides a nice way of dealing with lists (LISP-style).

Also, while I'm writing about tuples, this is a bit surprising:

julia> (head, tail) = (1,2,3,4,)
(1,2,3,4)
julia> (head, tail)
(1,2)

I would argue that there is at least a missed warning here (in the first line, while I understand that this is lowered as head=(1,2,3,4)[1]; tail=(1,2,3,4)[2], it should warn that the lvalue tuple is too short), and some strange behavior of the assignment operator (it is very weird that an expression of the form A=B does not return the value of A).

@fredrikekre
Copy link
Member

fredrikekre commented Feb 3, 2021

Implemented in #37410 on master (edit: actually in 1.6 too!):

julia> (head, tail...) = (1, 2, 3, 4)
(1, 2, 3, 4)

julia> head
1

julia> tail
(2, 3, 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants