FUNCTION REFERENCE

import

Add package functions and classes to the import list of the current workspace.

Add package functions and classes to the import list of the current workspace.

Syntax

import pkg.*

Syntax

import pkg.name pkg.sub.other

Syntax

import('pkg.*')

Syntax

L = import

Packages: a folder named +pkg directly inside the current folder or a search path folder is the package pkg; +sub inside it is pkg.sub. Its files are called by qualified name: pkg.fn(x), pkg.sub.fn(x), [a, b] = pkg.fn(x), pkg.fn or a script pkg.script as a statement, pkg.Cls(x) and pkg.Cls.staticMethod(x) for a classdef file (class(obj) is 'pkg.Cls'), @pkg.fn, feval('pkg.fn', x), str2func('pkg.fn'), which pkg.fn, exist('pkg.fn') and help pkg.fn. A variable named pkg always wins: pkg.fn is then field access. A package found in several folders is one package; per name the first folder in lookup order wins. Package folders do not go on the path (genpath leaves them out): inside a package function another function of the same package needs its qualified name or an import, and a private folder inside the package is visible to the package's files. An unknown name in an existing package errors "Unable to resolve the name 'pkg.nothere'."

import pkg.name makes name usable without the prefix; import pkg.* does so for every file of the package. The list belongs to the workspace that runs import: a function starts with an empty list and drops it on return, a script adds to the list of the workspace it runs in, and the Command Window list stays until clear import. Lookup order for a name: variables, explicitly imported names, local functions, wildcard-imported names, private functions, the current folder, the path, builtins; so an imported name shadows a builtin. A handle made to an imported name (@name) keeps the qualified name. L = import returns the list as a cell column of text ('pkg.*', 'pkg.name'); import alone prints it. A name or package that does not exist errors "Import argument 'pkg.nothere' cannot be found or cannot be imported."

Example

L = import; size(L)   % 0 1

Differences from MATLAB: import takes effect when the statement runs, not for the whole function before it. No Java imports (import java.util.* is an error) and no meta.package. clear import works at the Command Window only. Handles to static methods (@pkg.Cls.method) are not supported. A superclass in a package needs its full name (classdef B < pkg.A); import does not shorten it.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.