sicp.io
2.3.1 · Quotation and symbolic data

Quotation turns program-shaped text into inspectable data.

Keep symbols and lists unevaluated with quote, then distinguish symbolic identity from recursive structural equality.

Guiding question

How does the evaluator know when (+ x 3) is an application to run and when it is a list to inspect?

  • Read quote syntax as a boundary between evaluation and symbolic data
  • Inspect an expression-shaped list with ordinary selectors
  • Construct a new symbolic list while evaluating selected elements
  • Use eq? for symbol or object identity questions
  • Use equal? for recursive structural comparison

The quoted expression (+ x 3) is a three-element list. Its first element is the symbol + and its second is the symbol x; neither name is looked up while the quoted list is created. By contrast, (list '+ x 3) quotes only the + symbol, evaluates x to 10, and constructs the data list (+ 10 3).

eq? asks whether its operands denote the same symbol or object identity. equal? descends through compound data and compares structure and leaves. The second program therefore distinguishes one shared list from a separate list with the same contents while still recognizing their structural equality.

SICP code245 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 ((+ x 3) + x (+ 10 3) #t #t #f). The second returns (#t #f #t #t #t).

    Trace focus

    Notice that quote produces data without looking up + or x. Follow car and cadr over that list, then compare the construction of (+ 10 3), where x is evaluated. In the identity example, distinguish the alias binding from the separately allocated copy before equal? traverses both lists.

    Try it yourself

    Change the program and compare the result.

    Build the symbolic expression (* (+ x 1) (+ x 1)) without evaluating x, then build a second list where only one x position is replaced by the current numeric value. Compare the two structures with equal?.

    Show hint

    Quote the whole first expression. For the second, combine quoted operator symbols with list construction around the one element you intend to evaluate.

    Complete this lesson

    0 of 20 lessons complete in this chapter0%