next up previous
Contents Next: length (FUNCTION) Up: Appendix: Selected Lisp Previous: first (FUNCTION)

if (SPECIAL FORM)

Format: (if <test> <then> <else> )

Required arguments: 2

<test> : any Lisp expression <then> : any Lisp expression

Optional arguments: 1

<else> : any Lisp expression

The <test> expression is evaluated; if it returns a value other than NIL, if returns the result of evaluating the <then> expression. If <test> evaluates to NIL, and no <else> expression is provided, NIL is returned. Otherwise the result of evaluating <else> is returned.

Examples:

> (if (>  4 3) 4 3)
4

> (if (< 4 3)
     (- 4 3)
     (- 3 4))
-1

> (if (= 4 3) t) 
NIL



© Colin Allen & Maneesh Dhagat
March 2007