IF Statement

Common Lisp provides an IF statement:


(IF < test>  < then-form> )

(IF < test>  < then-form>  < else-form> )
The < test> is evaluated first. If it returns a non- NIL value, the < then-form> is evaluated and its value is the value of the IF; otherwise, the < else-form> is evaluated and its value is the value of the IF.

Since NIL is false and anything else is treated as true, a common convention is for a function to return NIL if it did not work, or an answer if it did work.


(SETQ Y (IF (<  X 0.0)
            (* X X)
            (SQRT X)))

Note that the < then-form> and < else-form> are single forms; if multiple things need to be done, they must be enclosed in a PROGN.

Contents    Page-10    Prev    Next    Page+10    Index