Program stack overflow defining infix operator



On Thu, Aug 6, 2009 at 6:16 AM, Stephan Lukits<stephan at lukits.de> wrote:

> (%i1) infix("imp", 50, 50, clause, clause, clause);
>
> (%o1)                                 imp
> (%i2) "imp"(a, b):= not(a) or b;

> (%i4) expand(a and b imp c);
>
> *** - Program stack overflow. RESET

Looking at the stack trace, it appears Maxima is trying to
evaluate a and b, for which it first needs a, which is
bound to a and b, for which it first needs a, ... ad infinitum.

(Maxima has so-called dynamic binding, not lexical.
There are arguments either way, but for the moment let's
take it as a given.)

Just renaming the argument variables avoids this problem:

imp (aa, bb) := not(aa) or bb;
a and b imp c;
 => ((not a) or (not b)) or c

Of course a name collisions causes it to crash as before:

aa and bb imp c;
 => stack overflow

Not sure if there's anything to do here aside from trying
to work around the problem.

Robert Dodier