Question: Is there an option to have Maple warn against using variable name that matches any option used by Maple functions?

Maple will give error when one tries to make a variable of the same name as a Maple command. Which is good ofcourse. So this gives an error

Vector:=5;

But Maple also uses hundreds of other names, as options, which are not protected like this. Even when adding this

adding interface(warnlevel=4);
kernelopts('assertlevel'=2):

There was no warning when a user makes a variable of same name as one of those Maple option names.

So if a user make a variable with such a name, it will cause serious problem. For example Vector constructor takes the name row as an option. But this name is not protected. So one can write  row:=5 and there is no warning generated by Maple.

Using Vector['row'] does not actually help. Here is an example, where Maple crashes due to this

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector['row']);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem

ArrayTools:-Concatenate(1,A,convert([a,b],Vector['row'])); #this will crash Maple

 

A workaround this, it to use double '' in the second call. Like this:

ArrayTools:-Concatenate(1,A,convert([a,b],Vector[''row''])); 

And if this to used again, to use

ArrayTools:-Concatenate(1,A,convert([a,b],Vector['''row'''])); 

And so on.  Ofcourse this is no way to do things.

So the user should not use row as variable name. May be use the_row instead, or a_row, and so on.

But this comes back to my question. The above is a made up example. How is the user supposed to remember there is some option used by Maple somewhere with such a name and avoid using it as a variable name? 

There are may be thousands of such names in Maple, with common names, like color and so on, and it is very easy to make a variable of this name by the user without noticing.

I also tried maplemint() and it gave no warning that a user variable have the same name as a Maple option name.

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc()
local A,row,res,a,b;
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector['row']);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem
ArrayTools:-Concatenate(1,A,convert([a,b],Vector['row'])); #this will crash Maple
end proc;

maplemint(foo);

foo()

 

Finally, I found that if I use Vector(:-row) instead of Vector('row'), then the crash goes away and now it works

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc()
local A,row,res,a,b;
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector[:-row]);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem
ArrayTools:-Concatenate(1,A,convert([a,b],Vector[:-row])); #this will now work
end proc;

foo();

But this worked because there was no global variable of the name row before calling foo. That is all. To make the above crash, all what I had to do is this
 

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc()
local A,row,res,a,b;
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector[:-row]);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem
ArrayTools:-Concatenate(1,A,convert([a,b],Vector[:-row])); #this will now work
end proc;

row:=5;
foo();

And now it crashes again.

This is all a big mess. Maple should warn users they are using variable of same name as Maple own option names, or make all Maple option names use some standard prefix. May be have them all start with or _ and have this special first letter be allowed only for Maple own use.

This will help prevent name clashes.

In Mathematica, this issue does not happen. Since all Mathematica names and symbols used, even as options, are protected or are strings. So no such possibility of name clash happen.

Is there a 100% robust way in Maple to prevent such name clash between user variable names and names used as options to Maple commands?

 

Please Wait...