Stream: helpdesk (published)

Topic: `include()` for an explicitly created module


view this post on Zulip James Wrigley (Nov 29 2024 at 17:01):

Why does this not work?

julia> m = Module()
Main.anonymous

julia> @eval m include("foo.jl")
ERROR: UndefVarError: `include` not defined in `Main.anonymous`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] top-level scope
   @ none:1
 [2] eval(m::Module, e::Any)
   @ Core ./boot.jl:430
 [3] top-level scope
   @ REPL[35]:1

m is not a baremodule and the include() docstring says that every module that isn't a baremodule gets its own include() definition.

view this post on Zulip Daniel Wennberg (Nov 29 2024 at 18:31):

Don't know why it doesn't work, but according to the docstring, the solution might be using Base.include, as in

julia> Base.include(m, "foo.jl")

Does that work for you?

view this post on Zulip James Wrigley (Nov 29 2024 at 19:14):

Yeah that's what I'm using as a workaround for now.


Last updated: Dec 28 2024 at 04:38 UTC