Error, attempting to assign to `_Z` which is protected. Try declaring `local _Z`; see ?protect for details. - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Error, attempting to assign to `_Z` which is protected. Try declaring `local _Z`; see ?protect for details.

Error, attempting to assign to `...` which is protected.  Try declaring `local ...`; see ?protect for details.

 

Description

Examples

Description

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.

Examples

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;

start1.3982

(1)

finish := 12.2315;

finish12.2315

(2)

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.

diff10.8333

(3)

diff;

10.8333

(4)

To access the Maple diff command, call :-diff. The following command differentiates ln(x) with respect to x.

:-diff(ln(x),x);

1x

(5)

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";

mynameglobal version of myname

(6)

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.

mynamelocal version of myname

(7)

myname;

local version of myname

(8)

:-myname;

global version of myname

(9)

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;

myProtectedName19

(10)

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');

myProtectedName := 23;

myProtectedName23

(11)

 

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

(12)

Changing the value of Pi affects this and any other result containing Pi.

unprotect(Pi);

Pi := 4;

π4

(13)

eval(arctan(1));

1

(14)

See Also

protect

type/protected

unprotect