Skip to content

Namespaces

Overview

A namespace N can contain declarations that are then accessed by writing N:: or using the namespace or declaration. For example:

Declaring some things in a namespace
//  A namespace to put all the names provided by a widget library
widgetlib: namespace = {
    widget: type = { /*...*/ }
    // ... more things ...
}

main: () = {
    w: widgetlib::widget = /*...*/;
}

using

A using statement brings names declared in another namespace into the current scope as if they had been declared in the current scope. It has two forms:

  • using a_namespace::a_name; brings the single name a_name into scope.

  • using namespace a_namespace; brings all the namespace's names into scope.

For example:

using statements
//  A namespace to put all the names provided by a widget library
widgetlib: namespace = {
    widget: type = { /*...*/ }
    // ... more things ...
}

main: () = {
    //  Explicit name qualification
    w: widgetlib::widget = /*...*/;

    {
        //  Using the name, no qualification needed
        using widgetlib::widget;
        w2: widget = /*...*/;
        // ...
    }

    {
        //  Using the whole namespace, no qualification needed
        using namespace widgetlib;
        w3: widget = /*...*/;
        // ...
    }

    // ...
}