If in Julia I try to do something like this, I’m rightly stopped by the program:
julia> f(; x, x) = x
ERROR: syntax: function argument name not unique: "x" around REPL[1]:1
Stacktrace:
[1] top-level scope
@ REPL[1]:1
julia> f(; x) = x
f (generic function with 1 method)
julia> f(; x = 2, x = 4)
ERROR: syntax: keyword argument "x" repeated in call to "f" around REPL[3]:1
Stacktrace:
[1] top-level scope
@ REPL[3]:1
But this instead is allowed, which seems strange/contradictory to me:
julia> f(; x, kwargs...) = x
f (generic function with 1 method)
julia> kwargs = (x = 4,)
(x = 4,)
julia> f(; x = 2, kwargs...)
4
So…is this a bug or a feature?
edit:
Actually it works also if you use as a definition of f
only f(; x) = x
, which is even weirder:
julia> f(; x) = x
f (generic function with 1 method)
julia> kwargs = (x = 4,)
(x = 4,)
julia> f(; x = 2, kwargs...)
4
Tried both in 1.9.4 and 1.10-rc3