Gretl Manual: Gnu Regression, Econometrics and Time-series Library | ||
---|---|---|
Prev | Chapter 11. User-defined functions | Next |
Functions must be defined before they are called. The syntax for defining a function looks like this
function function-name function body end function
function-name is the unique identifier for the function. Names must start with a letter. They have a maximum length of 31 characters; if you type a longer name it will be truncated. Function names cannot contain spaces. You will get an error if you try to define a function having the same name as an existing gretl command, or with the same name as a previously defined user function.
The function body is composed of gretl commands, or calls to user-defined functions (that is, functions may be nested). A function may call itself (that is, functions may be recursive). There is a maximum "stacking depth" for user functions: at present this is set to 8 but I can increase it if this seems too limiting. While the function body may contain function calls, it may not contain function definitions. That is, you cannot define a function inside another function.
Functions may be called, but may not be defined, within the context of a command loop (see Chapter 10).