micro-PROLOG variable names consist of a prefix character followed by an optional subscript number. Here are the details:
prefix character : X | Y | Z | x | y | z
subscript number : 0..127
The string of digits that form the subscript is interpreted as a number and internally stored as such against a variable prefix. This is not the prefix given by yourself. Rather, prefixes are dished out in the order
X, Y, Z, x, y, z
Read variable names like so:
Y3 => Y3
x14 => x14
z027 => z27 => z27
X => X0 => X0
Y312 => Y56 => Y56
Note how 027 is equivalent to 27. Further notice that a variable prefix on its own implies subscript 0. The last line illustrates another peculiarity. Subscripts are in the range 0..127. The variable name Y312 will internally be represented as Y56.
Since values are stored against a prefix and its subscript, the variable name that was used when the variable has been defined is lost and cannot be restored. Prefix and subscript depend on the position of the variable in a clause. Confused?
Let’s try this. Gives us a chance to interact with the system. First we enter a program:
&.((Reverse y26 X40) 1. (Reverse y026 () X40)) &.(Reverse (x0|Y2) x2 z0) 1. (Reverse Y2 (x|x2) z0)) &.(Reverse () z z) &.
The variable names are a bit silly, but this is for demonstration purposes. Now let’s run the program.
&.?((Reverse (1 2 3 4 5 6) x8) (P x8)) (6 5 4 3 2 1) &.
It works. Time to list the Reverse program:
&.LIST (Reverse) &.((Reverse X Y) 1. (Reverse X () Y)) &.(Reverse (X|Y) Z x) 1. (Reverse Y (X|Z) x)) &.(Reverse () X X) &.
If this is what you have expected then give yourself a pat on the shoulder.
What’s this about? The reason for this strange naming convention is simply the fact that the tokeniser has to make a distinction between variable names and constants. If it is not a variable name it is a constant.
These are not variable names:
Stuck with it? No, not at all. The syntax rules were provided in an editable file and could thus be changed. For example, the prefix characters could be changed from
X | Y | Z | x | y | z
a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z
making all tokens starting with a lowercase letter followed by a number a variable name, and the rest a constant.