module_parent

module_parent(m::Module) -> Module

Get a module's enclosing Module. Main is its own parent, as is LastMain after workspace().

Examples

  1. Get the parent module:

    julia> module A
              module B
                  module C
                  end
              end
          end
    julia> module_parent(A.B.C)
    B

    This example retrieves the parent module of A.B.C, which is B.

  2. Handle the top-level module:

    julia> module M
          end
    julia> module_parent(M)
    Main

    In this case, the module_parent function returns Main as the parent module of M.

  3. Handle modules after workspace():
    julia> workspace()
    julia> module N
          end
    julia> module_parent(N)
    LastMain

    After using workspace(), the parent module of N becomes LastMain.

Common mistake example:

julia> module X
          module Y
          end
       end
julia> module_parent(X)
ERROR: UndefVarError: X not defined

In this example, the module X is not defined in the current scope, resulting in an UndefVarError. Make sure the module is defined before calling module_parent.

See Also

assert, backtrace, code_llvm, code_lowered, code_native, code_typed, code_warntype, :@which, compilecache, current_module, eval, finalize, finalizer, fullname, function_module, function_name, include_dependency, InterruptException, invoke, isconst, isdefined, isgeneric, methodswith, method_exists, module_name, module_parent, require, subtypes, unsafe_load, workspace, __precompile__,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: