## `loadmod` -- load a module

#### Introduction

`loadmod``("modulename")` loads the dynamic module named `modulename`.

`loadmod``()` checks whether the MuPAD kernel supports dynamic modules.

#### Call(s)

`loadmod("modulename")`
`loadmod()`

#### Parameters

`"modulename"` | - | the name of a module: a character string

#### Returns

`loadmod``()` returns `TRUE` or `FALSE`; `loadmod``("modulename")` returns a module domain of type `DOM_DOMAIN`.

#### Side Effects

`loadmod``("modulename")` assigns a value to the identifier `modulename`. E.g., after `loadmod(`ßtdmod"`)`, the identifier `stdmod` has the loaded module as its value.

#### Further Documentation

Dynamic Modules - User's Manual and Programming Guide for MuPAD 1.4, Andreas Sorgatz, Oct 1998, Springer Verlag, Heidelberg, with CD-ROM, ISBN 3-540-65043-1.

#### Related Functions

`external`, `export`, `module::new`, `package`, `unloadmod`

#### Details

- `loadmod``()` returns `TRUE` if this MuPAD version supports the use of dynamic modules. Otherwise, it returns `FALSE`.
- `loadmod``("modulename")` loads the dynamic module named `modulename`. Doing this, it defines a corresponding module domain, assigns it to the identifier `modulename` and returns the domain to the MuPAD session. A previously assigned value of the identifier `modulname` is overwritten.
- If the module domain already exists, it is overwritten and the warning '`Warning: Redefinition of domain ...`' is displayed.
- The module file ```modulename.mdm`'' is first searched for in the directories defined in the variable `READPATH`, then in the current working directory and, finally, in the MuPAD module directory.
- If the module cannot be loaded, the evaluation is aborted with an error message.
- If the file ```modulename.mdg`'' exists, then it contains MuPAD objects that are likewise loaded and bound to the module domain. If an error occurs while loading these objects, a warning is displayed and MuPAD tries once more to load them at each call of the module functions affected by it.
- Apart from the module machine code file ```modulename.mdm`'', there may also be a text file ```modulename.mdh`'' containing a brief description of the module. This documentation can be read online using the module function `modulename::doc()` or `modulename::doc(`"methodname"), respectively.
- `loadmod` is a function of the system kernel.

#### Example 1

The following call loads the dynamic module `stdmod`:

    >> loadmod("stdmod")

                                      stdmod

    >> type(stdmod);

                                    DOM_DOMAIN

Since modules are represented as `domains`, they can be used in the same way as library packages or other MuPAD domains. E.g., a module function is called with the prefix `modulename`:

    >> stdmod::which("stdmod")

          "/usr/local/mupad/linux/modules/stdmod.mdm"

As for libraries, `info` can also be used to get information about a loaded module:

    >> info(stdmod)

          Module: 'stdmod' created on 28.Sep.00 by mmg R-2.0.0
          Module: Extended Module Management

          -- Interface:
          stdmod::age,  stdmod::doc,   stdmod::help, stdmod::max,
          stdmod::stat, stdmod::which

The function `export` exports all public functions of the module. After this, the method `"which"` can be called without the domain prefix `stdmod`:

    >> export(stdmod): which("stdmod")

          "/usr/local/mupad/linux/modules/stdmod.mdm"

#### Example 2

Documentation of a dynamic module named `modulename` may be provided by a plain text file ```modulename.mdh`'' which must be located in the same directory as the module file ```modulename.mdm`''. Such documentation can be accessed as demonstrated below. Cf. `module::help` for details.

    >> stdmod::doc()

          MODULE
            stdmod - Extended Module Management

          INTRODUCTION
            This module provides functions for an extended module ...

          INTERFACE
            age, doc, help, max, stat, which

Above, the introductory page of the module documentation was displayed. Below, using the argument `"doc"`, the help page of the function `stdmod::doc` is shown:

    >> stdmod::doc("doc")

          NAME
            stdmod::doc - Display online documentation

          SYNOPSIS
            ...

          SEE ALSO
            info, module::help

#### Background

- The kernel functions `external`, `loadmod`, and `unloadmod` provide basic tools for accessing modules. Extended facilities are available with the `module` library.
- Only one instance of a dynamic module can exist in memory at time. Each further call of `loadmod` only reloads the machine code if it was unloaded or displaced before. However, the module domain is always re-created on loading.
- The machine code of dynamic modules can be unloaded during a MuPAD session using the function `unloadmod`.
- MuPAD provides a module resource management which may displace the machine code of dynamic modules if they are currently not needed, or if there is a lack of memory resources.
- Besides dynamic modules, MuPAD also supports so-called static modules which cannot be unloaded or displaced at runtime automatically. Also refer to `unloadmod`.

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000