Caché MultiValue Basic Reference
[Back] [Next]
Go to:

Declares a user-defined function
DEFFUN name [(args)] [CALLING routine]
name The name of an existing user-defined function. This cannot be the name of any existing system-provided (built-in) function. Name validation is performed on name.
args Optional — An argument, or comma-separated list of arguments for the function. Arguments can be subscripted. If one or more arguments are specified, the enclosing parentheses are mandatory.
CALLING routine Optional — Used to map a identifier to a valid name. Either an identifier, or a quoted string literal that begins with the asterisk (*) character. No name validation is performed on routine.
The DEFFUN statement allows you to declare an existing user-defined function, placing it in the function lookup table. This operation only declares the function's name and argument list. Prior to invoking DEFFUN, the function must have been defined, using the FUNCTION statement.
The CALLING clause is commonly used to map an invalid function name (routine) to a valid user-defined function name (name). User-defined function names cannot begin with a punctuation character (except %); built-in function names often begin with a punctuation character. You can use a CALLING clause to map one to the other. In the optional CALLING clause, the routine name can be a quoted string literal function name beginning with an asterisk (*), as follows:
DEFFUN foo(x,y,z) CALLING "*foo"
In this example, DEFFUN allows calls to appear in expressions using the ordinary identifier foo, while the name *foo is passed to the runtime execution. The leading asterisk specifies how to look up this function name. In Caché MultiValue and most emulations, the asterisk is both part of the function name and an indicator specifying how to look up this function. In UniData emulation, the asterisk is removed from the function name and serves only as a lookup indicator. For further details, refer to the CALL statement.
The following example illustrates the use of the DEFFUN statement:
DEFFUN cuberoot(mynum,precision)
CRT cuberoot(mynum,precision)
See Also