How to keep the value of function pointer?

The code you showed here works fine:

julia> begin
         x = Ref{Function}(sin)
         @show x[](0)
         s = x[]
         x[] = cos
         @show s(0)
         @show x[](0)
         nothing
       end
(x[])(0) = 0.0
s(0) = 0.0
(x[])(0) = 1.0

So clearly there’s some difference between your actual code and the MWE you posted here.

2 Likes