unwind protect



I don't think Maxima has an (user-level) unwind_protect function. How about

(defmspec $unwind_protect (e)
  (setq e (margs e))
  (unwind-protect (meval (first e)) (mapcar #'meval (rest e))))

Example:

my_sign(e, [f]) := block([prederror : false, my_context],
   unwind_protect((
   newcontext (my_context),
   for fi in f do assume(fi),
   sign(e)),
   killcontext(my_context)));

(%i4) my_sign(x,x > 0);
 1 Enter killcontext [my_context]
 1 Exit  killcontext done
(%o4) pos

(%i5) my_sign(x,x < 0);
 1 Enter killcontext [my_context]
 1 Exit  killcontext done
(%o5) neg

(%i6) my_sign(%i);
`sign' called on an imaginary argument:
%i
#0: my_sign(e=%i,f=[])
 -- an error.  Quitting.  To debug this try debugmode(true);
 1 Enter killcontext [my_context]
 1 Exit  killcontext done

Barton