[Next] [Up] [Previous]

# The ORDINAL Statement

(ORD)

The ORDINAL statement has the form

```       ORDINAL series-name;element-1,element-2,element-3,...
```

where all the arguments are identifiers (that is, they have the form of variable names), and does three things:

• it declares element-1 to be a constant with the value 1, element-2 to be a constant with the value 2, and so on, and
• it creates a new type with series-name as its name, to which the element-n constants belong, for which arithmetic is not defined, and for which no implicit conversion to numeric form is available. (The function _ORD(n) converts from any such type to numeric form explicitly.) As a user-defined type, it has the form &"series-name" when used, either as a statement keyword or as a type name within parentheses in, for example, an argument list.
• it creates the function series-name(n) which returns the name of the n-th element of the new type (the n-th element of the new type itself is returned by _(series-name,n), 'of course', although for most user-defined types, conversion is not defined)

If a statement of the form

```       ORDINAL(integer-type) series-name;element-1,element-2,element-3,...
```

is used instead, no new type is created, and the elements have integer type.

If it is desired to specify the integer type used to store an ordinal, but the ordinal is still desired to be of a new, non-arithmetical type, replace (integer-type) by (NEW, integer-type).

It will cause an error to give elements of two different ordinal types the same name.

Note that the names of user-defined types normally occupy a different symbol table during compilation than other identifiers: a user-defined type may have the same name as a variable without causing confusion. Here, since series-name is (possibly) a type name and a function name, it is an entry in both symbol tables when it performs both functions.

[Next] [Up] [Previous]