GNU Info

Info Node: (cl)Conditionals

(cl)Conditionals


Next: Blocks and Exits Prev: Variable Bindings Up: Control Structure
Enter node , (file) or (file)node

Conditionals
============

These conditional forms augment Emacs Lisp's simple `if', `and', `or',
and `cond' forms.

 - Special Form: case keyform clause...
     This macro evaluates KEYFORM, then compares it with the key values
     listed in the various CLAUSEs.  Whichever clause matches the key
     is executed; comparison is done by `eql'.  If no clause matches,
     the `case' form returns `nil'.  The clauses are of the form

          (KEYLIST BODY-FORMS...)

     where KEYLIST is a list of key values.  If there is exactly one
     value, and it is not a cons cell or the symbol `nil' or `t', then
     it can be used by itself as a KEYLIST without being enclosed in a
     list.  All key values in the `case' form must be distinct.  The
     final clauses may use `t' in place of a KEYLIST to indicate a
     default clause that should be taken if none of the other clauses
     match.  (The symbol `otherwise' is also recognized in place of
     `t'.  To make a clause that matches the actual symbol `t', `nil',
     or `otherwise', enclose the symbol in a list.)

     For example, this expression reads a keystroke, then does one of
     four things depending on whether it is an `a', a `b', a <RET> or
     `C-j', or anything else.

          (case (read-char)
            (?a (do-a-thing))
            (?b (do-b-thing))
            ((?\r ?\n) (do-ret-thing))
            (t (do-other-thing)))

 - Special Form: ecase keyform clause...
     This macro is just like `case', except that if the key does not
     match any of the clauses, an error is signaled rather than simply
     returning `nil'.

 - Special Form: typecase keyform clause...
     This macro is a version of `case' that checks for types rather
     than values.  Each CLAUSE is of the form `(TYPE BODY...)'.  Note:
     Type Predicates, for a description of type specifiers.  For
     example,

          (typecase x
            (integer (munch-integer x))
            (float (munch-float x))
            (string (munch-integer (string-to-int x)))
            (t (munch-anything x)))

     The type specifier `t' matches any type of object; the word
     `otherwise' is also allowed.  To make one clause match any of
     several types, use an `(or ...)' type specifier.

 - Special Form: etypecase keyform clause...
     This macro is just like `typecase', except that if the key does
     not match any of the clauses, an error is signaled rather than
     simply returning `nil'.


automatically generated by info2www version 1.2.2.9