Attachment if
Because the parts (if test-expression then-expression else-expression)
an else if
would have to insert the new if
as else-expression
:
(if test-expression1 then-expression1 (if test-expression2 then-expression2 else-expression2))
Using cond
In other languages, else if
usually at the same level. For lisps for this we have cond
. Here is the same with cond
:
(cond (test-expression1 then-expression1) (test-expression2 then-expression2) (t else-expression2))
Note that the expression may be just that. Any expression, so often, is similar to (some-test-p some-variable)
, and other expressions are usually the same. Very rarely, these are just single characters to evaluate, but it can be for very simple conventions.
source share