The CALL_FUNCTION and CALL_PROCEDURE routines are used to indirectly call functions and procedures whose names are contained in strings. Although not as flexible as the EXECUTE function (see the following page), CALL_FUNCTION and CALL_PROCEDURE are much faster, and should be used in preference to EXECUTE whenever possible.
This example code fragment, taken from the routine SVDFIT, calls a function whose name is passed to SVDFIT via a keyword parameter as a string. If the keyword parameter is omitted, the function POLY is called.
;Function declaration.
FUNCTION SVDFIT,..., FUNCT = funct
...
;Use default name, POLY, for function if not specified.
IF N_ELEMENTS(FUNCT) EQ 0 THEN FUNCT = 'POLY'
;Make a string of the form "a = funct(x,m)", and execute it.
Z = EXECUTE('A = '+FUNCT+'(X,M)')
...
The above example is easily made more efficient by replacing the call to EXECUTE with the following line:
A = CALL_FUNCTION(FUNCT, X, M)