Expressions
Abelson & Sussman · 1996 · SICP §1.1
Programs are expressions. Evaluation = substitution. The environment maps names to values. Every compound expression is a tree of operator and operands, evaluated inside-out.
Primitive expressions
The simplest expressions are self-evaluating: numbers evaluate to themselves, strings evaluate to themselves. The interpreter reads, evaluates, and prints. That loop is the whole interface.
Combinations — prefix notation
A combination is a list where the first element is the operator and the rest are operands. Parentheses make the structure explicit. There is no precedence to memorize — nesting is the only grouping mechanism.
Naming — define
define binds a name to a value in the environment. Once bound, the name can stand in for the value anywhere. This is the simplest form of abstraction: giving things names so we don't have to remember their values.
Conditional expressions — cond and if
cond tests clauses in order and returns the value of the first true one. if is the two-branch special case. Both are special forms: they don't evaluate all their arguments.
The substitution model
To evaluate a combination: evaluate the subexpressions, then apply the operator to the operand values. For compound procedures, substitute the argument values for the formal parameters in the body. This is the substitution model — simple, mechanical, and sufficient until we introduce assignment in Chapter 3.
Notation reference
| Scheme | Python | Meaning |
|---|---|---|
| (+ 1 2) | 1 + 2 | Combination (prefix vs infix) |
| (define x 5) | x = 5 | Bind name to value |
| (define (f x) body) | def f(x): body | Define a procedure |
| (cond (p1 e1) (p2 e2)) | if p1: e1; elif p2: e2 | Conditional |
| (if test then else) | then if test else else | Two-branch conditional |
Neighbors
Other reading pages
- Milewski Ch.1 — composition as the essence of structure
Foundations (Wikipedia)
Translation notes
Scheme uses prefix notation uniformly; Python uses infix for arithmetic and keyword syntax for definitions and conditionals. The substitution model described here is applicative-order (evaluate arguments first). Python also uses applicative order. Normal-order (evaluate arguments only when needed) appears in Chapter 15 (Lazy Evaluation). The cond special form has no direct Python equivalent — the closest is an if/elif chain.