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))))))$
|