Previous Page Next Page Contents

protect -- protect an identifier

Introduction

protect(x) protects the identifier x.

Call(s)

protect(x <, protectionlevel>)

Parameters

x - an identifier

Options

protectionlevel - either Error or Warning or None. The default value is Warning.

Returns

the previous protection level of x: either Error or Warning or None.

Related Functions

unprotect

Details

Example 1

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:

Example 2

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:

Background

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000