Previous Page Next Page Contents

Pref::warnDeadProcEnv -- warnings about wrong usage of lexical scope

Introduction

Pref::warnDeadProcEnv() returns the current setting.

Pref::warnDeadProcEnv(TRUE) switches on warnings about unreachable procedure environments.

Pref::warnDeadProcEnv(FALSE) switches warning messages off.

Pref::warnDeadProcEnv(NIL) will reset the default value, which is FALSE.

Call(s)

Pref::warnDeadProcEnv()
Pref::warnDeadProcEnv(TRUE)
Pref::warnDeadProcEnv(FALSE)
Pref::warnDeadProcEnv(NIL)

Returns

the previously defined value; TRUE or FALSE

Side Effects

Allows or suppresses warning messages.

Further Documentation

changes

Related Functions

Pref::warnChanges, Pref::warnLexProcEnv, proc

Details

Example 1

Here we write procedure p which returns a local procedure. The returned procedure adds the value of its argument y to the value of the argument x of the first procedure. The following naive implementation produces a strange output and, when the resulting procedure is called, a warning message and an error:

>> Pref::warnDeadProcEnv(FALSE): 
   p := proc(x) begin y -> x + y end:  
   f := p(1);  f(2)
                           y -> DOM_VAR(1,2) + y
      Warning: Uninitialized variable 'unknown' used;
      during evaluation of 'f'
      Error: Illegal operand [_plus];
      during evaluation of 'f'

If Pref::warnDeadProcEnv is set to TRUE MuPAD will print a warning message when the local procedure escapes its scope:

>> Pref::warnDeadProcEnv(TRUE): 
   p := proc(x) begin y -> x + y end:  
   f := p(1)
      Warning: Found dead closure of procedure 'p'
      
                           y -> DOM_VAR(1,2) + y

Use option escape in the outer procedure to prevent this warning. The returned procedure f will then work as expected:

>> p := proc(x) option escape; begin y -> x + y end:  
   f := p(1);  f(2)
                                y -> x + y
      
                                     3

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000