Skip to content

default values for destructuring syntax: (; x=default) = y #51940

@stevengj

Description

@stevengj

As commented by @simeonschaub in #39285, it might be nice to have a way to provide default values in destructuring syntax. This came up recently on discourse.

A natural syntax for this might be:

(; a=default_a, b, c=default_c) = x

where the default values are employed if !hasproperty(x, :a) and/or !hasproperty(x, :c).

More precisely, I think it would be good to specify that the default-value expressions are only evaluated if the corresponding property on the rhs does not exist. So that you could do (; a=default_a()) = x and default_a() would only be called if x.a does not exist, functionally equivalent to a = hasproperty(x, :a) ? x.a : default_a().

Metadata

Metadata

Assignees

No one assigned

    Labels

    parserLanguage parsing and surface syntaxspeculativeWhether the change will be implemented is speculative

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions