Module loading

Module loading

Base.require is responsible for loading modules and it also manages the precompilation cache. It is the implementation of the import statement.

Experimental features

The features below are experimental and not part of the stable Julia API. Before building upon them inform yourself about the current thinking and whether they might change soon.

Module loading callbacks

It is possible to listen to the modules loaded by Base.require, by registering a callback.

  1. loaded_packages = Channel{Symbol}()
  2. callback = (mod::Symbol) -> put!(loaded_packages, mod)
  3. push!(Base.package_callbacks, callback)

Please note that the symbol given to the callback is a non-unique identifier and it is the responsibility of the callback provider to walk the module chain to determine the fully qualified name of the loaded binding.

The callback below is an example of how to do that:

  1. # Get the fully-qualified name of a module.
  2. function module_fqn(name::Symbol)
  3. fqn = fullname(Base.root_module(name))
  4. return join(fqn, '.')
  5. end

PreviousArrays with custom indicesNextInference

原文: https://juliacn.github.io/JuliaZH.jl/latest/devdocs/require/