protect
protect a name from modification
unprotect
undo name protection
Calling Sequence
Parameters
Description
Examples
protect(name1, name2, ...)
unprotect(name1, name2, ...)
name1, name2, ...
-
names
protect is used to prevent names from being modified either in an interactive session, user or library code. Most of the names initially known to Maple are protected by default.
Attempting to assign to a protected name will raise an error. There are two ways to circumvent this error, either use the unprotect command, or declare the name as a "local" variable.
Using unprotect can be dangerous as a subsequent assignment will override the default value of that name which will effect internal algorithms that may expect and rely on the default value for correctness. By the same token, being able to unprotect and reassign new values to methods in Maple gives you a powerful tool for extending the system.
Variables assigned to within procedures are implicitly understood as being local, in which case you would not run into a conflict with a protected name. At the top-level, you can declare a variable as local by using the statement, local X;. This will create a new version or binding of the name, X. The original protected name in this case is still accessible using :-X. In general the original name is always available using the :- prefix, except for the case of the imaginary unit, I. Declaring I to be local will always give you a warning telling you what the new global name is, favoring, _I, if available. To remove the local X use the command unbind(X).
A warning will be displayed when declaring and assigning to local X at the top-level only if X had been previously used in the session. To avoid this warning declare local X prior to using it.
protect has no effect on environment variables.
Protected Names
An error is raised when trying to assign to a protected name.
π≔3.14
Error, attempting to assign to `Pi` which is protected. Try declaring `local Pi`; see ?protect for details.
solve≔x2
Error, attempting to assign to `solve` which is protected. Try declaring `local solve`; see ?protect for details.
Unprotect
Redefining protected names can affect results. Consider the correct value of arctan(1).
eval⁡arctan⁡1
π4
Observe what happens when the constant Pi is changed to 1.
unprotect⁡π
π≔1
14
Protecting Your Own Names
Important variables and constants can be protected.
myname≔123
protect⁡myname
myname≔456
Error, attempting to assign to `myname` which is protected. Try declaring `local myname`; see ?protect for details.
unprotect⁡myname
myname≔789
Multiple names can be protected at once.
first≔1
second≔2
protect⁡first,second,π:
second≔3
Error, attempting to assign to `second` which is protected. Try declaring `local second`; see ?protect for details.
Creating Local Names
Local versions of names can be created that overshadow the protected version.
local length≔0.001
0.001
length2
1.×10−6
The original procedure is still available as :-length.
:-length⁡abc
3
The imaginary unit is special. When overridden with a local, the global version can be accessed via _I.
local I := <1,0;0,1>;
I
1001
I2
_I2
−1
interface⁡imaginaryunit
_I
To reset the imaginary unit after declaring it local, use the unbind command.
unbind⁡I
length
interface⁡imaginaryunit=I
See Also
environment
initialconstants
initialfunctions
local
name
type/protected
unassign
with
Download Help Document