Build Status

Provides two macros: @import and @using which loads a module or object and binds it to an alias.


@import can be used with modules, or specific objects inside modules, to create an alias, and to hide the underlying module from the user code. For example

julia> using ImportMacros

julia> @import LinearAlgebra as LA

julia> LA.dot([1, 2], [3, 4])

creates an alias LA which is bound to the LinearAlgebra module. Note that the name LinearAlgebra is hidden and only the alias name is introduced in the calling scope:

julia> LinearAlgebra
ERROR: UndefVarError: LinearAlgebra not defined

A (shorter) alias can be useful, for example, if non-exported functions from modules are used frequently in the code. For instance, compare the two different ways of calling the function foo from the module MyLongModuleName:

alias.foo() # via the alias

MyLongModuleName.foo() # via the original module name

An alias can also be useful in order to load a package with a name that conflicts with your own code.

The syntax for @using is the same as for @import

@using MyLongModuleName as alias

but the result is roughly equivalent to

using LongModuleName
const alias = LongModuleName


The package can be installed with Julia's package manager, either from the Pkg REPL

pkg> add ImportMacros

or from the Julia REPL

julia> using Pkg; Pkg.add("ImportMacros")

First Commit


Last Touched

7 months ago


21 commits