NET/MASTER Network Control Language (NCL) Programmer's Guide

Getting Started With Functions
An NCL Tutorial
106160 Tandem Computers Incorporated 3–25
CUBE executes the NCL statements in the function declaration. The purpose of CUBE
is to produce the cube of a number. There is no built-in function that performs this
task.
The CUBE: Label
You must name a user-written function with a label. “CUBE:” at the beginning of the
function is a label. The label is used to call the function.
The FUNCTION Core Statement
FUNCTION marks the beginning of the user-written function. It is used to explicitly
declare a function. Every FUNCTION statement must have a corresponding END
statement that terminates the function declaration.
The CUBE user-written function is called a nested function because its declaration is
inside the declaration of an NCL procedure. You can also nest NCL procedures inside
functions, NCL procedures inside other NCL procedures, and functions inside other
functions. You can nest NCL procedures and functions to a maximum of 256 levels.
The RETURN Core Statement
A function must have a RETURN statement, returning the result of the function to the
expression from which the function was called. The RETURN statement in a function
must enclose the result in parentheses (( )).
In USERW1, the result of the function is the value of the expression (2**3). 2 is a
number, the double asterisks (**) represent the exponentiation operator, and the
number 3 is the power to which to raise the number 2. The result is 8.
In USERW1, the result of the function is returned to the expression following the
DATA keyword of the WRITE verb.
The END Core Statement
END marks the end of the user-written function. Every FUNCTION statement must
have a matching END statement.
The CUBE Label
CUBE at the end of the function is a label. Including it after the END core statement is
not required but is good practice. It lets the compiler check that the label at the end of
the function matches the label at the beginning of the function. When a label follows
END, it does not require the colon (:).