Next: , Previous: , Up: Welcome to Lisp   [Contents][Index]

16.4.2 Evaluation

In this section we take a closer look at how expressions are evaluated.

Evaluation Rule

When Lisp evaluates a function call, it does so in two steps:

  1. First the arguments are evaluated from left to right.
  2. The values of arguments are passed to the fucntion named by the operator.

If any of the arguments are themselves function calls, they are evaluated according to the same rules.

Not all the operators in Common Lisp are functions, but most are. And function calls are always evaluated this way. The arguments are evaluated left-to-right, and their values are passed to the function, which returns the value of the expression as a whole. This is called the evaluation rule for Common Lisp.

Special Operators

One operator that does not follow the Common Lisp evaluation rule is quote. The quote operator is a special operator, meaning that it has a distinct evaluation rule of its own. And the rule is: do nothing. The quote operator takes a single argument and just returns it verbatim.

> (quote (+ 3 5)
(+ 3 5)

Common Lisp defines ‘'’ as an abbreviation for quote. You can get the effect of calling quote by affixing a ‘'’ to the front of any expression:

> '(+ 3 5)
(+ 3 5)

Lisp provides the quote as a way of protecting expressions from evaluation.