function hello(;name="world")
println("hello, $(name)")
end
keyname = "name"
hello(keyname="today") # I don't want to use hello(name="today") directly~
then will get error:
ERROR: LoadError: MethodError: no method matching hello(; keyname=“today”)
Closest candidates are:
hello(; name) at /ifshk7/BC_PS/sikaiwei/software/julia/tmp.jl:3 got unsupported keyword argument “keyname”
Stacktrace:
That’s an usual question. It would help to know why you don’t want to use hello(name="today") directly. Keyword arguments (like name in hello(;name) are intended to be set by assigning to the keyword when the function is called (hello(name="today")). There is no language-level provision for dynamically changing the keyword. Not knowing the purpose makes it difficult to advise … you might do this:
function hello(;name::String)
println(string("hello ",name))
end
hello2(;keyname::String) = hello(name = keyname)
hello2(keyname="world")
# prints: hello world