17.05.2015 Views

zl:1 - FTP

zl:1 - FTP

zl:1 - FTP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

case<br />

64<br />

I<br />

one clause and then executing all consequents of that clause. However,<br />

case differs in the mechanism of clause selection.<br />

The lrrst thing case does is to evaluate test·object, to produce an object<br />

called the key object. Then case considers each of the clauses in turn. If<br />

key is eql to any item in the clause, case evaluates the consequents of that<br />

clause as an implicit progn.<br />

If no clause is satisfied, case returns nil.<br />

case returns the value of the last consequent of the clause evaluated, or nil<br />

if there are no consequents to that clause.<br />

The keys in the clauses are not evaluated; they must be literal key values.<br />

It is an error for the same key to appear in more than one clause. TJ:1e order<br />

of the clauses does not affect the behavior of the case construct.<br />

Instead of a test, one can write one of the symbols t and otherwise. A<br />

clause with such a symbol always succeeds and must be the last clause;<br />

this is an exception to the order-independence of clauses.<br />

If there is only one key for a clause, that key can be written in place of a<br />

list of that key, provided that no ambiguity results. Such a "singleton key"<br />

can not be nil (which is confusable with 0, a list of no keys), t, otherwise,<br />

or a cons.<br />

Examples:<br />

(let «num 69»<br />

(case num<br />

«1 2) "math ... ack H )<br />

«3 4) "great now we can count"») => NIL<br />

(1 et «num 3»<br />

(case num<br />

«1 2) "one two")<br />

«3 4 5 6) (princ "numbers") (princ " three") (fresh-line) )<br />

(t "not today"») => numbers three<br />

T<br />

(let «object-one 'candy»<br />

(case object-one<br />

(apple (setq class 'health) "weekdays")<br />

(candy (setq class 'junk) "weekends")<br />

(otherwise (setq class 'unknown) "all week long"») => "weekends"<br />

class => JUNK<br />

For a table of related items: See the section "Conditional Functions" in<br />

Symbolics Common Lisp: Language Concepts.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!