Adding a null character to a name, shouldn’t affect it’s interpretation:
x := 'x'; evalb(x=x||``); x := x true
However, when doing the same thing in a procedure, this same behavior doesn’t seem to apply:
test := proc() local x; print(evalb(eval(x)=eval(x||``))); end: test(); false
What am I missing?
Well, you are missing the following (cf. online help page of cat):
"Note that if the result of cat is a name, then it is in fact a global name, even though there might be a local variable of the same name currently active."
and
"This allows you to make global assignments from within procedures. It illustrates the fact that only global names are returned by cat."
(the latter being the comment on the last example of that online help page). Thus we have in turn:
x:='x': test1:=proc() local x; print(evalb(x=cat(x,``))); print(x-cat(x,``)) end: test1(); false x - x
test2:=proc() global x; print(evalb(x=cat(x,``))); print(x-cat(x,``)) end: test2(); true 0
Actually you’re not adding anything to the name. But you can’t construct a local
variable inside a procedure. The constructed name refers to the global variable
x, not the local variable of the procedure. See my Maple Advisor Database
page ?Constructing_names_of_local_variables_and_formal_parameters
(http://www.math.ubc.ca/~israel/advisor):
The reason for this behaviour is connected to the way the Maple kernel processes procedure definitions. Internally, names are used for reference to global variables, but not local variables or formal parameters. For example:
> test3:= proc(x) local v; v:= x+g end: > pointto(disassemble(addressof(eval(test3)))[6]); LOC[1] := args[1] + g
Thus in the internal version of the procedure definition, the local variable name v is replaced
by LOC[1]
, and the formal parameter name x is replaced by args[1]
(more precisely, these
are special constructions which Maple interprets as references to the first local variable and
the first formal parameter). If a name is only produced when the procedure is
executed, these replacements do not occur and the name is interpreted as a global
variable.