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
November 1999