On 2012-07-02, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> newcontext/supcontext do evaluate their arguments -- try e.g.
> newcontext(gensym("ctx")) -- but the whole thing is silly.
newcontext does indeed evaluate its argument, but supcontext quotes its.
I don't see a reason for supcontext to quote ... seems reasonable and
harmless to have it evaluate.
> Sometimes you need to name contexts, but often anonymous contexts are fine.
> It looks like in most cases, all you want is something like
> with_local_context( ... ). Of course, this can be written as a Maxima
> macro (::=) using supcontext, but if the most common use case is anonymous
> contexts, Maxima should support them directly.
How about this:
load (unwind_protect); /* from share -- tnx Barton W */
with_local_context ([e]) ::= buildq ([e], block ([foo : gensym ()],
apply (supcontext, [foo]), unwind_protect (block (splice (e)),
killcontext (foo))));
macroexpand (with_local_context (assume (a > 0, b > a), integrate (1/x,
x, a, b)));
=> block([foo:gensym()],apply(supcontext,[foo]), unwind_protect(block
(assume(a > 0,b > a),integrate(1/x,x,a,b)), killcontext(foo)))
with_local_context (assume (a > 0, b > a), integrate (1/x, x, a, b));
=> log(b) - log(a)
facts ();
=> []
contexts;
=> [initial, global]
best
Robert Dodier