Menu ▾ ▴

#1721 defining infix operator leads to a crash

open
nobody
None
5
2012-11-18
2009-08-06
Anonymous
No

Maxima 5.18post http://maxima.sourceforge.net
Using Lisp Clozure Common Lisp Version 1.4-dev (WindowsX8632)

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

OK:

(%i3) a and (b imp c);
(%o3) a and ((not b) or c)

Not OK: (Maxima terminates)

(%i4) (a and b) imp c;

Discussion

  • Nobody/Anonymous

    its the same with
    (%i1) imp(a,b) := not(a) or b;
    (%o1) not(a) or b
    (%i2) imp(a and b, c);
    *** - Program stack overflow. RESET ...

     
  • Robert Dodier

    Robert Dodier - 2009-08-06

    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.

     

Log in to post a comment.