Load an object on demand
This functionality does not run in MATLAB.
autoload loads a MuPAD® object from a file when it is first accessed.
The MuPAD library is quite big. However, users typically need only a small part of the library. It would be very time and memory consuming to load the whole library at startup. autoload provides a concept for delaying the process of loading a predefined object, such as a library domain or a library procedure, until the time when it is first needed.
autoload returns an element of a special domain. This element only stores the information about the file where object is defined, but it does not yet read the file. This happens only when object is used for the first time.
Unlike loadproc, autoload does not require (nor allow) the explicit setting of path names. Therefore, it works only with objects adhering to the following filename convention: The definition of libname::function is found in the file function.mu in the directory LIBNAME (note: the directory name is capitalized for systems where this makes a difference) which is situated in a directory in LIBPATH.
For objects containing multiple levels of ::, such as a::b::c, the filename convention is similar: autoload(a::b::c) would expect to find a file c.mu in a directory B in a directory A in one of the directories in LIBPATH.
To avoid side-effects, alias definitions and user-defined operators are not in effect while the file is read, except those that are defined within the file. Alias definitions in the file are local to the file only; they are removed when the loading is finished.
myLib := newDomain("myLib"):
The functions, domains, etc. in this library will usually be placed in separate files. Assuming that all of these files adhere to the name convention outlined above, it is easy to arrange for load-on-demand of the definitions:
Usually, this command would be placed in LIBFILES/myLib.mu and be ended with a colon (:) to suppress the output. When looking at the output, we can see that the definition would be sought in a file someFunction in the directory MYLIB. This would happen transparently to the user, if the file existed, but since it does not, we get an error:
Error: Cannot read file 'MYLIB/someFunction.mu'. [loadproc]
The name of the object to be loaded, must be a valid left-hand side of an assignment
Element of the domain stdlib::LoadProc (see the documentation of loadproc for details).