## `Pref::warnLexProcEnv` -- warnings about usage of variables from lexical scope

#### Introduction

`Pref::warnLexProcEnv(``)` returns the current setting.

`Pref::warnLexProcEnv(`TRUE`)` switches on parser warnings about the usage of variables from the lexical scope.

`Pref::warnLexProcEnv(`FALSE`)` switches warning messages off.

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

#### Call(s)

`Pref::warnLexProcEnv()`
`Pref::warnLexProcEnv(TRUE)`
`Pref::warnLexProcEnv(FALSE)`
`Pref::warnLexProcEnv(NIL)`

#### Returns

the previously defined value; `TRUE` or `FALSE`

#### Side Effects

Allows or suppresses warning messages of the parser.

#### Further Documentation

changes

#### Related Functions

`Pref::warnChanges`, `Pref::warnDeadProcEnv`, `proc`

#### Details

- If `Pref::warnLexProcEnv` is enabled the parser warns if a procedure defined in the lexical scope of another procedure uses variables from its lexical scope.
- These warnings are not always critical. The example below shows a procedure which initiates a warning message but works without problems.
- `Pref::warnDeadProcEnv` switches on warnings about the critical usage of the lexical scope.

#### Example 1

Here you can see a procedure which computes the square of its argument in a very complicated way. The inner procedure `g` makes use of the variable `x` of procedure `f`, thus a warning is given. But this is no problem, since `g` does not escape its scope. See `Pref::warnDeadProcEnv` about problems of procedure leaving its scope.

    >> Pref::warnLexProcEnv(TRUE):
       f := proc(x) local g; begin g := y -> x*y; g(x) end:
       f(5)

          Warning: Procedure '->' is referring outer lexical closure \
           [col 42]

                                        25

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000