Node: Conditional, Next: Binding constructs, Previous: Derived expression types, Up: Derived expression types
cond <clause1> <clause2> ... | library syntax |
Syntax: Each <clause> should be of the form (<test> <expression1> ...) where <test> is any expression. Alternatively, a <clause> may be of the form (<test> => <expression>) The last <clause> may be an "else clause," which has the form (else <expression1> <expression2> ...). Semantics:
A (cond ((> 3 2) 'greater) ((< 3 2) 'less)) ==> greater (cond ((> 3 3) 'greater) ((< 3 3) 'less) (else 'equal)) ==> equal (cond ((assv 'b '((a 1) (b 2))) => cadr) (else #f)) ==> 2 |
case <key> <clause1> <clause2> ... | library syntax |
Syntax: <Key> may be any expression. Each <clause> should have the form ((<datum1> ...) <expression1> <expression2> ...), where each <datum> is an external representation of some object. All the <datum>s must be distinct. The last <clause> may be an "else clause," which has the form (else <expression1> <expression2> ...). Semantics:
A (case (* 2 3) ((2 3 5 7) 'prime) ((1 4 6 8 9) 'composite)) ==> composite (case (car '(c d)) ((a) 'a) ((b) 'b)) ==> unspecified (case (car '(c d)) ((a e i o u) 'vowel) ((w y) 'semivowel) (else 'consonant)) ==> consonant |
and <test1> ... | library syntax |
The <test> expressions are evaluated from left to right, and the value of the first expression that evaluates to a false value (see section see Booleans) is returned. Any remaining expressions are not evaluated. If all the expressions evaluate to true values, the value of the last expression is returned. If there are no expressions then #t is returned. (and (= 2 2) (> 2 1)) ==> #t (and (= 2 2) (< 2 1)) ==> #f (and 1 2 'c '(f g)) ==> (f g) (and) ==> #t |
or <test1> ... | library syntax |
The <test> expressions are evaluated from left to right, and the value of the first expression that evaluates to a true value (see section see Booleans) is returned. Any remaining expressions are not evaluated. If all expressions evaluate to false values, the value of the last expression is returned. If there are no expressions then #f is returned. (or (= 2 2) (> 2 1)) ==> #t (or (= 2 2) (< 2 1)) ==> #t (or #f #f #f) ==> #f (or (memq 'b '(a b c)) (/ 3 0)) ==> (b c) |