How one can evaluate @printf to be returned to a value

You could do something like

function DeltaAI(z)
    return 1/(1+z)
end

function DeltaAII(z)
    return √(1-z^2)
end

F=0;
if (F==0)
    myfunc = "AI"
elseif  (F==1)
    myfunc = "AII"
end

func(x) = getfield(@__MODULE__, Symbol("Delta", myfunc))(x)
func(1)

but I would very much recommend structuring your code differently and explicitly writing out the logic in func. E.g.

function func(x, F)
    if F == 0
        DeltaAI(x)
    elseif F == 1
        DeltaAII(x)
    else
        throw(ArgumentError("F must be 0 or 1"))
    end
end
1 Like