ch2_1_cond
COND
COND
is a multi branched conditional in LISP and accepts any number arguments, that must be lists - clauses. Sequentially, first element of the clause list is evaluated. If the result is NIL
the rest of the clause is ignored. If the first element is true (not NIL
), the following items in the clause are evaled as in PROGN
, the result of the last is returned from the COND
, and all the following clauses are ignored.
>(setq a 2) ; prepare A for this example 2 >(cond ((= a 1) (print "beep") 1) ((= a 2) (print "beep") (print "beep") 2) ((= a 3) (print "beep") (print "beep") (print "beep") 3) (T "none")) "beep" "beep" 2
When none of the clause conditions are true, the whole form returns NIL
. In the example above, the last form has the T
as condition, so if none of the previous conditions apply, the last clause will be evaled.
See also IF
, WHEN
, UNLESS
, AND
, OR
ch2_1_cond.txt · Last modified: 2024/05/05 10:50 by admin