|
![]() |
(if (> height limit) "too high") returns "too high" if the value in the variable height is greater than the value in the variable limit. Otherwise returns nil.
(if (minusp w) (/ w 2.0) (* w 1.5)) If the value in w is. negative, the second argument is executed. If it is positive, the third argument is executed.
Function definitions for the tests are given in "6
- Arithmetic tests" and "7 - Logic & category
tests."
Following the cond function is a series of lists. Within each list is one test expression and one or more response expressions. After one of the test expressions returns T and its response(s) are executed, no further tests are performed -- the cond function is exited.
(cond
((> j 100) (setq j 100))
((< j -100) (setq j -100)))
Examine the first list (the entire line) after the cond function. The test is the first element in this list, which is (> j 100). If this test passes, j is set to 100. If this test fails, then the AutoLISP interpreter moves on to the next list and runs its test, which is (< j -100). If this test passes, j is set to -100. If neither test passes, then the cond function closes without any action.
(cond
((>= pct 90.0) (setq grade "A"))
((>= pct 80.0) (setq grade "B"))
((>= pet 70.0) (setq grade "C"))
((>= pct 60.0) (setq grade "D"))
(1 (setq grade "F")))
The above expression assigns a letter grade to the variable grade based on the percentage in variable pct.
The 1 in the last list is actually the test. Since 1 always evaluates to 1 (non-nil), the test in the last list always passes, just in case all the other tests fail. This last list is a "catch-all" list. By the way, many AutoLISP books suggest the use of the pre-set variable T for this purpose instead of 1. However, T can be accidentally reset, whereas 1 cannot. So using 1 is the wiser choice.
Function definitions for the tests are given in "6
- Arithmetic tests" and "7 - Logic & category
tests."