regional

Prev Next

Function Names

regional

Synopsis

regional { statements; }
regional () statement;
regional () { statements; }

Description

In the statement or code block following the regional function, all local (and regional) variables accessible here will also be visible in the code of user-defined functions called further from here. This feature is useful for making a large number of variables accessible in the code of the user-defined function called, without using numerous function parameters or global variables.

Variables which are neither system variables, global variables, nor local variables, are defined as regional variables as they are defined by the calling code and made visible.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

0

Examples

  define procedure( zoo )
  {
      echo('Zoo in ', city[], ' ', country[]);
      city[] = Cambridge;                  // city and country are regional variables
      country[] = United Kingdom;
      echo( "   Scope of country[] in 'zoo': ", scope(country[]), " and city[]: ", scope( city[]) );
  }

  define procedure( bar )
  {
      country[] = USA;                     // country is a local variable, but city is not
      echo('Bar in ', city[], ' ', country[]);

      regional  // Alternative formulation
      {
          zoo;
      }
      echo('Bar in ', city[], ' ', country[]); // Cambridge, UK
      echo( "   Scope of country[] in 'bar': ", scope(country[]), " and city[]: ", scope( city[]) );

  }

  define procedure( foo )
  {
      city[] = Boston;
      regional() bar;
      echo('Foo(d) in ', city[]); // Cambridge
  }

  // Main program
  foo;

Output

Bar in Boston USA
Zoo in Boston USA
   Scope of country[] in 'zoo': regional and city[]: regional
Bar in Cambridge United Kingdom
   Scope of country[] in 'bar': local and city[]: regional
Foo(d) in Cambridge
Try it yourself: Open LIB_Function_regional.b4p in B4P_Examples.zip. Decompress before use.

See also

local
global