if
and cond
.
if
. The syntax follows that outlined for function application,
so it looks like a call to the function called if
. Of course, this
is not the case, since the whole purpose of if
is to evaluate
either the consequent, also known as the then-part, or the
alternative, also known as the else-part, but not both.
(if
condition consequent
alternative)
Each of condition, consequent and alternative can be arbitary Lisp expressions. In some Lisps the alternative is optional, but in EuLisp it is required. It is good practice to include it anyway. Here are the obvious examples with predictable results:
if
provides the chained if-then-elif ...
construct of other programming languages. This operator is called
cond
and looks like this:
exp-i1
is evaluated in turn to find
one whose result is true. Then exp-i2
is
evaluated and the result of this is the result of the cond
expression. If none of the exp-i1
results in true,
the result of the cond
expression is (). Thus, the
above cond
expression is equivalent to
if
above, we get: