next up previous contents
Next: Type Constraints Up: Feature Structures, Types and Previous: TRALE-EXTENSION:TRALE Descriptions   Contents


Functional Descriptions

[Code]
ALE also provides the means to define functions mapping descriptions to descriptions. The syntax is:

  <func_def> ::= <func_spec> +++> <desc>.

  <func_spec> ::= <func_name>
                 | <func_name>(<seq(desc)>)
Functional descriptions are compiled into code that is evaluated at run-time, first adding to each argument (if any) the description given for that argument, and then evaluating to the resulting description, which can itself include other functional descriptions, including recursive calls. As an example, one may consider the append/2 function:
append([],L) +++> L.
append([X|L1],L2) +++> [X|append(L1,L2)].
The lists shown here are instances of ALE's list macro notation. Notice that the only type checking in this definition is performed by appropriateness and the list macro, so the first clause could succeed with any L. To add more, one could redefine the first clause as:
append([],(list,L)) +++> L.
Functional descriptions can be used wherever other descriptions can. The user should be particularly careful with ensuring that the arguments to a functional description call will be sufficiently instantiated for the call to terminate; and the clauses, correctly ordered for the description to terminate correctly. Type checking cannot ensure this, in general. For example, in the definition for append/2, with or without explicit type-checking on the second argument, both clauses will match a functional description whose first argument or any TL value in the first argument is strictly of type list, i.e., a list that is not known to be elist or nelist. Such a functional description will, thus, evaluate to an infinite number of results. Clauses in functional descriptions are considered in the order they are given; and the search for solutions always backtracks into subsequent clauses.

Any functional description that can be defined so that its argument descriptions are only variables, and its result has no (mutual) recursion should be defined as a macro instead, which is completely expanded at compile-time. Remember, however, that it is not always sufficient to replace the +++> with macro: variable replacement in macros works by true textual replacement, whereas the variables in functional descriptions are ALE descriptions. For example, the functional description:

foo(X) +++> (bar,f:X,g:X).
evaluates to a feature structure with a re-entrancy. The macro:
foo(X) macro (bar,f:X,g:X).
does not necessarily evaluate to a feature structure with a re-entrancy. The functional description, foo/1 is correctly converted to the macro:
foo(X) macro (bar,f:(Y,X),g:(Y,X)).
The ALE variable, Y, establishes the re-entrancy that the macro variable, X, does not.


next up previous contents
Next: Type Constraints Up: Feature Structures, Types and Previous: TRALE-EXTENSION:TRALE Descriptions   Contents
TRALE User's Manual