I am developing a package, let’s say Package.jl. In its scr directory, I have three files: A.jl and B.jl in which are defined three functions (a(), b() and c()), and the main Package.jl file.
The latter includes:
module Psycho
export
a, c # b is not exported
include("A.jl")
include("B.jl")
end
In summary, three functions (a, b, c) located in two files (A and B). Critically, both c() and a() use b(), which is unexported, and c() also uses b():
a → b
c → a & b
Here’s the twist. I would like c() and b() to be in the B.jl file, and a() to be in the A.jl file.
It seems that the above implementation doesn’t work (it errors and says that b() is not defined). It works if I place b() in A.jl before the definition of a(), but I would like to know what are my options to avoid that? I hope the example is clear enough.
Sorry I got confused in my own example (I thought it’d be simpler but no ), I forgot to mention that c() also uses a() and b(), so including B before A doesn’t work as a() is not defined yet… I’ll edit the question
Are you sure a(), b() and c() are plain functions and not type definitions? You shouldn’t have any issues with functions since they are only resolved during first call which normally happens much later than the whole module is defined.
If these are indeed functions, could you please example content of A.jl and B.jl and other steps to reproduce it (e.g. ran from REPL, used precompilation, ran as script, etc.)?
Thanks for the example, though I agree that this setup is less ideal.
In my original example, I do wonder why Julia runtime needs to complain about not knowing type B during pre-compilation time — wouldn’t it be possible for Julia runtime to parse all the type definitions at once like other AOT-compiled languages?