try declaring local - Maple Help

Home : Support : Online Help : System : Error Message Guide : try declaring local

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

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;
 ${\mathrm{start}}{≔}{1.3982}$ (1)
 > finish := 12.2315;
 ${\mathrm{finish}}{≔}{12.2315}$ (2)
 > diff := finish - start;

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;
 ${\mathrm{diff}}{≔}{10.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);
 $\frac{{1}}{{x}}$ (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";
 ${\mathrm{myname}}{≔}{"global version of myname"}$ (6)
 > local myname := "local version of myname";
 ${\mathrm{myname}}{≔}{"local 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;
 ${\mathrm{myProtectedName}}{≔}{19}$ (10)
 > protect('myProtectedName');
 > myProtectedName := 23;

Use the unprotect command to remove protection from your name and change its value.

 > unprotect('myProtectedName');
 > myProtectedName := 23;
 ${\mathrm{myProtectedName}}{≔}{23}$ (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));
 $\frac{{\mathrm{\pi }}}{{4}}$ (12)

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

 > unprotect(Pi);
 > Pi := 4;
 ${\mathrm{\pi }}{≔}{4}$ (13)
 > eval(arctan(1));
 ${1}$ (14)