Reading the Parentheses

The parentheses are one rule applied everywhere, and once you see the rule the syntax stops being an obstacle.

Result: find the leading form in a parenthesized expression, separate it from the pieces that follow, and recognize whether the expression is an ordinary call or a special form.

What you need to know: nothing. This page is for a reader who has never written a program, and for a reader who has written many but bounced off the parentheses.

One main shape, reused everywhere

Most languages have a large syntax. There are function calls, operators with precedence, statements, blocks, and each has its own shape to memorize.

This language reuses one main shape.

LISPEX
(operation input1 input2 ...)

In an ordinary call, the first item inside a pair of parentheses says what procedure to call. Everything after it supplies the arguments. This reading rule covers most of the expressions you meet first.

LISPEX
(+ 2 3)

Read it aloud as add two and three. It produces 5. The plus sign is not a special operator sitting between two numbers. It is the first item, the procedure being called.

A small set of forms, including define, if, quote, and lambda, uses the same parenthesized shape but controls evaluation instead of calling a procedure. For these special forms, the first item names the form and the remaining pieces are the syntax it controls.

Nesting is the same rule inside itself

An inner expression is evaluated first, and its value takes its place.

LISPEX
(+ 10 (* 2 3))

Read from the inside out. Multiply two and three, giving six. Then add ten and six, giving sixteen.

This is why the parentheses look heavy at first and become light later. There is no precedence to remember, no question of whether multiplication happens before addition. The shape of the parentheses already says the order, unambiguously, every time.

What you can now read

Look at this and, without knowing what any of these names do, say what is being applied to what.

LISPEX
(define (price-with-fee price fee)
  (+ price fee))

The outer form is define, a special form rather than a procedure call. Its first piece is (price-with-fee price fee), the name being defined together with the names it expects. Its second piece is the body. The body (+ price fee) is an ordinary call, so it adds those two values.

You just separated a definition into its meaningful pieces before learning every detail of define. That is the payoff of a small, repeated shape.

Try this

Read this expression and predict the value before running it.

LISPEX
(+ 1 (* 2 (+ 3 4)))
Show answer

Fifteen. Innermost first, add three and four giving seven. Then multiply two and seven giving fourteen. Then add one, giving fifteen. Nothing about operator precedence entered the reasoning, because the parentheses said the order.

Ready to move on when

You can look at an unfamiliar expression, point at the first item inside each pair of parentheses, and say what is being applied to what, even when you do not know what the names mean.

Continue to First Program, where you will run this shape before learning its pieces in detail.