Navigation
Synopsis Declare a module.
Syntax
module Name
Imports;
Declaration1;
...
Declarationn;
Description A module declaration consists of:
  • A module name.
  • Zero or more imports;
  • Zero or more declarations.
The module name Name will be used when the current module is imported in another module. A module name is in general a qualified name of the form:
Name1::Name2:: ... ::Namen
which corresponds to a path relative to the root of the current workspace.

The constituents of a module are shown in the figure below. Module Parts

An Import declares other modules that are used by the current module. Following imports, a module may contain declarations (in arbitrary order, but a SyntaxDefinition can occur directly following the imports) for: Each declaration may contain a private or public keyword that determines the visibility of the declared entity.

The entities that are visible inside a module are
  • The private or public entities declared in the module itself.
  • The public entities declared in any imported module.
The only entities that are visible outside the module, are the public entities declared in the module itself. If different imported modules declare the same visible name, it can be disambiguated by explicitly qualifying it with its module name:
Module::Name
Each module resides in a separate file with extension .rsc.
Examples Here is the Hello module:
module demo::basic::Hello

import IO;

void hello() {
   println("Hello world, this is my first Rascal program");
}
It defines a module with the name demo::basic::Hello and imports the IO library. Finally, it declares the hello function.

The actual source of this module can be found in library/demo/basic/Hello.rsc in the Rascal sources.

More ways to write this example are discussed in Recipes:Hello.
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.