Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

cond

cond

type: special form (fsubr)
location: built-in
source file: xlcont.c
Common LISP compatible: yes
supported on: all machines

SYNTAX

(cond  [ ( <pred1> <expr1> ) [ ( <pred2> <expr2> ) ... ] ] )
        <predN>         -       a predicate (NIL/non-NIL) expression
        <exprN>         -       an expression

DESCRIPTION

The COND special form evaluates a series of predicate / expression pairs. COND will evaluate each predicate in sequential order until it finds one that returns a non-NIL value. The expression that is associated with the non-NIL value is evaluated. The resulting value of the evaluated expression is returned by COND. If there are no predicates that return a non-NIL value, NIL is returned by COND. Only one expression is evaluated - the first one with a non-NIL predicate. Note that the predicate can be a symbol or expression.

EXAMPLES

(cond                                   ; sample CONDitional
  ((not T) (print "this won't print"))  ;
  ( NIL    (print "neither will this")) ;
  ( T      (print "this will print"))   ;
  ( T      (print "won't get here")))   ; prints "this will print"
(defun print-what (parm)
 (cond                                  ; start of COND
  ((numberp parm) (print "numeric"))    ;  check for number
  ((consp parm)   (print "list"))       ;  check for list
  ((null parm)    (print "nil"))        ;  check for NIL
  (T              (print "something"))) ;  catch-all
 NIL)                                   ;  always return 
                                        ;
(print-what 'a)                         ; prints "something"
(print-what 12)                         ; prints "numeric"
(print-what NIL)                        ; prints "nil"
(print-what '(a b))                     ; prints "list"


Go to the first, previous, next, last section, table of contents.