N Code Variables and Scoping Rules
Home ] Up ] N Code Execution Model ] N Code Language ] N Code Data Types ] N Code Expressions ] N Code Statements ] [ N Code Variables and Scoping Rules ] N Code Filters ] N Code Function Definition ] N Code Tools ] N Code Triggers ]


N Code Variables and Scoping Rules

Use an alphabetic as the first character, alpha and digits, and _ and :as other characters. (the ':' is intended to describe the scope of variables)

Variables are typed at run time. Typically they don't need to be declared before use. Variable names are limited to 128 characters in length.

Variables are global, except when prefixed with a '$' to make them local.

Examples: i, j, marcus:ranum

Local Variables

Are named by prefixing them with '$'. The value stays associated with the function for all iterations ... These behave like static variables. Unlike C static variables, local variables do not have initialization values.

Example:

func next {
if ($# > 0 ) {
$a = $1;
} else {
$a = $a + 1;
}
return($a);
}
echo( next(1), "\n" );
echo( next(), "\n" );
echo( next(), "\n" );
echo( next(), "\n");
echo( next(), "\n" );
echo( next(), "\n" );
echo( next(), "\n" );
echo( next(), "\n");
echo( next(), "\n" );
echo( next(), "\n");
echo( next(), "\n" );
echo( next(), "\n"
);

The example generates:

1
2
3
4
5
6
7
8
9
10
11
12

Global Variables

A global variable can be referenced by using 'global:name', but Another mechanism also exists to allow modification of global variables. A 'declare/global' statement allows the creation of a variable which exists for the duration of the local scope.

Attaching Variables To TCP Sessions

Each tcp session can collect a number of variables that will be Available to the scope of the procedure making the reference. All procedures in the same scope will be able to view the same variable.

To attach a variable to the tcp session, a declare/inside statement is included. That statement creates a variable, whose value is maintained by the tcp session. When that session closes, all the values of all the variables will be discarded. The tcp stack provides triggers which allow .NFR code to be executed before any of the variables are discarded due to a session close.

Example:

declare $someDataItem inside tcp.connSym;

This creates a variable, `$someDataItem', which is associated with the tcp session. Any procedure which shares the same scope can also make a reference to the same variable, to either view, or modify its contents.


Back ] Home ] Up ] Next ]