1; SketchyLISP Library
2; Copyright (C) 2006,2007 Nils M Holm. All rights reserved.
3; See the file LICENSE of the SketchyLISP distribution
4; for conditions of use.
5
6; ---name---
7; case
8
9; ---conformance---
10; R5RS
11
12; ---purpose---
13; Select cases.
14
15; ---args---
16; KEY - key used to select a case
17; DATA - possible matches for this case
18; EXPR - value for this case
19
20; ---keywords---
21; CASE syntax, conditional evaluation, case selection
22
23; ---see-also---
24; if
25
26; ---example---
27; ; Example needs pre-loaded image
28; (case 'c ((a b) 'a-or-b) ((c d) 'c-or-d)) --> c-or-d
29
30(require "if.scm")
31(require "memv.scm")
32
33; ---code---
34(define-syntax case
35  (syntax-rules (else)
36    ((_ key (else expr))
37       expr)
38    ((_ key (data expr))
39       (if (memv key 'data)
40           expr
41           (bottom '(no default in case))))
42    ((_ key (data1 expr1) (data2 expr2) ...)
43       (if (memv key 'data1)
44           expr1
45           (case key (data2 expr2) ...)))))
46