Wiki
Clone wikipool-spec / Aliases
Aliases
Basic Usage
An alias is used to give a symbol a new name. The two names can be used interchangeably and will behave identically. An example of an alias is below.
alias languages::vitrualmachine::java::files::jar::Jar as JJar;
Now you may use JJar in place of languages::vitrualmachine::java::files::jar. This allows the following code:
// main.pool import containers::jar; import languages::vitrualmachine::java::files::jar; int main ( String[] arg ) { mutable jars = new containers::jar::Jar(); jars.insert(new languages::vitrualmachine::java::files::jar::Jar(arg[1])); }
becomes:
// main.pool import containers::jar; import languages::vitrualmachine::java::files::jar; alias containers::jar::Jar as GJar; alias languages::vitrualmachine::java::files::jar::Jar as JJar; int main ( String[] arg ) { mutable jars = new GJar(); jars.insert(new JJar(arg[1])); }
Allowing you to use both your glass jars and .jar
s with ease.
Disambiguating Aliases
Sometimes, like in the previous examples you get two symbols with the same name from two different modules. If you want to use one without having to fully qualify paths you can alias the symbol over itself.
alias containers::jar::Jar as Jar;
Now, any reference to Jar
will refer to containers::jar::Jar
without
needing to be fully qualified.
Scoped Aliases
Aliases are only valid in the scope in which they are declared and only below where they exist in the source file.
mutable score :Score = 1_000_000; // ERROR: Score is undefined. alias uint as Score; mutable score :Score = 1_000_000; // Good. { alias uint32 as Timeval; immutable t :Timeval = 779573880; } mutable curTime :Timeval = 779573880; // ERROR: Timeval undefined.
This is a recommended way of using aliases as shortcuts as the definition is close to the use. This prevents confusion when unreadable names are used.
Updated