Modules

A module is a set of rules packaged in a membrane with a module name definition:

{ module(modulename), RuleSet }

The RuleSet is made available only when it is copied or 'loaded' outside the membrane. The module system of LMNtal provides a loading mechanism of modules.

A module can be defined either in the source file or in a separate file. In the latter case, the module can be either in source code or in intermediate code.

Name Space

A single-level global name space is available for the names of atoms. An atom name p can be qualified with a module name m. The qualified atom name m.p can be referred to anywhere in the program.

Compile-Time Module Loading

When a program uses a qualified atom name of the form m.p, the membrane that contains the qualified atom name will be supplied with a copy of the rules specified in the module m.

Example

{ module(acc).
  acc.add(A),   acc.value(N) :- acc.value(A+N).
  acc.get(Res), acc.value(N) :- int(N) | Res=N, acc.value(N).
  acc.new                    :- acc.value(0) }.

{ acc.new, acc.add(3), acc.add(4), acc.get(N) }

Link-Time Module Loading

Modules defined in files in the $LMNTAL_HOME/installed/share/slim/lib directory or in the directories specified after the -I option of SLIM will be loaded, compiled (if not in the intermediate code) and linked before the exection of the user program starts.

System rulesets

A system ruleset is a set of global rules, namely rules applicable to every place in the membrane structure. For instance, built-in arithmetics (that evaluates x=1+2*3 to x=7, for example) is implemented as system rulesets.

A programmer can define his/her own system ruleset by defining the system_ruleset module.


Reload   New Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes
Last-modified: 2017-03-02 (Thu) 03:32:49 (25d)