1/*-*-Macsyma-*-*/
2
3
4/*
5CASEQ(<var>,'[<keys1>],<stmt1>,
6            '[<keys2>],<stmt2>,
7            ....,
8            '[<keysn>],<stmtn>
9            {,'otherwise,<code for no match>})
10
11where the first <stmt> that has <var> as a member of the associated
12<keys> is the one chosen to execute.  */
13
14
15sstatus(feature,"gcook caseq")$
16
17caseq(var,[pairs])::=
18   if length(pairs)<=2 then
19      block([keys:first(pairs),statement:last(pairs)],
20         if keys=otherwise then buildq([var,statement],statement)
21         else buildq([var,keys,statement],if member(var,'keys) then statement))
22   else buildq([var,keys:first(pairs),statement:first(rest(pairs)),
23                pairs:rest(rest(pairs))],
24          if member(var,'keys) then statement else caseq(var,splice(pairs)))$
25
26