Unit content
Evaluation contexts
Operational semantics can become repetitive if every expression form needs separate rules saying where the next step may occur. An evaluation context factors out that control information.
A context $E[;]$ is an expression with one hole. For call-by-value arithmetic, contexts might include
$$E ::= [;] \mid E+e \mid v+E.$$
The first form is the hole itself. The second says evaluation may occur in the left side of an addition; the third allows the right side only after the left has become a value.
A general congruence rule can then say
$$\frac{e\to e'}{E[e]\to E[e']}.$$
Only the truly computational redex rules need to be stated separately. For example,
$$n_1+n_2\to n_3$$
performs arithmetic, while contexts determine where such a redex may be reduced.
Evaluation contexts make evaluation order explicit while avoiding a large family of nearly identical rules. They scale particularly well to function calls, exceptions, mutable state and control operators, and they expose a useful decomposition of a program into “the next reducible operation” plus “the surrounding continuation of the computation.”