protect a name from modification
undo name protection
protect(name1, name2, ...)
unprotect(name1, name2, ...)
name1, name2, ...
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.
An error is raised when trying to assign to a protected name.
Pi ≔ 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.
Redefining protected names can affect results. Consider the correct value of arctan(1).
Observe what happens when the constant Pi is changed to 1.
Pi ≔ 1
Protecting Your Own Names
Important variables and constants can be protected.
myname ≔ 123
myname ≔ 456
Error, attempting to assign to `myname` which is protected. Try declaring `local myname`; see ?protect for details.
myname ≔ 789
Multiple names can be protected at once.
first ≔ 1
second ≔ 2
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
The original procedure is still available as :-length.
The imaginary unit is special. When overridden with a local, the global version can be accessed via _I.
local I ≔ 1|0,0|1
To reset the imaginary unit after declaring it local, use the unbind command.
Download Help Document
What kind of issue would you like to report? (Optional)