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

Getting Started With Functions
An NCL Tutorial
106160 Tandem Computers Incorporated 3–23
“hello, world.” The second parameter is a number, indicating the character at which
to begin the extraction—1, in this case, means the first character of the string, which is
the letter “h” in this example. The third parameter is also a number, indicating the
number of characters to extract from the string—5, in this case, means five characters,
which are the letters “h,” “e,” “l,” “l,” and “o” in this example.
Displaying the Results of a Function Using the WRITE Verb
Recall that the DATA keyword of the WRITE verb must be followed by an expression
containing the text of a message. In addition, recall that functions are called from
expressions and that the result of a function is used as part of expression evaluation.
When NCL encounters an expression in a statement, it evaluates the expression and
then uses the result. In BUILTIN1, the result of the built-in function is the substring
“hello.” Accordingly, the WRITE verb displays “hello” in the OCS message display
area.
The BUILTIN2 NCL
Procedure
NCL has many built-in functions that you can use to perform a variety of operations.
To illustrate the use of some more built-in functions, let us a create an NCL procedure
called BUILTIN2, as shown in the following listing:
builtin2: PROCEDURE
WRITE DATA="Builtin ABBREV: "ABBREV( "hello, world", he, 2 )
WRITE DATA="Builtin C2X: "C2X( "hello, world" )
WRITE DATA="Builtin CENTER: "CENTER( "hello, world", 24, "*" )
WRITE DATA="Builtin LENGTH: "LENGTH( "hello, world" )
WRITE DATA="Builtin UPPER: "UPPER( "hello, world" )
END builtin2
Follow the steps described earlier in this section to create, test compile, correct, and
execute HELLO2. When executed, the NCL procedure displays the following
messages in the OCS message display area:
Builtin ABBREV: 1
Builtin C2X: 68656C6C6F2C20776F726C64
Builtin CENTER: ******hello, world******
Builtin LENGTH: 12
Builtin UPPER: HELLO, WORLD
BUILTIN2 performs various operations on “hello, world.”
Features of BUILTIN2 Here are some of the features of the BUILTIN2 NCL procedure.
The ABBREV Built-in Function
The ABBREV built-in function performs a test of whether a string of characters is a
valid abbreviation of another string of characters. The result is a Boolean value: either
1 if the test is TRUE or 0 if the test is FALSE. In BUILTIN2, the result of the test is 1
(TRUE) because the string “he” matches the first two characters of the string “hello,
world.”