(Lispex)sicp.io
1.2 · Naming a method

A procedure gives a process a name.

Build a useful operation from smaller ones and watch names become parameters when the procedure is applied.

Guiding question

How does a procedure definition turn an expression into a reusable method?

  • Read a procedure definition as parameters plus a body
  • Follow one compound procedure application
  • Distinguish a name from the value bound to it

square names a one-parameter procedure. sum-of-squares then combines two applications of square. The definition records a method. Nothing in its body runs until the procedure is applied.

On application, each parameter is bound to an argument value in a new environment. The body is evaluated with those bindings, producing 25 for inputs 3 and 4.

Lispex · SICP sourceScheme-compatible SICP syntax executed by the Lispex SICP profile.
(begin
  (define (square x) (* x x))
  (define (sum-of-squares x y)
    (+ (square x) (square y)))
  (sum-of-squares 3 4))
Lispex learning runtimeLispex SICP profile 1.0.0
Loading Lispex SICP runtime
Lispex · SICP source122 / 1,048,576 UTF-8 bytes
Examples
Result
Output
Value
Diagnostic
Visible execution0 / 0 trace events
    This browser result is not a Lispex Vouch record or authority.wasm —
    Expected observation

    The first program returns 25 and produces no output.

    Trace focus

    Find the two square applications. They use different x bindings even though both calls evaluate the same procedure body.

    Try it yourself

    Change the program before you read the hint.

    Define sum-of-cubes using a cube procedure, then evaluate it for 2 and 3.

    Show one hint

    Keep the combining procedure independent from the details of cubing one value.