Why does not keyword parameter evaluate to String?

#1

Consider the code below

julia> function foo(f;FuncType="UnivariateFunction")
           foo_backend(f,FuncType=FuncType)
           end
foo (generic function with 1 method)

julia> function foo_backend(f;FuncType="UnivariateFunction")
           println("Function Type is ",FuncType)
           end
foo_backend (generic function with 1 method)

julia> func1(x) = x^2
func1 (generic function with 1 method)

julia> func2(x,y) = x^2 + y^2
func2 (generic function with 1 method)

julia> foo(func2,FuncType="MultivariateFunction")
Function Type is MultivariateFunction

Why doesn’t the code “foo_backend(f,FuncType=FuncType)” evaluate to

foo_backend(f,“MultivariateFunction”=“MultivariateFunction”)

when it is called with foo(func2,FuncType=“MultivariateFunction”)

I am just curious

0 Likes

#2

I am not sure I understand your question, but in

foo_backend(f,FuncType=FuncType)

the first FuncType is the name of the keyword argument, while the second FuncType (on the right hand side of the =) is just an expression like any other and will be evaluated as such — if there is not such variable, it will error.

0 Likes