A critical aspect of a programming language is the means it provides
names to refer to computational objects,
and our first such means are constants.
We say that the name identifies a constant whose
value is the object.
causes the interpreter to associate the value 2 with the
The purpose of the constant declaration is to
create this association,
and not to compute a particular value as for
demands that the special
be the result of evaluating such constant declarations.
Once the name size
has been associated with the number 2, we can
refer to the value 2 by name as in
declaration for size
before the name size can be used
in an expression. In this online book, the statements that need to be
evaluated before a new statement are omitted for brevity.
However, in order to see and play with the
program, you can click on it.
The program, preceeded by all required statements, then
appears in a new browser tab.
Thus, as a result of clicking on
a new tab appears that contains the statement
The interpreter evaluates the components of the sequence in the given order,
and treats the value of the last component as the value of the sequence.
const size = 2;
5 * size;
Here are further examples of the use of const:
const circumference = 2 * pi * radius;
Constant declaration is our language's
simplest means of abstraction, for it allow us to use simple names to
refer to the results of compound operations, such as the
computed above. In general, computational objects may have very
complex structures, and it would be extremely inconvenient to
have to remember and repeat their details each time we want to use
them. Indeed, complex programs are constructed by building, step
by step, computational objects of increasing complexity.
Our interpreter facilitates this step-by-step program construction
because name-object associations can be created incrementally in
It should be clear that the possibility of associating values with
names and later retrieving them means that the interpreter must
maintain some sort of memory that keeps track of the name-object
pairs. This memory is called the
(more precisely the
global environment, since we will see later that a
computation may involve a number of different
1.1.2 Naming and the Environment