Evaluation and Quoting

When the interpreter reads a symbol, by default it tries to evaluate it, either as a function name if it is at the beginnning of a list, or otherwise as a variable. For example, given the example above, entering 'one' at the interpreter prompt would return '1'.

   > one
   1
  

While a list starting with 'inc' would be evaluated in this manner, if one were to trace the evaluation:

 
   > (inc one)
    ---> (inc 1)
    ---> (+ one 1)
    ---> (+ 1 1)
   2
  

This evaluation can be overridden using the (quote) special form:

   (quote a)
  

This can (and almost always is) abbreviated using the apostrophe, like so:

   'a
  

Quoting an atom allows you to manipulate the atom itself, rather than its value; the same can be done with an entire list. Given the following definitions:

   (define one 1)

   (define two 2)

   (define (square x) 
           (* x x))
  

Then entering the following at the interpreter prompt will have the results:

   > (list one two (square two))
   (1 2 4)
  

but if you quote the atoms, the result is

   >(list 'one 'two '(square two))
   (one two (square two))
  

Quasiquote, Unquote and Quote-Evaluated

There is a special variant of the quote form, (quasiquote) or '`' (backtick). A list which is quoted using a quasiquote can contain special escape forms, the unquote ',' (comma) and quote-evaluated ',@' (a comma followed by an at-sign). The unquote causes the literal value of the unquoted symbol or list to be inserted into the quoted list. The quote-evaluated causes the evaluated value of the symbol or list to be inserted into the quoted list.

Contents Previous Next