You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to redistribute the keyword arguments to subsequent function calls? I tried the following code
julia> f1(;x1=1)=x1
f1 (generic function with 1 method)
julia> f2(;x2=2)=x2
f2 (generic function with 1 method)
julia> g(;args...)=f1(;args...)+f2(;args...)
g (generic function with 1 method)
julia> g(x1=1)
ERROR: unrecognized keyword argument "x1"
in g at none:1
julia> g(x2=1)
ERROR: unrecognized keyword argument "x2"
in g at none:1
I was expecting x1 to be passed to f1 and x2 to be passed to f2. By redefining f2 as below I concluded that only the keyword arguments accepted by all subsequent function calls are valid for g.
julia> f2(;x1=1,x2=2)=x2
f2 (generic function with 1 method)
julia> g(x1=1)
3
julia> g(x2=1)
ERROR: unrecognized keyword argument "x2"
in g at none:1
Wouldn't it be more natural to just ignore the unrecognized keyword arguments? Here is a real-life example of how I was trying to use keyword arguments
function meshsolve(rhs,; args...)
[...]
mesh=prepare_mesh(rhs; args...)
[...]
solve(rhs, mesh; args...)
end
The function meshsolve solves the equation rhs=0 but it first tries to prepare a suitable mesh. Both prepare_mesh and solve can accept keyword arguments, but for obvious reasons these arguments are not identical for both functions.
The text was updated successfully, but these errors were encountered:
Any function can choose to ignore unrecognized keywords by adding ; args.... Given such a simple workaround, it doesn't seem appropriate to automatically ignore unmatched keywords everywhere. I think the current design has it right.
Also having the ;args... as a Dict might help (#4916).
Is it possible to redistribute the keyword arguments to subsequent function calls? I tried the following code
I was expecting x1 to be passed to f1 and x2 to be passed to f2. By redefining
f2
as below I concluded that only the keyword arguments accepted by all subsequent function calls are valid forg
.Wouldn't it be more natural to just ignore the unrecognized keyword arguments? Here is a real-life example of how I was trying to use keyword arguments
The function
meshsolve
solves the equationrhs=0
but it first tries to prepare a suitable mesh. Bothprepare_mesh
andsolve
can accept keyword arguments, but for obvious reasons these arguments are not identical for both functions.The text was updated successfully, but these errors were encountered: