Menu ▾ ▴

#5878 Translated block variables with an assignment check behave differently from interpreted ones

None
open
nobody
5
3 days ago
3 days ago
No

By Claude:

Translated and compiled functions bind option variables that have an assignment check differently from the interpreter. A block variable without an initial value is bound to itself, and the interpreter does not check that binding, but translated code does, so it fails for boolean variables:

(%i1) r2() := block([listconstvars], listconstvars : true, listconstvars)$
(%i2) r2();
(%o2) true
(%i3) translate(r2)$
(%i4) r2();
assignment: cannot assign `listconstvars' to `listconstvars': must be one of: true, false.

Translated code also runs the check before it saves the old value. The check of ratvars sets ratvars, so the global value is not restored after the block:

(%i5) p4() := block([ratvars : [b, a]], ratvars)$
(%i6) [p4(), ratvars];
(%o6) [[b,a],[]]
(%i7) translate(p4)$
(%i8) [p4(), ratvars];
(%o8) [[b,a],[b,a]]

For the same reason a check that looks at another variable of the same block sees its old value: block([ratwtlvl : false, ratfac : true], ratfac) fails when translated and the global ratwtlvl is 2, though it works interpreted. With ratwtlvl set, this breaks a compiled rational() from functs, which binds ratfac without a value.

The first problem also exists in Maxima 5.48.1.

Discussion


Log in to post a comment.