5.1.1 Generic Class Declaration


A Generic Class has parameters that are substituted into the source code in the Class source code and any generic procedures that belong to it. A list of Generic parameters follows the class name. Each parameter is a macro name with a leading underscore with an optional default value. When a Generic name appears within the Class file or any of its Generic member procedures, the name is replaced with the corresponding value.

To import a Generic Class add Generic arguments used to import the class and set the generic parameters. Then when source code contains a parameter name it will be substituted with the argument value for the parameter.


Unique Class, Type, and Procedure names are created when declaring a Generic Class. When a class is imported a compound name is created that can be used to reference an instance of a generic class. The compound name consists of the class name, two dots, and the first value. When Array(string) is imported the generic class is referenced as "Array..string". The first value is either a valid compound symbolic name or a decimal integer. Note that Gilda names are not case sensitive.


Generic arguments and default values may be a symbol or a simple decimal integer without any underscores, leading zeros, or sign. When a Generic class is Imported without a parameter then the default specified on the Class declaration is used. Often symbolic macro values represent type names, but that is not a requirement.

In the second form of a Generic Class declaration, no parameter is designated. This creates a single class with the compound name "Class..value". No macro substitution occurs within the Class or its methods. The purpose of this is to create unique names for a Class and any generic procedures within it. This is particularly useful to avoid name conflicts. Generic proceduress can be called using a shorthand notation when the type of the first argument extends the procedure name in the call.


Withing a program the As clause on an Import declaration can be helpful. It denotes an alias name for the imported class. The alias can be simpler than the full class name and more meaningful within the context of the program.


The Import As clause can also disambiguates generic classes with multiple parameters. Only the first parameter is user as the full class name. In the following example both full class names would be "Stack..string" and would collide. Using the aliases resolves the name conflict.


Class Preamble

Virtual Generic Class