PS TEXT FORMAT Reference Manual

Examples of Function and Macro Constructs
11387 Tandem Computers Incorporated G-3
\ASSIGN month_from ARG(1)
\ASSIGN day_from ARG(2)
\ASSIGN month_to ARG(3)
\ASSIGN day_to ARG(4)
\ASSIGN time 0
FUNCTION month_length BEGIN
RETURN SELECT(ARG(1),31,28,31,30,31,30,31,31,30,31,30,31)
ENDFUNCTION month_length
\
\
\
\FUNCTION span BEGIN LOCAL month_from,day_from,month_to,day_to,time
\ ASSIGN time time+(day_to-day_from)
\ RETURN time
\ENDFUNCTION span
2
3
1
5
4
\ LOOP month_to_month_from
\ ASSIGN time time+(month_length(month_from)-day_from)+1
\ ASSIGN day_from 1
\ ASSIGN month_from month_from+1
\ ENDLOOP
1 - The function’s name is “span” and five LOCAL variables are defined.
2 - The span function calls another function named month_length. The
month_length function returns to the span function the number of
days for a specified month.
3 - The values of the four arguments to the span function are assigned to
local variables using the TFORM ARG function. The variable time is
given the value of 0.
4 - This loop counts days from the beginning of the last month. The
month_length function is called. The day_from variable is set to –1,
then the month_from variable is assigned the value of month_from
plus 1.
5 - The time variable value is computed by adding the value of time to the
results of day_from subtracted from day_to. This value of time is
stored in span. When the function span is called, this value will be
substituted for span and its four arguments.