Conditionals
June 8, 2008 | Filed Under Common Lisp - Touretzky
———————————————————
Chapter 4
———————————————————
Conditionals - IF:
(IF (ODDP 5) ‘odd ‘even) -> odd
COND
(DEFUN COMPARE-TO (x y) (DEFUN WHICH-COUNTRY (x) AND and OR macros: (AND (> 2 1) (< 3 4)) ->T AND progresses until it hits a NIL (in which case it returns NIL) or the end of the arguments, in which case it returns the evaluated last argument. OR progresses until it hit a non-NIL argument (in which case it returns that evaluated argument) or the end of the arguments in which case it returns NIL. (AND ‘a ‘b ‘c) -> c (PLUSP 4) -> T Boolean functions: If both x and y and non-NIL, then the function returns the last evaluated argument (in this case, T) DeMorgan’s Theorum (and x y) = (not (or (not x) (not y))) Leave a Reply
(COND ((EQUAL x y) ‘equal)
((> x y) ‘x-greater-than-y)
((
(COND ((EQUAL x 'LONDON) 'ENGLAND)
((EQUAL x 'PARIS) 'FRANCE)
(T 'UNKNOWN))) ;default fall through
(OR (> 1 2) (< 3 4)) -> T
(AND ‘(1 2) ‘(3 4)) -> (3 4)
(PLUSP -4) -> NIL
(DEFUN LOGICAL-AND (x y)
(AND (x y T)))
(or x y) = (not (and (not x) (not y)))Comments