Fix bug #3379: recur.mac correct bug in varc2
[maxima.git] / share / macro / caseq.mac
blob4c51cc0038c8a500441dec06feb5c56192043f5a
1 /*-*-Macsyma-*-*/
4 /*
5 CASEQ(<var>,'[<keys1>],<stmt1>,
6             '[<keys2>],<stmt2>,
7             ....,
8             '[<keysn>],<stmtn>
9             {,'otherwise,<code for no match>})
11 where the first <stmt> that has <var> as a member of the associated
12 <keys> is the one chosen to execute.  */
15 sstatus(feature,"gcook caseq")$
17 caseq(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)))$