Previous Table of Contents Next


11.8.13. Type Operations

ISTYPE is defined as

   ISTYPE  (x: Reference; T: RefType)  : BOOLEAN

ISTYPE(x, T) is TRUE if and only if x is a member of T. T must be an object type or traced reference type, and x must be assignable to T:

NARROW is defined as

   NARROW  (x: Reference; T: RefType)  : T

NARROW(x, T) returns x after checking that x is a member of T. If the check fails, a runtime error occurs. T must be an object type or traced reference type, and x must be assignable to T.

TYPECODE is defined as

   TYPECODE  (T: RefType)       : CARDINAL
             (r: REFANY)        : CARDINAL
             (r: UNTRACED ROOT) : CARDINAL

Every object type or traced reference type (including NULL) has an associated integer code. Different types have different codes. The code for a type is constant for any single execution of a program but may differ for different executions. TYPECODE(T) returns the code for the type T and TYPECODE(r) returns the code for the allocated type of r. It is a static error if T is REFANY or is not an object type or traced reference type.

ORD and VAL operators are defined as

   ORD   (element: Ordinal)           : INTEGER
   VAL   (i: INTEGER; T: OrdinalType) : T

ORD converts an element of an enumeration to the integer that represents its position in the enumeration order. The first value in any enumeration is represented by zero. If the type of element is a subrange of an enumeration T, the result is the position of the element within T, not within the subrange.

VAL is the inverse of ORD; it converts from a numeric position i into the element that occupies that position in an enumeration. If T is a subrange, VAL returns the element with the position i in the original enumeration type, not the subrange. It is a checked runtime error for the value of i to be out of range for T.

If n is an integer, ORD(n) = VAL(n, INTEGER) = n.

NUMBER operator is defined as

   NUMBER   (T: OrdinalType)    : CARDINAL
            (A: FixedArrayType) : CARDINAL
            (a: Array)          : CARDINAL

For an ordinal type T, NUMBER(T) returns the number of elements in T. For a fixed array type A, NUMBER(A) is defined by NUMBER(IndexType(A)). Similarly, for an array a, NUMBER(a) is defined by NUMBER(IndexType(a)). In this case, the expression a will be evaluated only if it denotes an open array.

FIRST and LAST are defined as

   FIRST(T: OrdinalType)     : BaseType(T)
        (T: FloatType)       : T
        (A: FixedArrayType)  : BaseType(IndexType(A))
        (a: Array)           : BaseType(IndexType(a))
   LAST (T: OrdinalType)     : BaseType(T)
        (T: FloatType)       : T
        (A: FixedArrayType)  : BaseType(IndexType(A))
        (a: Array)           : BaseType(IndexType(a))

For a non-empty ordinal type T, FIRST returns the smallest value of T and LAST returns the largest value. If T is the empty enumeration, FIRST(T) and LAST(T) are static errors. If T is any other empty ordinal type, the values returned are implementation dependent, but they satisfy FIRST(T) > LAST(T).

For a floating-point type T, FIRST(T) and LAST(T) are the smallest and largest values of the type, respectively. On IEEE implementations, these are minus and plus infinity.

For a fixed array type A, FIRST(A) is defined by FIRST(IndexType(A)) and LAST(A) by LAST(IndexType(A)). Similarly, for an array a, FIRST(a) and LAST(a) are defined by FIRST(IndexType(a)) and LAST(IndexType(a)). The expression a will be evaluated only if it is an open array. Note that if a is an open array, FIRST(a) and LAST(a) have type INTEGER.

The following operations return size information for variables or types:

   BITSIZE   (x: Any)    : CARDINAL
             (T: Type)   : CARDINAL
   BYTESIZE  (x: Any)    : CARDINAL
             (T: Type)   : CARDINAL
   ADRSIZE   (x: Any)    : CARDINAL
             (T: Type)   : CARDINAL

BITSIZE returns the number of bits, BYTESIZE the number of 8-bit bytes, and ADRSIZE the number of addressable locations. In all cases, x must be a designator and T must not be an open array type. A designator x will be evaluated only if its type is an open array type.

11.8.14. Text Operations

The following is the concatenation of a and b, as defined by Text.Cat:

   infix   & (a,b: TEXT) : TEXT

11.8.15. Constant Expressions

Constant expressions are a subset of the general class of expressions, restricted by the requirement that it be possible to evaluate the expression statically. All operations are legal in constant expressions except for ADR, LOOPHOLE, TYPECODE, NARROW, ISTYPE, SUBARRAY, NEW, and dereferencing (explicit or implicit). The only procedures that can be applied to constant expressions are the functions in the Word interface.

A variable can appear in a constant expression only as an argument to FIRST, LAST, NUMBER, BITSIZE, BYTESIZE, or ADRSIZE, and such a variable must not have an open array type. Literals and top-level procedure constants are legal in constant expressions.


Previous Table of Contents Next