Instead of passing around functions as strings (or encoded as numbers like F
), it is much better to simply pass them around as functions. e.g. if you set
myfunc = DeltaAII
you can just call myfunc(1)
. A function called DeltaAII
can also be passed as an argument to another function. This is called a higher-order function.
PS. The literal answer to your original question is
func(x) = eval(Meta.parse(@sprintf("Delta%s(%f)",myfunc,x)))
but this is a classic anti-pattern. See How to warn new users away from metaprogramming … in particular, you almost never want to pass functions or expressions as strings that you parse and evaluate. It’s fragile, slow, and inflexible. Julia has first-class functions — enjoy it!