NET/MASTER Network Control Language (NCL) Programmer's Guide
Getting Started With Functions
An NCL Tutorial
3–22 106160 Tandem Computers Incorporated
Getting Started With
Functions
The examples in this section have focused on NCL procedures. This subsection
discusses functions.
An NCL procedure is a sequence of NCL statements that performs a task and,
optionally, returns a result. For example, an NCL procedure can display a message
such as “hello, world” in various ways.
Functions also perform tasks, but do so in a much more limited way than NCL
procedures. Functions are designed for one specific kind of task: taking a list of
values (called arguments or parameters) and returning a single value. The value is
used to evaluate the expression from which the function is called.
When you call a function, you use its name, optionally followed by a list of parameters
that must be enclosed in parentheses (( )). You must be careful not to include a space
between the name of the function and the opening parenthesis ((); if you do, NCL
does not recognize the function. Parameters in the list are separated by commas (,).
Spacing between parameters in the parameter list is not important.
NCL is distributed with a range of functions, called built-in functions. You can also
write your own functions using NCL. These are called user-written functions. This
subsection introduces built-in functions and then looks at user-written functions.
Refer to the NonStop NET/MASTER NCL Reference Manual for a complete description of
all the built-in functions distributed with NonStop NET/MASTER MS.
The BUILTIN1 NCL
Procedure
The first NCL procedure we will create uses a single built-in function. The name of the
NCL procedure is BUILTIN1; the name of the built-in function is SUBSTR. BUILTIN1
is shown in the following listing:
builtin1: PROCEDURE
WRITE DATA=SUBSTR( "hello, world", 1, 5 )
END builtin1
Follow the steps described earlier in this section to create, test compile, correct, and
execute BUILTIN1. When executed, this NCL procedure displays the following
message in the OCS message display area:
hello
The BUILTIN1 NCL procedure uses the WRITE verb to illustrate the use of the
SUBSTR built-in function.
Features of BUILTIN1 Here are some of the features of the BUILTIN1 NCL procedure.
The SUBSTR Built-in Function
SUBSTR is the name of a built-in function used to extract a substring from a string of
characters.
In BUILTIN1, three parameters are passed to the SUBSTR built-in function. The first
parameter is the string from which to extract the substring: in this case,