INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
yes | all versions | all versions | all versions |
Mingle, or interleave, is one of the two binary operators in INTERCAL-72. However, different INTERCAL compilers represent it in different ways, so it is impossible to write a mingle in a program completely portably, because it differs between Princeton and Atari syntax, and worse, the sequence of character codes needed to represent it in each syntax has varied from compiler to compiler.
The original INTERCAL-72 compiler (the Princeton compiler)
used the ’change’ (cent) character for a mingle,
represented as c
, backspace, /
. (By the way,
this is still the most portable way to write a mingle; both
C-INTERCAL and CLC-INTERCAL accept it, at
least if a lowercase c
is used, the Atari compiler was to
accept it, and its documentation claimed that the Princeton compiler
also accepted it; CLC-INTERCAL also accepts a capital
C
before the backspace and /
, and allows
|
rather than /
.) The uncompleted Atari
compiler intended to use a ’big money’ character
($
) as the mingle character; this character is also the
only one accepted for mingle by the J-INTERCAL compiler.
C-INTERCAL originally also used the $
character for mingle, and this character is the one most commonly seen
in existing C-INTERCAL programs, and most often used when
giving examples of INTERCAL on Usenet, because it
exists in the ASCII-7 character set, and because it doesn’t
contain control characters. From version 0.18 of
C-INTERCAL onwards, various other units of currency
(change, quid, and zlotnik if Latin-1 is used as the input, and euro if
Latin-9 is used as the input) are accepted; from version 0.20 onwards,
in addition to the Latin-1 characters, all the currency symbols in
Unicode are accepted if UTF-8 is used as the input format.
CLC-INTERCAL has always used the change character (either
the Latin-1 version or the version that contains a backspace) for
mingle. In this manual, mingle will be represented as $
,
but it’s important to bear in mind that this character is not the
most portable choice.
The mingle operator should be applied to two operands or expressions. To be portable, the operands must both be onespot expressions, that is expressions which have a 16-bit result; C-INTERCAL relaxes this rule slightly and only requires that the result be in the onespot range. (This is because the data type of a select operator’s value is meant to be determined at runtime; C-INTERCAL determines all data types at compile time, so has to guess a 32-bit result for a select with a 32-bit type as its right operand even when the result might actually turn out to be of a 16-bit type, and so this behaviour prevents an error when a select operation returns a value with a 16-bit data type and is used as an argument to a mingle.) The result is a 32-bit value (that is, it is of a 32-bit data type, even if its value fits into the onespot range), which consists of bits alternated from the two arguments; to be precise, its most significant bit is the most significant bit of its first argument, its second most significant bit is the most significant bit of its second argument, its third most significant bit is the second most significant bit of its first argument, and so on until its least significant bit, which is the least significant bit of its second argument.
One of the most common uses of interleaving is to create a constant
with a value greater than 65535; for instance, 65536 is
#0$#256
. It is also commonly used in expressions that need
to produce 32-bit results; except in some simple cases, this is usually
coded by calculating separately the odd-numbered and even-numbered bits
of the result, and mingling them together at the end. It is also used
in expressions that need to left-shift values or perform similar
value-increasing operations, as none of the other operators can easily
do this; and mingle results are commonly used as the argument to unary
binary logic operators, because this causes them to behave more like
the binary logic operators found in some other languages.