Conditionals

  • macro function
  • special function
    • quote lambda defun if
    • The distinction between ‘‘macro’’ functions and ‘‘special’’ functions is explained in Chapter 14

if

The IF special functiontakes three arguments: a test, a true-part, and a false-part. (if (oddp 1) ’odd ’even) ⇒ odd

or no false-part

(if t ’happy) ⇒ happy
(if nil ’happy) ⇒ nil

THE COND MACRO

as switch in java run out of clauses, returns NIL

(defun where-is (x)
(cond ((equal x ’paris) ’france)
((equal x ’london) ’england)
((equal x ’beijing) ’china)
(t ’unknown)))

and or

and (and nil t t) ⇒ nil

(defun small-positive-oddp (x)
(and (< x 100)
(> x 0)
(oddp x)))

(and ’george ’fred ’harry) ⇒ harry
(and 1 2 3 4 5) ⇒ 5

or (or ’george nil ’harry) ⇒ george

(defun gtest (x y)
(or (> x y)
(zerop x)
(zerop y)))

(defun logical-and (x y) (and x y t))

Why are AND and OR classed as conditionals instead of regularfunctions? The reason is that they are not required to evaluate every clause

Lisp Toolkit: STEP

debugging