Tritium Libraries (Mixers): Namespaces

A namespace is a self-contained set of functions or variables. They are most commonly found in libraries added to your project.

The default namespace for a project is the tritium namespace.

Defining a Namespace

To define a namespace, use the following:

@namespace json

Including Other Namespaces

In order to carry over functions from other namespaces, you can add those to the opening definition:

@namespace json, tritium

The above line means that when using the namespace json, the Tritium namespace will also be included. Tritium functions can then be used inside the json namespace.

Variables are not inherited in the same way: in the above example, variables defined in the tritium namespace are not available in the json namespace. This includes environment variables (e.g., $path).

Using a Namespace

To use a namespace, just use the @open function with the name of the namespace:

@open json

After that, you can use functions or variables from that namespace. The namespace will only be opened within the current scope.

Using Functions Outside of the Namespace

You can use functions outside of the namespace — just prepend the function with the namespace required.