Slide 8.c: Basic functions
Slide 8.e: How to write functions
Home

COND


COND is an unusual function which may take any arbitrary number of arguments. Each argument is called a clause, and consists of a list of exactly two S-expressions. We will call the first S-expression in a clause a condition, and the second S-expression a result. Thus, a call to COND looks like this:
   (COND
      (condition1   result1)
      (condition2   result2)
      ...
      (T            resultN))
The value returned by COND is computed as follows: It is an error if none of the conditions are true, and the result of the COND is undefined. For this reason, T is usually used as the final condition.

  (cond  ((null  (read))  'empty)
         (T               'not-empty))
READ:        

       


The above expression tests whether or not the input is empty by using the following two instructions: