Function Call Semantics
You'll learn: How programming languages formally define what happens when you call a function, from binding arguments to managing scope.
The Core Idea
When you write f(x, y), a lot happens behind the scenes. Function call semantics specify the exact rules for:
- Parameter binding — matching arguments to parameters
- Environment extension — creating a new scope with those bindings
- Body evaluation — executing the function's code
- Return — producing a result and restoring the calling context
Think of it like a recipe handoff: the caller packages ingredients (arguments), the function receives them in labeled containers (parameters), works in its own kitchen (local scope), then hands back the finished dish (return value).
Formal Treatment
In operational semantics, we express function calls as judgments. Given a function definition and call:
define f(a, b) = a + b
call: f(3, 5)
The semantic rule captures:
- Binding step: extend environment with
{a ↦ 3, b ↦ 5} - Evaluation step: evaluate body in extended environment
- Result: return computed value (8), discard local bindings
Scope Management
The critical detail: the function body sees its parameters plus any captured environment (closures), but not the caller's local variables. After the call completes, parameter bindings disappear — they're not visible to the caller or subsequent calls.
This isolation prevents "spooky action at a distance" and makes programs predictable.
Key Takeaway: Function call semantics formally define parameter binding (matching args to params), scope extension (creating a local environment), and cleanup (discarding bindings on return) — ensuring functions are isolated, predictable units of computation.