Writing Procedures and Functions
A procedure or function is a self-contained module that performs a well-defined task. Procedures and functions break large tasks into manageable smaller tasks. Writing modular programs simplifies debugging and maintenance and minimizes the amount of new code required for each application.
New procedures and functions may be written in PV-WAVE and called in the same manner as the system-defined procedures or functions (i.e., from the keyboard or from other programs). When a procedure or function is finished, it executes a RETURN statement which returns control to its caller.
The following directory contains procedures and functions that can be accessed by all PV-WAVE users:
(UNIX) <wavedir>/lib/user
(WIN) <wavedir>\lib\user
Where <wavedir> is the main PV-WAVE directory.
note | This subdirectory is automatically placed in the environment variable or logical WAVE_PATH by the PV-WAVE initialization routine, and is also automatically placed in the system variable !Path. The user subdirectory is placed at the end of the search path and is thus searched last. For more information on the search path, see
Modifying Your Environment. |
PV-WAVE automatically compiles and executes a user-written function or procedure when it is first referenced if:
The source code of the routine is in the current working directory or in a directory in the search path defined by the system variable !Path.
The name of the file containing the routine is the same as the routine name suffixed by .
pro.
note | User-written functions must be compiled (e.g., with .RUN) before they are referenced, unless they meet the above conditions for automatic compilation. This restriction is necessary in order to distinguish between function calls and subscripted variable references. |
A procedure is called by a procedure call statement, while a function is called via a function reference. A function always returns an explicit result. For example, if ABC is a procedure and XYZ is a function:
ABC, A, 12
; Calls procedure ABC with two parameters.
A = XYZ(C/D)
; Calls function XYZ with one parameter. The result of XYZ is
; stored in variable A.
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.