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.
using a_namespace::a_name ; brings the single name a_name into scope.
using a_namespace::_ ; brings all the namespace's names into scope using the _ wildcard.
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 specific name, no widgetlib:: qualification needed
using widgetlib::widget;
w2: widget = /*...*/;
// ...
}
{
// Using the whole namespace, no widgetlib:: qualification needed
using widgetlib::_;
w3: widget = /*...*/;
// ...
}
// ...
}