Compaq AA-PWCBD-TE Computer Accessories User Manual


 
Lexical Elements of the DEC Text Processing Utility Language
4.9 Reserved Words
4.9.4.5 Procedures That Return a Result
Procedures that return a result are called function procedures. Example 4–6
shows a procedure that returns a true ( 1 ) or false ( 0 ) value.
Note
All DECTPU procedures return a result. If they do not do so explicitly,
DECTPU returns 0.
Example 4–6 Procedure That Returns a Result
PROCEDURE user_on_end_of_line !test if at eol, return true or false
IF CURRENT_OFFSET = LENGTH (CURRENT_LINE) ! we are on eol
THEN
user_on_end_of_line := 1 ! return true
ELSE
user_on_end_of_line := 0 ! return false
ENDIF;
ENDPROCEDURE;
Another way of assigning a value of 1 or 0 to a procedure is to use the DECTPU
RETURN language statement followed by a value. See Example 4–13.
You can use a procedure that returns a result as a part of a conditional statement
to test for certain conditions. Example 4–7 shows the procedure in Example 4–6
within another procedure.
Example 4–7 Procedure Within Another Procedure
PROCEDURE user_nested_procedure
.
.
.
IF user_on_end_of_line = 1 ! at the eol mark
THEN
MESSAGE ("Cursor is at the end of the line")
ELSE
MESSAGE ("Cursor is not at the end of the line")
ENDIF;
.
.
.
ENDPROCEDURE;
4.9.4.6 Recursive Procedures
Procedures that call themselves are called recursive procedures. Example 4–8
shows a procedure named user_reverse that displays a list of responses to the
READ_LINE built-in procedure in reverse order. Note the call to the procedure
user_reverse within the procedure body.
4–18 Lexical Elements of the DEC Text Processing Utility Language