FUNC

Summary


"func" is used to call a function that is executed with its own local variables with a return to the calling process.

Syntax

SYNTAX 1
func process.function ['(' args_list ')' ]
 
SYNTAX 2
func =Expression With ['(' args_list  ')' ]
 

Parameters

Element

Description

Restrictions

process

Process in which the function is defined (by default, it is the current function)

The process must be accessible.

function

Function name

Must correspond to a Subprog in the corresponding process.

expression

Expression of the type Char where the result is the name of the function or process.function

Syntax 2.

args_list

List of arguments separated by ','. These arguments can be variables or expressions.

None.

Examples

   # Call to the calculation X function in the ZETRT process
   # RESULT will give the number 22

Local Integer RESULT
RESULT = 4*(
funcZETRT.X(3,2) + 1)
End

   # the calculation X function in the ZETRT process 

Funprog X(A,B)
Value Integer A
Value Integer B
End A*A/B

    # another way of calling the function X for the ZETRT process

Local Integer RESULT
Local Char    PROC
PROC = "ZETRT.X" 
RESULT =
4*(func=PROC with (3,2))+1
End

Description and comments

"func" is used to launch a function with potentially a transfer of parameters. On completion of this execution, the calling process continues its execution with the instruction following the "func" instruction, and can use the result of the expression specified at the End of the function. The local variables for the function and the Objects opened by it in Local mode are re-closed.

When the call "func" is made without specifying the process, the function must be found in the process itself. Warning, when using the Evalue instruction in combination with the "func" instruction, the process must be specified. In fact, the Evalue instruction creates a pseudo process, in which the label of the " func" does not exist. 

The arguments passed in the "func" must be of an equal number to those of the function. The order of the parameters in "func" being matched to those in Funprog.

The arguments can be expressions or variables. If this is an expression, its passage MUST be made by value (Value); the Funprog argument must not be sized.

A variable passed in an argument can be dimensioned. It must then have the same dimension as the variable corresponding to the Funprog. Only part is transferred.

Example : either a grid of integers with 2 dimensions declared by :
Integer T2(I1..I2,J1..J2)
With I1 <= I11 <= I21 <= I2 et J1 <= J11 <= J21 <= J2

If func FUNCTION( T2 ) is carried out, all the grid is transferred.
If func FUNCTION( T2(I1..I2,J1..J2)) is carried out (identical).
If func FUNCTION( T2(I11,J1..J2)) is carried out only one "line" will be transferred.
If func FUNCTION( T2(I1..I2,J11)) is carried out, a "column".
If func FUNCTION( T2(I11,J11) is carried out, only one "element".
If func FUNCTION( T2(I11..I21,J1..J2)) is carried out, several "lines".
etc.

Remarks

During a "func", the following information is saved :

On the other hand these are lost :

During the execution of a "func", there is the creation of a class of local variables with the abbreviation function[L]. This local class becomes the default class, the local class for the calling process is then no longer accessible. On return to the process, the default local class is recovered, that existed prior to the call.

If during the execution of a "func" the default classes, the masks, the open files or dialogue boxes are modified, it is imperative to use the Local Mask, Local File, or Local ...Box instructions to carry this out. In fact, the instructions Mask, File and ...Box influence the open OBJects, which poses problems on the return from the "func".

A "func" can be called recursively, the number of overlapping "func" is not limited but it will be necessary to pay attention to the available memory, to the number of open OBJect and in particular, to the number of files open in Local mode because each function is viewed as independent.

Warning, the func function may not be used in a Where clause. 

Associated errors

Error

Description

PAFIC (20)

Non-existent process

ERDIM (55)

Incorrect number of dimensions.

ERARGNO (69)

Number of arguments declared in Funprog does not correspond to the number passed in func.

ERARGTY (70)

incompatible transfer mode.

ERLAB (39)

non existent function.

ERMODE (10)

exp_nomtrt is not a string of characters.

Associated keywords

FUNPROG - END  


SUMMARY


Copyright © Sage 1999 - 2007