Dear all,
As a part of a program I am developing in Julia, I would like to have boundary conditions defined as Julia functions. However, I ran into the “too new for this world problem”. It took me quite a while to come up with MWE. (It may still be a bit on the big side, but anything smaller simply wouldn’t feature the error I am getting in the real program.) Hence, apologizing in advance that it may still be too long, here it comes:
module BoundaryMod
export Boundary
mutable struct Boundary # structure with boundary condition definition
value :: Function # holds functions describing boundary conditions
function Boundary() new((x,y,z) -> 0.0) end
end
end
module StagMod # module holding numerical method
export Stag
export stag_allocate # allocates memory for the method
export stag_compute # compute something based on boundary conditions
using ..BoundaryMod
mutable struct Stag
b :: Boundary # needs boundary conditions
function Stag() new(Boundary()) end
end
function stag_allocate(s :: Stag)
s.b.value = eval(Meta.parse("function(x,y,z) return x+y end"))
end
function stag_compute(s :: Stag)
println(s.b.value(1.0, 1.0, 1.0))
end
end
using .BoundaryMod
using .StagMod
function main() # calling this creates "not from this world" problem
s = Stag()
stag_allocate(s) # allocate memory and define boundary conditions
stag_compute(s) # compute something with it
end
If I load this into Julia and run main()
, it creates the error:
ERROR: MethodError: no method matching (::Main.StagMod.var"#1#2")(::Float64, ::Float64, ::Float64)
The applicable method may be too new: running in world age 29641, while current world is 29642.
Closest candidates are:
(::Main.StagMod.var"#1#2")(::Any, ::Any, ::Any) at none:1 (method too new to be called from this world context.)
Funny enough (or maybe quite logical, just beyond my understanding) if I load this file and run three functions from the main()
from REPL, they behave just fine:
julia> s = Stag()
Stag(Boundary(Main.BoundaryMod.var"#1#2"()))
julia> stag_allocate(s)
#3 (generic function with 1 method)
julia> stag_compute(s)
2.0
Please let me know if you can give me a hint on how to resolve this.
Cheers