Product SiteDocumentation Site

Chapter 7. Modules

Figure 7.1. Module

You can group functions and variables in separate library modules.
Figure 7.2. MainModule

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

Figure 7.4. ModuleDecl

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 7.1. A library module
module namespace my = "";
declare variable $my:variable := { "foo" : "bar" };
declare variable $my:n := 42;
declare function my:function($i as integer) { $i * $i };

Figure 7.5. 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 7.2. An importing main module
import module namespace other= "";
Result (run with Zorba):