[Next] [Up] [Previous]

The COLLECTION Statement

FALCON possesses two special statements, the COLLECTION statement and the GENERIC statement, to assist in generating multiple versions of the same program for operating on different types of operand. While the effect can be achieved by passing MUTABLE variables, it may be desired to improve efficiency by performing as much type checking as possible at compile time.

For both the COLLECTION and GENERIC statements, differences between types are accommodated by the following @$ conditional-compilation entities:

@$IF type-symbol=type-name
...statements to be included in program text if the condition is true
@$ELSE
...statements to be included in program text if the condition is false
@$ENDIF

which may be nested. Also, @$ORIF acts as a qualified ELSE that does not create an additional depth of nesting (turning an IF into an ORDSEL, in effect).

An @$ENDIF is required for every @$IF.

Other conditions, such as @$IF constant-name=constant-value, are also possible, although less badly needed.

It is hoped that programmers will not be confused by the use of different forms of IF for conditional compilation and conditional execution; it is felt that the most appropriate form of IF was used in each context.

The COLLECTION statement

The collection statement has the form

        COLLECTION type-symbol:type-symbol:type-symbol...;
                  type-name:type-name:type-name...,routine-name,
                  type-name:type-name:type-name...,routine-name,...
                  type-name:type-name:type-name...,routine-name

and causes the FUNCTION or SUBROUTINE following it to be compiled once for each type-name...routine-name entry, with each type-symbol (an identifier) replaced by the corresponding type-name, and having the name routine-name instead of the one given.

Since separate externally-compiled subroutines are being generated, the routine-name parameters cannot be omitted.

Note that unlike the GENERIC subroutine type in Ada, this forces compilation for every set of types given, creating routines that are externally-compiled.


[Next] [Up] [Previous]