Currently, keyword arguments must explicitly state the key and value being referenced in a call. However, this can be fairly verbose when both the value variable and kwarg key share the same name (e.g. f(; value = value)
).
This issue proposes that f(; value)
be interpreted as f(; value = value)
. A precedent for this style comes from ES6, namely { value }
as the shorthand for { value: value }
.
color = :green
printstyled("test"; color = color) # current
printstyled("test", color) # proposed
This is especially helpful for functions which recursively propagate keyword arguments:
f(x; kwarg) = x ≤ 0 ? kwarg : ("(" * f(x-1; kwarg = kwarg) * " | " * f(x-2; kwarg = kwarg) * ")")
f(x; kwarg) = x ≤ 0 ? kwarg : ("(" * f(x-1; kwarg) * " | " * f(x-2; kwarg) * ")")
The existing convention for right-precedence would not be affected.
I believe @davidanthoff suggested this during the discussion on named tuples, and indeed it's already implemented in julia-syntax.scm and would just need to be un-commented :)
If this were done it should be conditional on using semicolon to denote the start of keywords
printstyled("test"; color)
Otherwise this convenience could end up calling unintended methods. Or at least it would be quite ambiguous
Closing since most of the discussion is on the dup.
Most helpful comment
I believe @davidanthoff suggested this during the discussion on named tuples, and indeed it's already implemented in julia-syntax.scm and would just need to be un-commented :)