Mailfromd Manual (split by node):   Section:   Chapter:FastBack: MFL   Up: Modules   FastForward: Library   Contents: Table of ContentsIndex: Concept Index

4.21.3 Require and Import

Functions or variables declared in another module must be imported prior to their actual use. MFL provides two ways of doing so: by requiring the entire module or by importing selected symbols from it.

Module Import: require modname

The require statement instructs the compiler to locate the module modname and to load all public interfaces from it.

The compiler looks for the file modname.mf in the current search path (see include search path). If no such file is found, a compilation error is reported.

For example, the following statement:

require revip

imports all interfaces from the module revip.mf.

Another, more sophisticated way to import from a module is to use the ‘from ... import’ construct:

from module import symbols.

Note the final dot. The ‘from’ and ‘module’ statements are the only two constructs in MFL that require the delimiter.

The module has the same semantics as in the require construct. The symbols is a comma-separated list of symbol names to import from module. A symbol name may be given in several forms:

  1. Literal

    Literals specify exact symbol names to import. For example, the following statement imports from module A.mf symbols ‘foo’ and ‘bar’:

    from A import foo,bar.
    
  2. Regular expression

    Regular expressions must be surrounded by slashes. A regular expression instructs the compiler to import all symbols whose names match that expression. For example, the following statement imports from A.mf all symbols whose names begin with ‘foo’ and contain at least one digit after it:

    from A import '/^foo.*[0-9]/'.
    

    The type of regular expressions used in the ‘from’ statement is controlled by #pragma regex (see regex).

  3. Regular expression with transformation

    Regular expression may be followed by a s-expression, i.e. a sed-like expression of the form:

    s/regexp/replace/[flags]
    

    where regexp is a regular expression, replace is a replacement for each part of the input that matches regexp. S-expressions and their parts are discussed in detail in s-expression.

    The effect of such construct is to import all symbols that match the regular expression and apply the s-expression to their names.

    For example:

    from A import '/^foo.*[0-9]/s/.*/my_&/'.
    

    This statement imports all symbols whose names begin with ‘foo’ and contain at least one digit after it, and renames them, by prefixing their names with the string ‘my_’. Thus, if A.mf declared a function ‘foo_1’, it becomes visible under the name of ‘my_foo_1’.

Mailfromd Manual (split by node):   Section:   Chapter:FastBack: MFL   Up: Modules   FastForward: Library   Contents: Table of ContentsIndex: Concept Index