sicp.io
1.1.7 · Procedures as black-box abstractions

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.

Guiding question

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.

SICP code459 of 1,048,576 UTF-8 bytes
Examples
Result
Output
Value
Diagnostic
Execution trace0 / 0 events
    Programs run in the browser with their result and execution trace.
    Expected result

    The first program returns (13 61 global-marker). The second returns (61 61 #t).

    Trace focus

    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.

    Try it yourself

    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.

    Complete this lesson

    0 of 18 lessons complete in this chapter0%