scope

Prev Next

Function Names

scope

Description

Identifies the variable scope (e.g. global, local).

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1

Parameters

No.TypeDescription
1
code
variable
:string
Variable to check

Return value

TypeDescription
string variable form

One of the following:

not found Variable does not exist
system System variable
global Global variable
regional Regional variable (reserved, not yet implemneted)
local Local variable

Examples

       // In the main program area, variables created are global.
       g[] = world;

       define procedure ( foo )
       {
               // Inside procedure, functions and B4P programs called with start(...),
               // the variables declared are local unless the 'global' function is used.

               a[] = 1;
               global { h[] = 1; }
               g[me] = you;

               echo( "Variable a[]: ", scope( a[] ) );     // global
               echo( "Variable g[]: ", scope( g[] ) );     // local
               echo( "Variable g[me]: ", scope( g[me] ) );   // global
               echo( "Variable h[]: ", scope( h[] ) );     // global
               echo( "Verbose settings: ", scope( runtime settings[verbose] ) );     // system
       }

       foo; // Call the function

Output

Variable a[]: local
Variable g[]: global
Variable g[me]: global
Variable h[]: global
Verbose settings: system
Try it yourself: Open LIB_Function_scope.b4p in B4P_Examples.zip. Decompress before use.

See also

identify