Next: , Previous: , Up: scheme overview   [Index]


3.1.4 Expressions

The most important elements of Scheme code are expressions. Expressions can be evaluated, producing a value. (Actually, any number of values. Multiple return values.)

The most fundamental expressions are literal expressions:

#t ⇒ #t
23 ⇒ 23

this notation means that the expression ‘#t’ evaluates to #t, that is, the value for “true”, and that the expression ‘23’ evaluates to a number object representing the number 23.

Compound expressions are formed by placing parentheses around their subexpressions. The first subexpression identifies an operation; the remaining subexpressions are operands to the operation:

(+ 23 42)               ⇒ 65
(+ 14 (* 23 42))        ⇒ 980

in the first of these examples, + is the name of the built–in operation for addition, and ‘23’ and ‘42’ are the operands. The expression (+ 23 42) reads as “the sum of 23 and 42”. Compound expressions can be nested—the second example reads as “the sum of 14 and the product of 23 and 42”.

As these examples indicate, compound expressions in Scheme are always written using the same prefix notation. As a consequence, the parentheses are needed to indicate structure. Consequently, “superfluous” parentheses, which are often permissible in mathematical notation and also in many programming languages, are not allowed in Scheme.

As in many other languages, whitespace (including line endings) is not significant when it separates subexpressions of an expression, and can be used to indicate structure.