julia> a(x) = 3 + x
a (generic function with 1 method)
julia> a(2)
5
julia> function b(a)
@eval a(x) = $a + x
return nothing
end
b (generic function with 1 method)
julia> b(10)
julia> a(2)
12
Likely this is not actually something you want to do, so it would be good if you described the problem you are trying to solve so we avoid X/Y problems.
This is generally not a good idea and won’t work out of the box because the already compiled code won’t see the redefined method until you hit global scope. You’d need to use Base.invokelatest inside the solve which is not performant. See documentation.
You could try is pass that function as another parameter into the problem or define some sort of struct where you can then change the values later on.
globals are very difficult to reason about, you are opening yourself up to a lot of potential bugs, and poor performance too.
I don’t totally understand your use case as your code is not a full MWE (e.g. what is prob). But you could maybe use a functor ? that’s a struct that can be called like a function:
struct Temperature{L}
interp::L
end
(f::Temperature(t, x) = f.interp(x) # But why don't you use `t` ??
interp = Temperature(LinearInterpolation(Tvec, [1.,2.,3.,4.,5.]))