There are probably better ways to resolve this problem – as Isaiah points
out, if getFuncPointer is fast enough, you needn't do anything at all. If
it's slow, I would probably just memoize it.
That said, if for some reason you particularly needed to inline a runtime
constant, you could do so by defining a function that redefines itself. For
example, as a proof of concept:
function f(x)
@eval begin
function f(x)
return x*$(hard_calculation())
end
f($x)
end
end
hard_calculation() = (sleep(1); 5)
# Will take a second the first time, but is instant thereafter.
@time f(10)
And of course, as there are many functions that follow this format you'd
want to use a macro to generate them. With all the quoting and splicing
that might take some decent macro-fu, though. Happy to help with this if
you want.