Table of contents:
CLC-INTERCAL introduces an unique infrastructure over the registers. We shall explain it with an example.
Imagine building a tree structure in other languages. You have a root, and there are pointers from the root to other nodes, which in turn have pointers to other nodes, until you get to the leaves.
This all sounds simple, but it has several drawbacks. The most important, is that each node can have an arbitrary number of children, so you need to start using messy techniques like variable-length lists. Also, if the nodes need to contain values as well as pointers, you need to remember reserving the extra space.
CLC-INTERCAL does not suffer from these problems. By simply reversing the pointers, you can easily see that any leaf or node has exactly one parent. We call this a BELONGS TO relation. Because the relation is an infrastructure built on top of the registers, you can still use them for something else: a popular choice of "something else" is to store values in them.
As an example, consider the following binary tree in LISP notation: ((1, (2, 3)), (4, ((5, 6), 7))). It looks awfully complicated for a seven leaves data structure. To write that in CLC-INTERCAL one could do:
PLEASE DO .1 <- #1 DO MAKE .1 BELONG TO .3 DO .2 <- #2 DO MAKE .2 BELONG TO .4 PLEASE .5 <- #3 DO MAKE .5 BELONG TO .4 DO MAKE .4 BELONG TO .3 DO MAKE .3 BELONG TO .6 PLEASE .7 <- #4 DO MAKE .7 BELONG TO .8 DO .9 <- #5 DO MAKE .9 BELONG TO .10 PLEASE .11 <- #6 DO MAKE .11 BELONG TO .10 DO MAKE .10 BELONG TO .12 DO .13 <- #7 PLEASE MAKE .13 BELONG TO .12 DO MAKE .12 BELONG TO .8 DO MAKE .8 BELONG TO .6
The root of the tree is .6
. Its two subtrees are .3
and .8
. Down the left subtree, we note that both .1
and .4
BELONG TO it. And so on, just as simple as the rest of
INTERCAL.
Since we have removed the need to use variable-length lists to represent trees, we can reintroduce them to represent more complicated data structures. This means that a register can be made to belong to more than one other register.
If you know that a register belongs to another one you can get the name of
the latter by prefixing the former with a big-money symbol ($
).
If a register happens to BELONG TO more than one register, the big-money
symbol is the one it was most recently made to belong to. The previous one
is accessed with the prefix 2 (two), and the one before it with the prefix 3
(three). Therefore up to nine different registers can be accessed that way,
if it belongs to that many. For example, after:
PLEASE .1 <- #2 DO .2 <- #5 DO .3 <- #8 DO MAKE .3 BELONG TO .2 DO MAKE .3 BELONG TO .1 DO MAKE .3 BELONG TO .3The register
$.3
would be itself, while 2.3
would
be .1
and 3.3
would be .2
.
The prefix can be repeated as necesary: if a register .1 belongs to .2 which
in turn belongs to .3, then $$.1 is .3 etcetera. There is no limit. If prefixes
are repeated, they are executed from left to right.
Thus, in the above example, $$2.3
would be the same as
2.3
aka .1
(because $.3
is the same
as .3
). On the other hand, 2$$.3
is an error,
because 2.3
is .1
, which does not belong to
anything. Note that this order of evaluation of prefixes differs from the
way other languages do that.
If you were wondering why CLC-INTERCAL has registers which cannot hold any
value (whirlpool, @
), here's is why. They can be made to belong
and in turn oteher registers can be made to belong to them. So you can use
them as indirect references to other registers. In fact, this is what the
lecture system does. See the chapter on Classes
and Lectures.
This documentation occasionally refers to a register as a "group" if another register BELONGs TO it.
One more note. When a register is STASHed, any information about which groups it belongs to is saved in the STASH. When it is retrieved, the belonging information comes back from the STASH. Also, if you MAKE a register BELONG while it's ignored, nothing happens, and similarly when you MAKE it NO LONGER BELONG.
If you think to use this mechanism as pointers, you'll find out that you very quickly run into problems. We won't tell you how, as it would spoil the fun.