Function Declarations

Syntax

FunctionDeclaration =
     "$func"   FunctionName
          InputFormat "=" OutputFormat ";" |
     "$func?"  FunctionName
          InputFormat "=" OutputFormat ";".
InputFormat = FormatExpression.
OutputFormat = FormatExpression.

FormatExpression = HardExpression.

Purpose

A function declaration introduces a function name. The declaration of a function must precede all references to the function as well as the definition of the function.

The declaration of a function imposes restrictions on the forms that can take the calls to the function, the input patterns in the function's definition and the result expressions producing the values returned by the function. These restrictions will be described in detail below.

The input and output formats must be hard, i.e. any subexpression of a format expression may contain no more than one e-variable or v-variable.

The variable indices appearing in formats serve as comments, thus they have no effect on the meaning of the program and may be omitted.

It should be noted that the format expressions and the hard expressions are considered to be different constructs, despite their having the same context-free syntax. This is due to the differences in the interpretation of variable indices.

If the declaration of a function begins with the key word $func, the function is an unfailing one, i.e. evaluating a call to the function may result in returning either a ground expression or an error.

If the declaration of a function begins with the key word $func?, the function is a failing one, i.e. evaluating a call to the function may result in returning either a ground expression, a failure, or an error.

Examples

$func  Interpreter (e.Program) (e.Input) = e.Result;
$func? Attempt t.Arg = s.Result1 t.Result2 (e.Result3);
Related concepts
Static and Dynamic Symbols
Function Names
Hard Expressions
Restrictions Imposed by Function Declarations