protect
-- protect an
identifierprotect
(x)
protects the identifier
x
.
protect(x <, protectionlevel>)
x |
- | an identifier |
|
- | either Error or Warning or None. The default value is Warning. |
the previous protection level of x
: either Error or Warning or None.
protect(
x, Error)
sets full
write-protection for the identifier. Any subsequent attempt to assign a
value to the identifier will lead to an error.protect(
x, Warning)
sets a ``soft''
protection. Any subsequent assignment to the identifier results in a
warning message. However, the identifier will be assigned a value,
anyway.
protect(
x)
is equivalent to
protect(
x, Warning)
.
protect(
x, None)
removes any protection
from the identifier. This call is equivalent to unprotect
(x)
.Overwriting protected identifiers such as the names of MuPAD functions may damage your current session.
The following call protects the identifier
important
with the protection level ``Warning'':
>> protect(important, Warning)
None
The identifier can still be overwritten:
>> important := 1
Warning: protected variable important overwritten 1
We protect the identifier with the level ``Error'':
>> protect(important, Error)
Warning
Now, it is no longer possible to overwrite
important
:
>> important := 2
Error: Identifier 'important' is protected [_assign]
The identifier keeps its previous value:
>> important
1
In order to overwrite this value, we must unprotect
important
:
>> protect(important, None)
Error
>> important := 2
2
The identifier is protected again with the default level ``Warning'':
>> protect(important)
None
>> important := 1
Warning: protected variable important overwritten 1
>> unprotect(important): delete important:
protect
does not evaluate its first
argument. Here the identifier x
can still be overwritten,
while its value - which is the identifier y
- remains
write protected:
>> protect(y, Error): x := y: protect(x): x := 1
Warning: protected variable x overwritten 1
>> y := 2
Error: Identifier 'y' is protected [_assign]
>> unprotect(x): unprotect(y): delete x, y:
protect
does not evaluate its first argument. This way
identifiers can be protected that have been assigned a value.