Menu ▾ ▴

#5875 Translated functions fail on nested block bindings of a define_variable variable

None
open
nobody
5
3 days ago
3 days ago
No

By Claude:

A translated function that binds a variable from define_variable in two nested blocks fails, while the interpreted function works:

(%i1) define_variable(zz, 0, fixnum)$
(%i2) f() := block([zz], block([zz], 42))$
(%i3) f();
(%o3) 42
(%i4) translate(f)$
(%i5) f();
translator: zz was declared with mode fixnum, but it has value: zz
 -- an error. To debug this try: debugmode(true);

With a single block([zz], 42) the translated function works, that was bug #3402. The same happens when a function parameter is bound again in a block, as in f(zz) := block([zz], zz + 1).

Conversely, a local variable that has the same name as a variable declared with a global mode_declare gets that mode in translated code, though it is a different variable. Interpreted, this returns 2.5, translated with SBCL it gives a Lisp error:

(%i1) mode_declare(x9, fixnum)$
(%i2) g() := block([x9 : 2.5], x9)$
(%i3) translate(g)$
(%i4) g();
Maxima encountered a Lisp error:
 [...]
 is
   2.5,
 not a
   FIXNUM.

The same happens for a parameter, as in h(x9) := x9 and h(2.5). Finally, a mode_declare of a local variable inside a translated function stays in effect after the translation: after translating h() := block([y7], mode_declare(y7, fixnum), y7 : 1), translating k() := block([y7 : 2.5], y7) gives a function that fails the same way.

Discussion


Log in to post a comment.