File: caseq.mac

package info (click to toggle)
maxima 5.10.0-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 44,268 kB
  • ctags: 17,987
  • sloc: lisp: 152,894; fortran: 14,667; perl: 14,204; tcl: 10,103; sh: 3,376; makefile: 2,202; ansic: 471; awk: 7
file content (28 lines) | stat: -rw-r--r-- 882 bytes parent folder | download
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
/*-*-Macsyma-*-*/


/*
CASEQ(<var>,'[<keys1>],<stmt1>,
            '[<keys2>],<stmt2>,
            ....,
            '[<keysn>],<stmtn>
            {,'otherwise,<code for no match>})

where the first <stmt> that has <var> as a member of the associated
<keys> is the one chosen to execute.  */


sstatus(feature,"gcook caseq")$

caseq(var,[pairs])::=
   if length(pairs)<=2 then
      block([keys:first(pairs),statement:last(pairs)],
         if keys=otherwise then buildq([var,statement],statement)
         else buildq([var,keys,statement],if member(var,'keys) then statement))
   else buildq([var,keys:first(pairs),statement:first(rest(pairs)),
                pairs:rest(rest(pairs))],
          if member(var,'keys) then statement else caseq(var,splice(pairs)))$

push(c,l)::=(if symbolp(x) then x else error("arg must be a symbol",x),
             buildq([c,l],l:cons(c,l)))$