[Next] [Up] [Previous]

The MUTABLE Statement

The MUTABLE statement

The statement

       MUTABLE X,Y,Z

causes X,Y, and Z to have the type MUTABLE. Initializing MUTABLE variables is not recommended, as it wastes memory, unlike the initialization of ordinary variables.

Variables belonging to the type MUTABLE behave like variables do in the computer language APL. That is, a MUTABLE variable can be assigned a value of any type at any time. At one point in a program, it can be a character string, and at another point a 10 by 10 array of floating-point numbers.

The function _MQ(variable) generates the 'mutable equivalent' of its argument. Normally, this has no effect: but when the mutable equivalent of a non-mutable variable is assigned to a mutable variable, the result is like an execution-time EQUIVALENCE: until the mutable variable is assigned a new value, its value changes whenever that of the non-mutable variable does, as both values are found at the same storage location.

Thus, the statement

       . MVAR=_MQ(I)

would be equivalent to the statements

       . _EFAD(MVAR)=_ADR(I)
       . _CTYP(MVAR)=_TYPE(I)
       . _DIM(MVAR)=&DIM I

which, incidentally, perform assignments of type ADDRESS, TVAL, and INTEGER (or MUTABLE, as a variable-length array of integers is being assigned).

The TYPE of a MUTABLE variable is MUTABLE, thus it is the CTYP (contents current type) that is the left-hand function in the second statement; in the first statement, it is the effective address of the MUTABLE variable, that is, the address of the data it contains, that is to be changed: that of the type and pointer part of the variable, likely to be indicated by _ADR in most implementations, is not what we are interested in, so EFAD (effective address) is used.

When a MUTABLE variable has an array for its value, assignment to an element of that array is permitted, and will result in type conversion of the value assigned rather than a change in the type of the MUTABLE variable.

Multiple variables, dimensioning, and initial values can all be used in the MUTABLE statement as in other type-declaration statements.

As any mutable variable can be an array, to refer to an element of the current value of an element of a MUTABLE array, the notation M(5)(3,4) would be used to refer to element (3,4) of the array currently in the fifth element of the array of mutable variables M. When a MUTABLE variable has a value of array of MUTABLE, it behaves somewhat like a list in the computer language LISP (or a variable in APL2 rather than regular APL).

Also note that in FALCON, unlike APL, a MUTABLE variable 'containing' an array of real numbers may have them in single, double, or quadruple precision form; FALCON assumes precision is maintained by following, at execution time, the same rules for type conversion as are applied at compile time using the order, implementation, and length priorities of each type.

[Next] [Up] [Previous]