Skip to content

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

@plut

Description

@plut

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions