Do it, if it's true.
This function is a commonly used conditional in LISP. If statement1 evaluates to true, any functions that follow within that block are performed, and the result of the last function is returned.
Examples
Code | Results |
---|---|
(cond ((zerop x) 0) | (T nil)) |
In the previous example, the cond function looks at (zeropx) and decides if it is not nil. If so, it returns zero (0). If not, it moves to the second test, (T nil). This test is already true (T) and would return a nil. Look at the following setqs of actual examples of the above condition.
Code | Results |
---|---|
(setq x 8) | nil |
(setq x 0) | 0 |
In the next example, if d is set to 5, LISP returns the string "Equal to." If set to 6, it returns "Greater than."
Code |
---|
(cond ((< d 5) "Less than") |
((= d 5) "Equal to") |
((> d 5) "Greater than") |
) |
Tell me about...
(if test statement1 [statement2])
(repeat number statement1 [statement2 ...])
Programming Overview of LISP (LISt Processing) Language
Bricscad™ is commercialized by Bricsys NV. Bricsys NV and Vondle NV are fully owned subsidiaries of Menhirs NV. © 2001- Menhirs NV - All rights reserved. |