5.1.4 Generic Class Declaration


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

To import a Generic Class list Generic arguments to substitute into the Class for each Generic parameter. Then wherever source code contains a parameter name it will be substituted with the argument value for that parameter.


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


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

The second form of a Generic Class does not designate any parameter name. 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 procedures can be called using a shorthand notation so that 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 used 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.


Record Type Declaration

Import Class Declaration