-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
parserLanguage parsing and surface syntaxLanguage parsing and surface syntaxspeculativeWhether the change will be implemented is speculativeWhether the change will be implemented is speculative
Description
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
Labels
parserLanguage parsing and surface syntaxLanguage parsing and surface syntaxspeculativeWhether the change will be implemented is speculativeWhether the change will be implemented is speculative