FUNCTION DECLARATIONS
Introduction
The CAWI language can be extended by the writing functions in the native language used by particular implementations. For XCAWI2, this is Perl and in CAPMI this is Javascript.
There are also some functions which exist in the XCAWI2 or CAPMI standard libraries which are not declared as part of the core language.
To use one of these functions in the ROUTE section, its name and return type must be declared in the DSC script.
:::tip Note
The standard library of core functions in the CAWI language do NOT need to be explicitly declared before you can use them.
:::
These declarations can appear anywhere outside the ROUTE and PRINTNG sections, but a FUNCTION declaration will end the previous section. They are typically included just before the start of the ROUTE section (after the end of VARIABLES).
Syntax
'FUNCTION' IDENTIFIER 'RETURNS' TYPE-NAME
Where:
- IDENTIFIER is the name of the function
- TYPE-NAME is the return type of the function.
Valid values for TYPE-NAME are:
- INTEGER
- DECIMAL
- FLOAT
- TEXT
- STRING
- OPENTEXT
- DATE
- TIME
- The name of a question domain defined in
DEFINITIONS
Examples
VARIABLES
i : INTEGER
s : STRING
FUNCTION myfunc RETURNS INTEGER
FUNCTION myotherfunc RETURNS STRING
ROUTE
i = myfunc()
s = myotherfunc(i, 53)