Compiling Procedures and Functions
There are three ways procedures and functions can be compiled:
Using .RUN with a filename
Compiling automatically
Compiling with interactive mode
Using .RUN with a Filename
Procedures and functions can be compiled using the executive command .RUN. The format of this command is:
.RUN file1, file2, ...
From one to ten files, each containing one or more program units, may be compiled with the .RUN command. Consult Executive Commands in the PV‑WAVE Reference for more information on the .RUN command.
Compiling Automatically
Generally, however, you create a procedure or function file with a filename that matches the actual procedure or function name. Then you do not need to use .RUN to compile the procedure or function file if this file is in the current working directory, PV-WAVE library directory, or in the !Path directory. The procedure or function automatically compiles when first called. For example, a function named CUBE which calculates the cube of a number has the file name cube.pro. The file looks like this:
FUNCTION CUBE, NUMBER
RETURN, NUMBER ^ 3
END
When the function is initially used within a PV-WAVE session the file is automatically compiled. A compiled module message displays on the screen. For example, using the function for the first time at the WAVE> prompt results in:
WAVE> z = cube(4) & print, z
% Compiled module: CUBE
64
If you change the source file of a routine that is currently compiled in memory, then you have to explicitly recompile it with .RUN or .RNEW.
Compiling with Interactive Mode
You can enter the procedure or function text directly at the keyboard (interactively) by simply entering .RUN in response to the
WAVE> prompt. Rather than executing statements immediately after they are entered, PV-WAVE compiles the program unit as a whole. See
"Creating and Running a Function or Procedure".
Procedure and function definition statements may not be entered in the single statement mode but must be prefaced by either .RUN or .RNEW when being created interactively.
The first non-empty line the compiler reads determines the type of the program unit: procedure, function, or main program. If the first non-empty line is not a procedure or function definition, the program unit is assumed to be a main program.
The name of the procedure or function is given by the identifier following the keyword Pro or Function. If a program unit with the same name is already compiled, it is replaced by the newer program unit.
Note Regarding Functions
User-defined functions must be compiled using the .RUN command before the first reference to the function is made. There are two exceptions:
As discussed previously in
"Compiling Automatically", if the filename is the same as the function name and is located in the current working directory or in the !Path directory, the file automatically compiles.
The file is located in the PV-WAVE library directory.
Otherwise the function must be compiled using .RUN because the compiler is unable to distinguish between a reference to a subscripted variable and a call to a presently undefined user function with the same name. For example, in the statement:
A = XYZ(5)
it is impossible to tell if XYZ is an array or a function by context alone.
Always compile the lowest-level functions (those that call no other functions) first, then higher-level functions, and finally procedures. PV-WAVE searches the current directory and then those in the directory path (!Path) for function definitions when encountering references that may either be a function call or a sub- scripted variable, thereby avoiding this restriction in the case of library functions.