File: contrl.mac

package info (click to toggle)
maxima 5.49.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 128,980 kB
  • sloc: lisp: 437,854; fortran: 14,665; tcl: 10,143; sh: 4,598; makefile: 2,204; ansic: 447; java: 374; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (42 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download | duplicates (9)
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
38
39
40
41
42
/*-*-MACSYMA-*-*/

eval_when([translate,batch,demo],
          if get('sharem,'version)=false then load(autolo))$

herald_package(contrl)$

/* cond and caseq */

eval_when([translate,batch,demo,loadfile],

cond([pair_sequence])::=
 if pair_sequence=[] then buildq([],false)
 else
  block([pred:pop(pair_sequence),
	 form:if pair_sequence=[] then error("odd number of cond args")
	      else pop(pair_sequence)],
    if pred=true then buildq([form],form)
    else buildq([pred,form,pair_sequence],
	    if pred then form else cond(splice(pair_sequence))))
)$

caseq(exp,[pairs])::=
 block([predt,statement],
  cond(not atom(exp),
       buildq([g:gensym(),exp,pairs],block([g:exp],caseq(g,splice(pairs)))),

       pairs=[],buildq([],false),

       (predt:pop(pairs),if listp(predt) and length(predt)=1 then predt:predt[1],pairs=[]),
       error("odd number of caseq case args"),
       
       true,
       (statement:pop(pairs),
        if member(predt,'[otherwise,true]) then buildq([statement,exp],statement)
	else
	   buildq([condition:if listp(predt) then
				buildq([exp,predt],member(exp,'predt))
			     else buildq([exp,predt],exp='predt),
		   statement,exp,pairs],
              if condition then statement
	      else caseq(exp,splice(pairs))))))$