Example 4–12 procedure that returns a value – Compaq DEC Text Processing Utility AA-PWCBD-TE User Manual
Page 94
Lexical Elements of the DEC Text Processing Utility Language
4.9 Reserved Words
•
If the error is not due to you pressing Ctrl/C, the error message is written
to the message buffer and DECTPU performs the equivalent of the following
sequence:
special_error_symbol := 0;
LEARN_ABORT;
RETURN (FALSE);
In a procedure with a case-style error handler, an ABORT statement produces
the same effect as the sequence Ctrl/C, with one exception: an ABORT statement
in the TPU$_CONTROLC clause of a case-style error handler does not reinvoke
the TPU$_CONTROLC clause, as is the case when Ctrl/C is pressed while
TPU$_CONTROLC is executing. Instead, an ABORT statement causes DECTPU
to exit from the error handler and look for a TPU$_CONTROLC selector in
the procedures or program (if any) in which the current procedure is nested. If
DECTPU does not find a TPU$_CONTROLC selector in the containing procedures
or program, DECTPU places the message associated with TPU$_CONTROLC in
the message buffer.
4.9.4.17 Ctrl/C Handling
The ability to trap a Ctrl/C in your DECTPU program is both powerful and
dangerous. When you press Ctrl/C, you usually want the application that is
running to prompt for a new command. The ability to trap the Ctrl/C is intended
to allow a procedure to clean up and exit gracefully.
4.9.4.18 RETURN Statement
The RETURN statement causes a return to the procedure that called the current
procedure or program. The return is to the statement that follows the statement
that called the current procedure or program. You can specify an expression after
the RETURN statement and the value of this expression is passed to the calling
procedure.
Syntax
RETURN expression;
The expression is optional; if it is missing, DECTPU supplies a 0. Also,
the RETURN statement itself is optional. That is, if DECTPU reaches the
endprocedure of a procedure before encountering a RETURN statement, it will
return 0.
Example 4–12 shows a sample procedure in which a value is returned to the
calling procedure.
Example 4–12 Procedure That Returns a Value
PROCEDURE user_get_shift_key
LOCAL key_to_shift;
! Keyword for key pressed after shift key
SET (SHIFT_KEY, LAST_KEY);
key_to_shift := KEY_NAME (READ_KEY, SHIFT_KEY);
RETURN key_to_shift;
ENDPROCEDURE;
In addition to using RETURN to pass a value, you can use a 1 (true) or a 0 (false)
with the RETURN statement to indicate the status of a procedure. Example 4–13
shows this usage of the RETURN statement.
4–28 Lexical Elements of the DEC Text Processing Utility Language