DEFFUN

Top  Previous  Next

 

The DEFFUN statement defines a function.

 

 

Format

 

DEFFUN name {(arg1 {,arg2 ...})} {CALLING "subr" | LOCAL} {VAR.ARGS} {KEY key}

 

where

 

nameis the name of the function.

 

arg1, arg2...are the function arguments.

 

subris the catalogue name of the subroutine if different from name.

 

keyis a key value to be passed into the subroutine as described below.

 

 

The DEFFUN statement defines a function that may be called from within the program. The DEFFUN statement must appear before the first reference to the function. If the function name matches the name of a built in function, any references to name before the DEFFUN will call the intrinsic function and references after the DEFFUN will call the declared function.

 

If the LOCAL keyword is not present, the function must correspond to a catalogued item. A call to this function call is effectively translated to a call to a subroutine with an additional hidden first argument through which the result is returned. The optional CALLING component of the DEFFUN statement allows the catalogue name of the function to be different from the name of the function itself.

 

Use of the LOCAL keyword indicates that this function is internal to the program module and will be defined later in the source by use of the LOCAL FUNCTION statement.

 

The argument names used in the DEFFUN statement are for documentation purposes only and have no significance within the program except that the compiler counts them to verify correct use of the function. The variables used in the actual call to the function are determined by the use of the function. An argument may be defined to be a whole matrix in which case it should be prefixed by the keyword MAT in the DEFFUN argument list.

 

The function is used in the same way as the intrinsic functions described in this manual. Although it is not recommended, a function can update its argument variables.

 

The VAR.ARGS option indicates that compiler should not check the number of arguments in calls to the function. It is of use with functions that take variable length argument lists. This option cannot be used with local function.

 

The KEY option passes the key value as an additional argument before the first one named in calls to the function. This enables construction of multiple functions that call a single catalogued item with a mode key as the first argument. The !PCL() function provided in the BP file of the QMSYS account uses this feature to implement the various PCL functions defined in the SYSCOM PCL.H include record.

 

 

Example

 

DEFFUN MATMAX(MAT A)

DIM VALUES(100)

...

MAX = MATMAX(MAT VALUES)

 

The program fragment above uses the MATMAX() function to find the maximum value of all the elements of matrix VALUES.

 

 
See also:

FUNCTION, LOCAL