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

Calling Procedures and Functions
Procedures and Functions
106160 Tandem Computers Incorporated 6–45
Calling a Function You can call a function only from within an expression. A call to a function can occur
whenever a value is required in an expression. The following example shows how a
function call returns a single result that is used to evaluate an expression:
zex0623n: PROCEDURE
/* Calling a function */
SAY "The mean is "mean(&SYS.ALLPARMS)
mean: FUNCTION
&count = 1
&total = 0
DO UNTIL ( &count > WORDS(&1) )
&total = &total + WORD(&1,&count)
&count = &count + 1
END
RETURN( &total / WORDS(&1) )
END mean
END zex0623n
This procedure obtains the mean of a series of numbers, which are entered as
parameters to the procedure when it is executed. The parameters are placed in the
system variable &SYS.ALLPARMS. The MEAN function analyzes &SYS.ALLPARMS
to determine each number, to calculate how many numbers there are, and to add up
all the numbers. The final result returned by the MEAN function is displayed by the
SAY statement.
The following screen shows the results of executing the procedure twice:
(14:04) --------------------- OPERATOR CONTROL SERVICES ----------------------
START ZEX0623N 15 3 17 21 32 75 4
The mean is 23.8571428571429
NNM1005 START ZEX0623N PROCESSING COMPLETE. NCLID 001154
START ZEX0623N 1 2 3 4 5 6 7 8 9 10
The mean is 5.5
NNM1005 START ZEX0623N PROCESSING COMPLETE. NCLID 001155
_____________________________________________________________________________
---------- ------------------ NonStop NET/MASTER D30 ---------------- --------
M=>
The values passed are: 15, 3, 17, 21, 32, 75, and 4; and 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.