Chapter 6. User-Defined Functions
APL provides an extensive set of primitive functions; nevertheless, you may want
a function to solve a special problem. APL provides a way to create a new func-
tion, called function definition. During function definition, you use existing APL
functions to create new functions called user-defined functions.
Normally, the 5100 is in execution mode; that is, after a line has been entered
and the EXECUTE key pressed, the 5100 executes that line. To define a func-
tion, the mode must be changed to function definition mode; after the function
is defined, the mode must be changed back to execution mode before the func-
tion can be executed. The mode is changed by entering the V (dell symbol. The
first V changes the mode to function definition mode; the second V indicates the
end of function definition and changes the mode back to execution mode.
MECHANICS OF FUNCTION DEFINITION
The following steps are required to define a new function:
1. Enter a V followed by the function header (see Function Header in this
chapter). After the function header is entered, APL responds with a
[I] and waits for the first statement of the function to be entered:
2. Enter the statements that define the operations to be performed by the
function. As each line is entered, APL automatically responds with the
next line number:
Mote: During function definition mode, the print width (see 0 PW system vari-
able in Chapter 5) is automatically set to 390. The print width returns to its
original value when the function is closed. This prevents problems that occur
when editing statements that exceed the print width. Editing statements are
discussed later in this chapter. If a user-defined function contains a statement
that is greater than 11 5 characters in length, that statement cannot be edited and
the function cannot be written on tape. (See OCR and OFX in Chapter 5 for
information on changing a user-defined function to a matrix.)
I
1 34
APL provides an extensive set of primitive functions; nevertheless, you may want
a function to solve a special problem. APL provides a way to create a new func-
tion, called function definition. During function definition, you use existing APL
functions to create new functions called user-defined functions.
Normally, the 5100 is in execution mode; that is, after a line has been entered
and the EXECUTE key pressed, the 5100 executes that line. To define a func-
tion, the mode must be changed to function definition mode; after the function
is defined, the mode must be changed back to execution mode before the func-
tion can be executed. The mode is changed by entering the V (dell symbol. The
first V changes the mode to function definition mode; the second V indicates the
end of function definition and changes the mode back to execution mode.
MECHANICS OF FUNCTION DEFINITION
The following steps are required to define a new function:
1. Enter a V followed by the function header (see Function Header in this
chapter). After the function header is entered, APL responds with a
[I] and waits for the first statement of the function to be entered:
2. Enter the statements that define the operations to be performed by the
function. As each line is entered, APL automatically responds with the
next line number:
Mote: During function definition mode, the print width (see 0 PW system vari-
able in Chapter 5) is automatically set to 390. The print width returns to its
original value when the function is closed. This prevents problems that occur
when editing statements that exceed the print width. Editing statements are
discussed later in this chapter. If a user-defined function contains a statement
that is greater than 11 5 characters in length, that statement cannot be edited and
the function cannot be written on tape. (See OCR and OFX in Chapter 5 for
information on changing a user-defined function to a matrix.)
I
1 34