Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2306 unevalled if doesn't eval subscripted exprs

None
open
Robert Dodier
5
2013-11-20
2011-11-18
Stavros Macrakis
No

foo(q):=block([r:[2,3]],if q<0 then r[1] else r[2]);
foo(uuu) => if uuu < 0 then r[1] else r[2]

This should be
if uuu < 0 then 2 else 3

Note that r[1] and r[2] are not defined in the global context.

Compare:

bar(q):=block([r1:2,r2:3],if q<0 then r1 else r2)$
bar(uuu) => if uuu < 0 then 2 else 3

When fixing, don't forget cases like this:

qux(q,i):=block([r:[2,3]],if q<0 then r[i] else r[i+1])$
qux(uuu,1) => if uuu < 0 then r[1] else r[2]

Or this:

qux(uuu,j) => if uuu < 0 then r[j] else r[j+1]

Correct result is if uuu < 0 then [2,3][j] else [2,3][j+1]

Tested in Maxima 5.25.1.
In the real case, the list being subscripted was the result of divide, not that it matters.

Discussion

  • Robert Dodier
    Robert Dodier
    2013-11-20

    • labels: Lisp Core --> Lisp Core, if, evaluation
    • Group: --> None