Facts may have a functional expression attached to them. This is the way we incorporate functional programming into Milord II. A fact with such an expression attached to it will get its value as the result of the evaluation of the expression.
Possible applications of fact functions could be: interfaces with other programs (windows, networks, statistics, etc), or procedural computations.
Figure 7: Syntax of function definition.
The function attribute (see Figure 7) of a fact is programmed in Common Lisp with some extensions, it is a S-expression. This S-expression is considered to be evaluated inside an environment that contains variables, with the same name of the facts declared into a module, bound to the fact's value. It means that any fact name appearing in a S-expression will be considered as a local variable and its evaluation will return the current fact value.
The meaning of the two Milord II predefined functions is:
It is necessary to know the internal representation of the values of facts depending on their type. This is useful to manipulate the values of facts in a function attribute and to know which is the value format that a function must return depending on the type of the fact that contains it. We remind you that a fact with a functional expression attached to it will have the result of the evaluation of such expression as value.
Now we can see an example of function declaration of the Terap-IA\ [6] application. The value of the clearance_of_creatinina can be obtained by means of the following expression.
We can see the declaration of the fact creat_clear that contains a function attribute to compute its value.
Creat_clear= Name: "Clearance of creatinina" Type: numeric Function: (let* ((true (first (linguistic_terms))) (male (equal (second (first sex)) (list true true)))) (- 140 (/ (* age weight (if male 1.0 0.8)) 72)))
In this function age and weight are numeric facts, and sex is a set fact of type (male, female).