Modules

Figure 79. Module

Module

You can group functions and variables in separate library modules.

Figure 80. MainModule

MainModule

Up to now, everything we encountered were main modules, i.e., a prolog followed by a main query.

Figure 81. LibraryModule

LibraryModule

A library module does not contain any query - just functions and variables that can be imported by other modules.

A library module must be assigned to a namespace. For convenience, this namespace is bound to an alias in the module declaration. All variables and functions in a library module must be prefixed with this alias.

Example 179. A library module

module namespace my = "http://www.example.com/my-module";
declare variable $my:variable := { "foo" : "bar" };
declare variable $my:n := 42;
declare function my:function($i as integer) { $i * $i };
    

Figure 82. ModuleImport

ModuleImport

Here is a main module which imports the former library module. An alias is given to the module namespace (my). Variables and functions from that module can be accessed by prefixing their names with this alias. The alias may be different than the internal alias defined in the imported module.

Example 180. An importing main module

import module namespace other= "http://www.example.com/my-module";
other:function($other:n)
    

Result (run with Zorba): 1764