Serves as the primary conditional function for AutoLISP
(cond [(test result ...) ...])
cond function accepts any number of lists as arguments. It evaluates the first item in each list (in the order supplied) until one of these items returns a value other than nil. It then evaluates those expressions that follow the test that succeeded.
TheReturn Values
cond returns nil.
The value of the last expression in the sublist. If there is only one expression in the sublist (that is, if result is missing), the value of the test expression is returned. If no arguments are supplied,Examples
cond to perform an absolute value calculation:
The following example uses(cond
((minusp a) (- a))
(t a)
)
a is set to the value -10, this returns 10.
If the variablecond can be used as a case type function. It is common to use T as the last (default) test expression. Here's another simple example. Given a user response string in the variable s, this function tests the response and returns 1 if it is Y or y, 0 if it is N or n; otherwise nil.
As shown,(cond
((= s "Y") 1)
((= s "y") 1)
((= s "N") 0)
((= s "n") 0)
(t nil)
)