Popularity
35 Stars
Updated Last
4 Months Ago
Started In
November 2016

ImportMacros.jl

Build Status

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

Usage

@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])
11

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

Installation

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")

Required Packages

No packages found.

Used By Packages