-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Variadic (or "Varargs") destructuring of tuples #9870
Comments
The package https://github.com/kmsquire/Match.jl allows to do this
|
This is a usage question for the julia-users mailing list. The issue tracker is for bug reports. |
You could interpret this as a feature request for such syntax. @lilinjn, |
@jiahao, the topmost syntax doesn't work: julia> (x,z...) = (1,2,3)
ERROR: syntax: invalid assignment location I'm pretty sure I've proposed this before and I think we can reasonably view this issue as a feature request for this syntax. |
Implementing this can also prepare the way for deprecating the sometimes surprising behaviour where |
I'm torn about discarding trailing values. It makes it possible to have silent bugs where you drop values that you didn't mean to, but on the other hand, it allows gracefully extending APIs by returning additional values without breaking old call sites, which is a very handy property. |
Sorry, misread. |
Thanks for the feedback -- I should have been more clear that I was seeking comments prior to working on a potential PR (as well as making sure that I wasn't missing some alternate syntax). |
No worries – I thought it was clear enough. A PR would be excellent and most appreciated! |
duplicate of #2626 |
See? I knew it was a good idea. |
In julia, is there some syntax similar to
(x,z...) = (1,2,3)
which would result inx=1
&z=(2,3)
?If not, are there reasons why this was not supported, or perhaps this could be a reasonable feature request (or, more constructively, prior to working on a PR, do others have thoughts about this)?
Ideally, since nested destructuring e.g.
(a,(b,c)) = (1,(2,3))
works as expected, any variadic version would also work e.g.(a,(b,c,d...),e...) = (1,(2,3,4,5),6,7)
would yieldAnd perhaps
(a,(b,c,d...),e..., nexttolast, last) = (1,(2,3,4,5),6,7,8,9,10)
would yieldWhile
(a,(b,c,d...),e..., nexttolast, last) = (1,(2,3,4,5),9,10)
would yieldAnd finally
(a,(b,c,d...),e..., nexttolast, last) = (1,(2,3,4,5),10)
would result in an error, justlike the current behavior for
(a,b) = 1
The text was updated successfully, but these errors were encountered: