Content, this page | Offpage Links | ||
(operator operand operand operand)The number of operands is defined by the operator. Here are just a few examples:
0 operands |
|
|
1 operand |
|
|
2 operands |
|
|
Indefinite number
of operands |
|
|
(display (+ 3 4))The first (innermost) statement adds three and four, and the result is fed to the display operator, so 7 is written on the screen. Here's another example:
(* 5 (+ 3 4))The innermost statement evaluates to 7, and its return value is multipled by 5 to produce 35, although it's not written because there's no display statement. The following is a formula for a hypotinuse, given the lengths of the two sides adjacent to the right angle:
(sqrt (+ (* adj1 adj1) (* adj2 adj2)))There are two innermost statements, each of which squares one of the adjacent sides. The next statement out adds those two squares, and the statement outside of that takes the square root.
(display (* (+ 3 4) (+ 5 6))) | (display | (display |
(sqrt (+ (* adj1 adj1) (* adj2 adj2)))The return values of the multiplication operations depend only on their operands. The only effect of the multiplication operations is the return value. The sum operator takes as arguments the returns of the multiplications, depending only on them, and its only effect is its return, which is used by sqrt. All the way up the chain, every operation's action is defined exclusively by its arguments (operands), and the sole effect of each operation is its return value. If there were a variable elsewhere in the program, that variable could not possibly influence the hypotinuse formula. Therefore the formula doesn't depend on state.