A useful boundary hides a method without hiding its contract.
Give callers one stable procedure while local helpers and alternative decompositions remain implementation details behind that boundary.
What may change inside a procedure without forcing every caller to change with it?
- Separate a public procedure contract from its local helper names
- Recognize block structure as a way to keep helper bindings private
- Observe that a local name can shadow an unrelated outer name safely
- Compare two internal decompositions through the same finite inputs
- Compare matching examples at their displayed inputs
sum-squares-two-largest exposes only three inputs and one numeric result. square and the local choose procedure belong to its implementation. The global binding named choose remains global-marker because the local helper exists only while the public procedure body is evaluated. A caller does not need the selected pair or either helper name.
The second program computes the same sample result by two different decompositions: select the two largest values directly, or subtract the square of the smallest value from the sum of all three squares. The public question is unchanged even though the internal work differs. Agreement confirms the shared result for the displayed finite input.
- Output
- —
- Value
- —
- Diagnostic
- —
The first program returns (13 61 global-marker). The second returns (61 61 #t).
Enter sum-squares-two-largest and identify the local square and choose bindings without confusing them with the global choose. In the comparison program, contrast the selected cond branch with the path that sums three squares and subtracts one, while keeping the final client observation separate from those internal steps.
Change the program and compare the result.
Replace the body of sum-squares-two-largest with the subtraction method while keeping its name, parameters, and returned result unchanged. Run several inputs and record which caller code did not need editing.
Show hint
The abstraction boundary is the public procedure signature and result contract; helper names and decomposition may remain local.