protect - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


protect

protect a name from modification

unprotect

undo name protection

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

protect(name1, name2, ...)

unprotect(name1, name2, ...)

Parameters

name1, name2, ...

-

names

Description

• 

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.

Examples

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.

solvex2

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).

evalarctan1

π4

(1)

Observe what happens when the constant Pi is changed to 1.

unprotectπ

π1

π1

(2)

evalarctan1

14

(3)

Protecting Your Own Names

Important variables and constants can be protected.

myname123

myname123

(4)

protectmyname

myname456

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

unprotectmyname

myname789

myname789

(5)

Multiple names can be protected at once.

first1

first1

(6)

second2

second2

(7)

protectfirst,second,π:

second3

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 length0.001

0.001

(8)

length2

1.×10−6

(9)

The original procedure is still available as :-length.

:-lengthabc

3

(10)

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

(11)

I2

1001

(12)

_I2

−1

(13)

interfaceimaginaryunit

_I

(14)

To reset the imaginary unit after declaring it local, use the unbind command.

unbindI

length

(15)

interfaceimaginaryunit=I

_I

(16)

I2

−1

(17)

See Also

environment

initialconstants

initialfunctions

local

name

type/protected

unassign

with