Subsections


Identity declarations

Suppose you want to use the integer whose denotation is

   48930767

in various parts of your program. If you had to write out the denotation each time you wanted to use it, you would find that

It is imperative, particularly with large programs, to make the meaning of the program as clear as possible. Algol 68 provides a special construct which enables you to declare a synonym for a value (in this case, an integer denotation). It is done by means of the construct known as an identity declaration which is used widely in the language. Here is an identity declaration for the integer mentioned at the start of this paragraph:

   INT special integer = 48930767

Now, whenever you want to use the integer, you write

   special integer

in your program.

An identity declaration consists of four parts:

   <mode indicant> <identifier> = <value>

You have already met the <mode indicant>. An identifier is a sequence of one or more characters which starts with a lower-case letter and continues with lower-case letters or digits or underscores. It can be broken-up by spaces, newlines or tab characters. Here are some examples of valid identifiers (they are separated by commas to show you where they end, but the commas are not part of the identifiers):

   i,  algol,  rate 2 pay,  eigen_value_3

The following are wrong:

   2pairs   escape.velocity   XConfigureEvent

The first starts with a digit, the second contains a character which is neither a letter nor a digit nor an underscore, and the third contains capital letters.

An identifier looks like a name, in the ordinary sense of that word, but we do not use the term “name” in this sense because it has a special meaning in Algol 68 which will be explained in Chapter 5. The identifier can abut the mode indicant as in

   INTa = 4

but this is unusual. For clarity in your programs, ensure that a mode indicant followed by an identifier is separated from the latter by a space.

The third part is the equals symbol =. The fourth part (the right-hand side of the equals symbol) requires a value. You will see later that the value can be any piece of program which yields a value of the mode specified by the mode indicant. So far, we have only met integers, and we can only denote positive integers.

There are two ways of declaring identifiers for two integers:

   INT i = 2 ; INT j=3

The semicolon ; is called the go-on symbol because it means “throw away the value yielded by the previous phrase, and go on to the next phrase”. If this statement seems a little odd, just bear with it and all will become clear later. We can abbreviate the declarations as follows:

   INT i=2, j = 3

The comma separates the two declarations, but does not mean that the i is declared first, followed by the j. On the contrary, it is up to the compiler to determine which declaration is elaborated first. They could even be done in parallel on a parallel processing computer. This is known as collateral elaboration, as opposed to sequential elaboration determined by the go-on symbol (the semicolon). We shall be meeting collateral elaboration again in later chapters. Elaboration means, roughly, execution or “working-out”. The compilation system translates your Algol 68 program into machine code. When the machine code is obeyed by the computer, your program is elaborated. The sequence of elaboration is determined by the compiler as well as by the structure of your program. Note that spaces are allowed almost everywhere in an Algol 68 program.

Some values are predefined in what is called the standard prelude. You will be learning more about it in succeeding chapters. One integer which is predefined in Algol 68 has the identifier max int. Can you guess its value?


Exercises

1.5
What is wrong with the following identifiers? Ans[*]
(a)
INT

(b)
int

(c)
thirty-four

(d)
AreaOfSquare

1.6
What is wrong with the following identity declarations? Ans[*]
(a)
INT thirty four > 33

(b)
INT big int = 3 000 000 000

1.7
Write an identity declaration for the largest integer which the Algol 68 compiler can handle. Use the identifier
max int. Ans[*]

Sian Mountbatten 2012-01-19