# Eval() fails inside a function when it works stand alone

I have this code, which works just fine outside of the function but when I enclose it inside the function it fails at the eval() command with the following hard to decipher message. I have looked at other similar problems but I do not understand how to fix this one. Any help will be appreciated. Cheers

MethodError: no method matching (::var"#87#88")(::Float64)
The applicable method may be too new: running in world age 33916, while current world is 33917.

Closest candidates are:
(::var"#87#88")(::Any) (method too new to be called from this world context.)
@ Main C:\Users\PWC.julia\packages\SymbolicUtils\ssQsQ\src\code.jl:373

``````function testing(time)
@variables t

D = Differential(t)

c = 0.06 * pi   # Used to make the mathematical code clearer only.
C = 0.3  # Capacitance in Farad.
L = 1.7  # Inducatance in Henry.
R = 1.4  # Resistance in Ohms.

# This the function as given in the assignment question.
v_equ = (exp(-c*t) * sin(2*t - pi))

# This calculates the 1st derivative
dv_equ = D(v_equ)

# This calcultes the 2nd derivative
dv2_equ = D(dv_equ)

# This is the full function for di/dt as a function of t only
di_equ = expand_derivatives(C * dv2_equ + 1/R * dv_equ + v_equ/L)

f_i=build_function(integrate(di_equ, symbolic=true, detailed=false),t)
f_i=eval(f_i)

current=f_i.(time)-f_i.(zeros(size(time)))
return(time,current)
end

time,current=testing(time)

plot(time,current,label="Integrated")
plot!(Runga_time,Runga_current, label="Runga")
plot!(Euler_time,Euler_current,label="Euler")
``````
1 Like

You’ll want to try `invokelatest`, documented here. That’s the usual fix for world-age problems.

Thank you, I did discover that command, however, I have no idea how or where to use it as the example in the reference you gave is totally different to what I am doing.

I will leave the code in the main body for the time being, it is just untidy and I don’t like doing so.

I was hoping Julia was ‘better’ than other languages and would not have all these weird issues going on everywhere

No, the answer is almost never “use `eval` and `invokelatest`”. Instead the answer is to avoid using `eval`.

In a situation like this, I’d recommend RuntimeGeneratedFunctions.jl instead.

3 Likes

Thank you,

Is there any chance you might indicate how to use this in my code please?

I have included the module RuntimeGeneratedFunctions but like most other documentation, the simple example is far from simple and really gives me exactly no clue what is required to incorporate this into my code.

I am getting an error but I have no understanding of what it means.

Cheers, Paul

That error is telling you that there’s not a macro named `@RuntimeGeneratedFunctions` defined — it’s not defined because it’s misspelled. It should be singular: `@RuntimeGeneratedFunction`.

1 Like

Thank you so much, and i am sorry for the silly mistake.

It is working as it should now, with three different method of solving my differential equation producing almost identical results.

2 Likes