loadproc
-- load an object on
demandloadproc
loads a MuPAD object from a file when
it is first accessed.
object := loadproc(object, path, file)
object |
- | any MuPAD object that is a valid left hand side for an assignment |
path |
- | a relative path name with a terminating path separator: a string |
file |
- | a file name without suffix: a string |
an element of the domain stdlib::LoadProc
(see
``Background'' below).
export
, finput
, fread
, LIBPATH
, loadmod
, package
, pathname
, Pref::verboseRead
, read
loadproc
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.loadproc
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.
The path and the name of the file are given by the two strings
path
and file
, respectively. The function
pathname
is useful
for creating path names in a platform independent way.
object
is evaluated for the first time, the
system first tries to read the MuPAD binary file
path . "." . file . ".mb"
,
where .
is the
concatenation operator. MuPAD searches for this file relative to
the directories given by LIBPATH
. The first matching file is
read. If the search fails, MuPAD tries the text file
path . "." . file . ".mu"
instead.
The corresponding file must contain the ``real''
definition of object
, typically a statement of the form
object := value
. If this is not the case, the system may
run into infinite recursion.
Finally, after the file has been read, value
is
returned as the value of object
. The whole loading process
is transparent to the user. See the example below for illustration.
loadproc
does not evaluate the first argument
object
, but the other arguments are evaluated as
usual.At system startup, the identifier int
is initialized as follows:
>> int := loadproc(int, pathname("STDLIB"), "int"):
This tells the system that it finds the actual
definition of the integration function int
in the file
"STDLIB/int.mu"
, relative to the library path specified by
LIBPATH
, which by
default points to MuPAD's installation directory.
When you first use int
,
e.g., by entering the command int(t^2,t)
, MuPAD automatically
loads the file "STDLIB/int.mu"
. This file contains the
following lines defining the actual function
environment int
:
int := funcenv( proc(f, x = null()) begin if args(0) = 0 then error("No argument given") end_if; ... end_proc):
After the file has been read, the function environment
is returned as the value of int
, and then the system proceeds as
usual: the call int(t^2,t)
is executed and its result t^3/3
is returned.
loadproc
returns an object of the domain stdlib::LoadProc
. This is an
internal data type; manipulating its elements should never be
necessary. Therefore it remains undocumented.loadproc
. In such a case, it may
happen that an object is loaded even before it is first accessed,
namely when another object is accessed whose definition is located in
the same source file.