sicp.io
5.1.2 · Abstraction in machine design

Keep the controller stable while operations and storage change.

A controller can depend on named operation contracts rather than one arithmetic method, and on a register-bank protocol rather than one storage form.

Guiding question

Which boundaries let a machine design change locally instead of rewriting its controller?

  • Separate controller structure from the operation package it invokes
  • Run one controller with Euclidean and subtraction-based reduction packages
  • Compare process cost without changing the controller text
  • Hide register storage behind read and write messages
  • Compare one abstraction boundary across two measured implementations

The reduction controller knows only done?, next-a, next-b, and answer. The Euclidean package maps those names to remainder reduction; the subtraction package maps them to repeated difference reduction. Both machines use the identical assembled instruction sequence and return the same greatest common divisor, but their instruction counts expose different processes.

The second program gives the same counter controller two register banks. One bank stores mutable association records and the other stores values in a vector behind a name-to-index table. The controller sends read and write messages only. Equal observations show that the finite client contract survives the storage change.

SICP code7,465 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 operation-package program returns ((euclid complete 2 32) (subtraction complete 2 95) #t). The register-bank program returns ((4 10) (4 10) #t).

    Trace focus

    In the first run, confirm that both machines fetch the same instruction tags while operation lookup selects different procedures. Compare four Euclidean reduction cycles with thirteen subtraction cycles. In the second run, follow the same read/write call sequence into different hidden storage operations.

    Try it yourself

    Change the program and compare the result.

    Add a binary-GCD operation package or a third register-bank representation. Keep the controller text unchanged and state which operation or storage contracts your replacement must satisfy.

    Show hint

    A valid operation package must make each nonterminal transition progress toward its own done? predicate. A valid bank must preserve the read-after-write observations used by the controller.

    Complete this lesson

    0 of 23 lessons complete in this chapter0%