File: case

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (37 lines) | stat: -rw-r--r-- 1,356 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
R4RS 4.2.1  (case <key> <clause1> <clause2> ...)  ==>  object

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 expression is evaluated as follows. <Key> is
evaluated and its result is compared against each <datum>. If the
result of evaluating <key> is equivalent (in the sense of EQV?; see
section see section 6.2 Equivalence predicates) to a <datum>, then
the expressions in the corresponding <clause> are evaluated from
left to right and the result of the last expression in the <clause>
is returned as the result of the CASE expression. If the result of
evaluating <key> is different from every <datum>, then if there is
an ELSE clause its expressions are evaluated and the result of the
last is the result of the case expression; otherwise the result of
the CASE expression is unspecified.

(case (* 2 3)
  ((2 3 5 7) 'prime)
  ((1 4 6 8 9) 'composite))  ==>  composite

(case (car '(c d))
  ((a) 'a)
  ((b) 'b))                  ==>  unspecific

(case (car '(c d))
  ((a e i o u) 'vowel)
  ((w y) 'semivowel)
  (else 'consonant))         ==>  consonant