Next: NEXT FORGET and RESUME, Previous: Syntax Error, Up: Statements [Index]
INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
yes | all versions | all versions | all versions |
At present, the only INTERCAL command that contains
no keywords (apart from the statement identifier and possibly
ONCE
or AGAIN
) is what is known as the
‘calculate’ command. It is used to assign values to
variables, array elements, and arrays; assigning a value to an array
changes the number of elements that that array can hold, and causes the
values of all elements previously in that array to be lost. The syntax
of a calculate command is as follows:
DO .1 <- ':2~:3'~#55
That is, the command is written as a variable or array element, then
the <-
operator (known as an ‘angle-worm’
and pronounced ‘gets’), then an expression to assign to it.
In the special case when an array is being dimensioned by assigning a
value to it, the expression can contain the keyword BY
to
cause the array to become multidimensional; so for a 3 by 4 by 5 array,
it would be possible to write
DO ,1 <- #3 BY #4 BY #5
The calculate command always evaluates the expression, even if for some reason the assignment can’t be done (for instance, if the variable being assigned to is read-only); this is important if the expression has side-effects (for instance, giving an overflow error). If the variable does happen to be read-only, there is not an error; the expression being assigned to it is just evaluated, with the resulting value being discarded.
The gerund to refer to calculations is CALCULATING
;
however, if you are planning to use this, note that a bug in older
versions of C-INTERCAL means that assignments to arrays
are not affected by this gerund before version 0.27.
CLC-INTERCAL from 1.-94.-4 onwards, and
C-INTERCAL from 0.26 onwards, allow arbitrary expressions
on the left hand side of an assignment (C-INTERCAL only if
the -v
option is used); for more information on how such
‘reverse assignments’ work, see Operand Overloading.
Next: NEXT FORGET and RESUME, Previous: Syntax Error, Up: Statements [Index]