(if test statement1 [statement2])
If it is true, do it; otherwise, do something else.
This function lets you test two conditions: if test is true, then perform statement1, else perform statement2. (Statement2 is optional.) If test is true, then LISP returns the value of statement1. If test is not true, then LISP returns the value of statement2.
Examples
Code | Returns |
---|---|
(setq d 9) | |
(if (>= d 10) "Greater") | nil |
(if (>= d 8) "Greater") | "Greater" |
(if (and (> d 12) (< d 13)) "In range" "Out of range") | "Out of range" |
NOTE The if function only allows a single statement for statement1 and statement2. If you want a multi-line statement, surround them by the progn function, as in the following example:
(if (> x 15)
(progn (
(setq window 20.0 door 32.0)
(command "color" 1)
) ; end progn
) ; end then
) ; end if
Tell me about...
(cond (statement1 result1 ...) ...)
(repeat number statement1 [statement2 ...])