Basic Concepts

Go to the first, previous, next, last section, table of contents.

Basic concepts

Variables and regions

Any identifier that is not a syntactic keyword (see section Identifiers) may be used as a variable. A variable may name a location where a value can be stored. A variable that does so is said to be bound to the location. The set of all visible bindings in effect at some point in a program is known as the environment in effect at that point. The value stored in the location to which a variable is bound is called the variable's value. By abuse of terminology, the variable is sometimes said to name the value or to be bound to the value. This is not quite accurate, but confusion rarely results from this practice.

Certain expression types are used to create new locations and to bind variables to those locations. The most fundamental of these binding constructs is the lambda expression, because all other binding constructs can be explained in terms of lambda expressions. The other binding constructs are let, let*, letrec, and do expressions (see section Lambda expressions, section Binding constructs, and section Iteration).

Like Algol and Pascal, and unlike most other dialects of Lisp except for Common Lisp, Scheme is a statically scoped language with block structure. To each place where a variable is bound in a program there corresponds a region of the program text within which the binding is effective. The region is determined by the particular binding construct that establishes the binding; if the binding is established by a lambda expression, for example, then its region is the entire lambda expression. Every reference to or assignment of a variable refers to the binding of the variable that established the innermost of the regions containing the use. If there is no binding of the variable whose region contains the use, then the use refers to the binding for the variable in the top level environment, if any (section section Standard procedures); if there is no binding for the identifier, it is said to be unbound.

True and false

Any Scheme value can be used as a boolean value for the purpose of a conditional test. As explained in section Booleans, all values count as true in such a test except for #f. This report uses the word "true" to refer to any Scheme value that counts as true, and the word "false" to refer to #f.

Note: In some implementations the empty list also counts as false instead of true.

External representations

An important concept in Scheme (and Lisp) is that of the external representation of an object as a sequence of characters. For example, an external representation of the integer 28 is the sequence of characters "28", and an external representation of a list consisting of the integers 8 and 13 is the sequence of characters "(8 13)".

The external representation of an object is not necessarily unique. The integer 28 also has representations "#e28.000" and "#x1c", and the list in the previous paragraph also has the representations "( 08 13 )" and "(8 . (13 . ()))" (see section Pairs and lists).

Many objects have standard external representations, but some, such as procedures, do not have standard representations (although particular implementations may define representations for them).

An external representation may be written in a program to obtain the corresponding object (see quote, section Literal expressions).

External representations can also be used for input and output. The procedure read (section Input) parses external representations, and the procedure Output (section Output) generates them. Together, they provide an elegant and powerful input/output facility.

Note that the sequence of characters "(+ 2 6)" is not an external representation of the integer 8, even though it is an expression evaluating to the integer 8; rather, it is an external representation of a three-element list, the elements of which are the symbol + and the integers 2 and 6. Scheme's syntax has the property that any sequence of characters that is an expression is also the external representation of some object. This can lead to confusion, since it may not be obvious out of context whether a given sequence of characters is intended to denote data or program, but it is also a source of power, since it facilitates writing programs such as interpreters and compilers that treat programs as data (or vice versa).

The syntax of external representations of various kinds of objects accompanies the description of the primitives for manipulating the objects in the appropriate sections of section Standard procedures.

Disjointness of types

No object satisfies more than one of the following predicates:

boolean?          pair?
symbol?           number?
char?             string?
vector?           procedure?

Inlab Scheme extends this by adding IP addresses, IP address ranges, MAC addresses and MAC address ranges as intrinsic data types and the matching predicates ipaddr?, ipaddr-range?, macaddr? and macaddr-range?.

These predicates define the types boolean, pair, symbol, number, char (or character), string, vector, and procedure.

Storage model

Variables and objects such as pairs, vectors, and strings implicitly denote locations or sequences of locations. A string, for example, denotes as many locations as there are characters in the string. (These locations need not correspond to a full machine word.) A new value may be stored into one of these locations using the string-set! procedure, but the string continues to denote the same locations as before.

An object fetched from a location, by a variable reference or by a procedure such as car, vector-ref, or string-ref, is equivalent in the sense of eqv? (section section Equivalence predicates) to the object last stored in the location before the fetch.

Every location is marked to show whether it is in use. No variable or object ever refers to a location that is not in use. Whenever this report speaks of storage being allocated for a variable or object, what is meant is that an appropriate number of locations are chosen from the set of locations that are not in use, and the chosen locations are marked to indicate that they are now in use before the variable or object is made to denote them.

In many systems it is desirable for constants (i.e. the values of literal expressions) to reside in read-only-memory. To express this, it is convenient to imagine that every object that denotes locations is associated with a flag telling whether that object is mutable or immutable. The constants and the strings returned by symbol->string are then the immutable objects, while all objects created by the other procedures listed in this report are mutable. It is an error to attempt to store a new value into a location that is denoted by an immutable object.


Go to the first, previous, next, last section, table of contents.