Error, attempting to assign to `...` which is protected. Try declaring `local ...`; see ?protect for details.
Description
Examples
This error occurs when you assign a value to a protected name. Protection is used to prevent names from being modified by the user.
One way to solve this error is to use a name that is not protected. However, if you prefer to use the protected name, you can do one of the following to avoid this error.
use local to declare a local version of the name (see Example 1)
use unprotect to remove protection from the protected name (see Example 2)
Note: It is not recommended that you remove protection from Maple protected names. If you must use a Maple protected name, you should declare a local version of the name.
Example 1: Declaring a protected name as local
An error is generated when you assign a value to a Maple protected name.
start≔1.3982
finish≔12.2315
diff≔finish−start
Error, attempting to assign to `diff` which is protected. Try declaring `local diff`; see ?protect for details.
The error is generated because diff is the Maple protected name for the differentiation command. To use a Maple protected name in your worksheet, declare the name using local.
local diff≔finish−start
Warning, A new binding for the name `diff` has been created. The global instance of this name is still accessible using the :- prefix, :-`diff`. See ?protect for details.
diff≔10.8333
diff
10.8333
To access the Maple diff command, call :-diff. The following command differentiates ln(x) with respect to x.
:-diff⁡ln⁡x,x
1x
You can even declare a local version of a name you already declared. The global (that is, original) name is again accessed by adding :- before the name.
myname≔global version of myname
local myname≔local version of myname
Warning, A new binding for the name `myname` has been created. The global instance of this name is still accessible using the :- prefix, :-`myname`. See ?protect for details.
myname≔local version of myname
myname
local version of myname
:-myname
global version of myname
Example 2: Using unprotect on a protected name
You can protect a name with the protect command. After protecting a name, an error is generated if you try to change the value stored in the protected name.
myProtectedName≔19
protect⁡myProtectedName
myProtectedName≔23
Error, attempting to assign to `myProtectedName` which is protected. Try declaring `local myProtectedName`; see ?protect for details.
Use the unprotect command to remove protection from your name and change its value.
unprotect⁡myProtectedName
Although you can use the unprotect command on a Maple protected name, this is not recommended because it alters the value of results. For example, consider the correct value of arctan(1).
eval⁡arctan⁡1
π4
Changing the value of Pi affects this and any other result containing Pi.
unprotect⁡π
π≔4
1
See Also
protect
type/protected
unprotect
Download Help Document
What kind of issue would you like to report? (Optional)