Next: Multithreading and Backtracking, Previous: System Libraries, Up: Top [Index]
INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
no | version 0.7+ | version 1.-94.-8+ | no |
One extension to INTERCAL that is implemented by both C-INTERCAL and CLC-INTERCAL is known as TriINTERCAL, and extends INTERCAL to bases other than binary. Unlike ordinary INTERCAL programs, which have the extension ‘.i’, TriINTERCAL programs in bases from 3 to 7 (the only allowed bases) have extensions from ‘.3i’ to ‘.7i’ respectively.
The change of numeric base only affects expressions, and in particular the behaviour of operators, and the range of variables. (The onespot and twospot ranges become the highest number of trits or other digits in the base required that fit inside the binary ranges, so for instance, the maximum value of a onespot variable in ternary is 59048, or 3 to the power 10 minus 1.) Interleave/mingle is the simplest to explain; it alternates digits just as it alternated bits in binary. The other operators all change, as follows:
?
and ^
). (In Princeton
syntax, these are the bookworm or yen sign, and a spike
(|
).) The two operators do the same thing in binary, but
differ in higher bases. (Nevertheless, it is an error to use a sharkfin
in binary, because it is a so-called ‘controlled unary
operator’, as are the rest of the new operators defined in this
section, which has a lower limit on which base it is allowed in.)
Instead of doing the exclusive-or operation, the bits being combined
are either subtracted or added; if the result is out of range for the
base being used, the base is added or subtracted from the result until
it is in range. (For the subtraction, the bit that was less significant
is subtracted from the bit that was more significant in any given pair
of bits, except for the subtraction between the most and least
significant bits, where the most significant bit is subtracted from the
least.)
The way to think of it is this: in base 2, an AND gives the result
0 if either argument is a 0, and otherwise a 1, and likewise, an OR
gives the result 1 if either argument is a 1, and otherwise a 0;
they could be said to favour 0 over 1 and 1 over 0 respectively. In
base 3, AND favours 0 over 2 over 1, OR favours 2 over 1 over 0,
and BUT favours 1 over 0 over 2. (The symbol for BUT is
@
(a ‘whirlpool’, which is another name
for the BUT operation) in Atari syntax, and ?
in
Princeton syntax.) The pattern continues: in base 4, AND favours 0
over 3 over 2 over 1, BUT favours 1 over 0 over 3 over 2, 2BUT
(written 2@
or 2?
) favours 2 over 1 over
0 over 3, and OR favours 3 over 2 over 1 over 0. (This can be
extended to higher bases following the same pattern, introducing
operators 3@
or 3?
, etc., to favour 3,
etc., when neither AND (which always favours 0) nor OR (which
favours the highest digit in the base) are available.) All the
whirlpool operators are controlled unary operators, which are only
legal when both the base contains the favoured digit, and they
aren’t redundant to AND nor OR.
Note that the base doesn’t affect anything other than variable ranges and expressions; in particular, it doesn’t affect the bit-reversal used by Turing Tape I/O. (The tape still has characters written on it in binary, even though the program uses a different base.)
Next: Multithreading and Backtracking, Previous: System Libraries, Up: Top [Index]