Functions: pre-defining

Function pre-definitions

  • allow function interfaces to be described separately from function implementations, and
  • support mutually recursive functions.

Functions must be defined or pre-defined before they are used. For mutually recursive functions, one or more of the functions must be pre-defined prior to the first actual function definition. A pre-definition looks like a function definition, but using the keyword elsewhere instead of as, and no following function body:

  define function 
     sort-by-value      read-only  string original
                   into modifiable string sorted

In general the properties of the function arguments in a pre-definition must match those in the function definition. The exceptions are:

  • the argument names in elsewhere definitions are placeholders, and can have different names when the function is defined, and
  • the predefinition should not specify initial values for the optional arguments, and the initial values should only be specified in the function definition.
On the second point, initial values are permitted in the pre-definition for backwards compatibility if the values are static, but this is discouraged.

Prerequisite Concepts