Previous: Execution Chance, Up: Syntax [Index]
| INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
|---|---|---|---|
| no | version 0.25+ | no | no |
The last part of a statement is an optional ONCE or
AGAIN. ONCE specifies that the statement is
self-abstaining or self-reinstating (this will be explained below);
AGAIN specifies that the statement should behave like it
has already self-reinstated or self-abstained. Whether the behaviour is
self-abstention or self-reinstatement depends on whether the statement
was initially abstained or not; a ONCE on an initially
reinstated statement or AGAIN on an initially abstained
statement indicates a self-abstention, and a ONCE on an
initially abstained statement or AGAIN on an initially
reinstated statement indicates a self-reinstatement.
The first time a self-abstaining statement is encountered, it is
executed as normal, but the statement is then abstained from and
therefore will not run in future. Likewise, the first time a
self-reinstating statement is encountered, it is not executed (as is
normal for an abstained statement), but then becomes reinstated and
will run in future. In each of these cases, the ONCE
effectively changes to an AGAIN; the ONCE
only happens once, as might be expected.
REINSTATING a currently abstained self-abstaining
statement or ABSTAINING (that is, with the
ABSTAIN or REINSTATE commands) a currently
reinstated self-reinstating statement causes the AGAIN on
the statement to change back into a ONCE, so the statement
will again self-abstain or self-reinstate. Likewise,
REINSTATING a currently abstained self-reinstating
statement or ABSTAINING a currently reinstated
self-abstaining statement causes its ONCE to turn into an
AGAIN.
Historical note: ONCE was devised by Malcom Ryan as a
method of allowing synchronisation between threads in a multithreaded
program (ONCE is atomic with the statement it modifies,
that is, there is no chance that threads will change between the
statement and the ONCE). AGAIN was added to
Malcom Ryan’s Threaded Intercal standard on the suggestion of
Kyle Dean, as a method of adding extra flexibility (and to allow the
ONCEs to happen multiple times, which is needed to
implement some multithreaded algorithms).
Previous: Execution Chance, Up: Syntax [Index]