Download Definitional Programming in GCLA Techniques, Functions, and
Transcript
Functional Logic Programming in GCLA find functions and predicates and the code given in Figure 2 is generated without asking any questions. 6.4 Discussion If we use explicit quantification as in the example in Section 6.3 it is usually possible to divide the defined atoms into functions and predicates automatically, for most definitions it is even enough to use explicit quantification in the object functions only. It would of course be trivial to get rid of the entire splitting problem by introducing some kind of declarations, but we wish to keep our definitions free from this kind of external information. The rule-generation process is really very much like a kind of partial evaluation of a general rule definition like FL with respect to a certain definition and a given set of queries. An interesting question is if this process can be extended to more general classes of definitions as well. Another possibility to investigate is to unfold as many rule calls as possible thus minimizing the number of rule calls and increasing performance. When we generate rules according to the method local strategies, what we get is so to speak a basic procedural interpretation for each function and predicate. Since we have a distinct procedural part for each function and predicate it is very easy to manually alter the procedural behavior of a separate function or predicate. For example, given the definition member(X,[X|_]). member(X,[_|Xs]) <= member(X,Xs). the created rule member2_d_right will enumerate all instances of X in Xs. If we only want to find the first member somewhere in a program we can write another procedural part achieving this and substitute it for member2_d_right at the appropriate places. 7 Moving Information to the Rule Level Almost all our function definitions so far have contained some clause to force evaluation of arguments when necessary. If we want to have function definitions which by themselves explicitly describe the computations needed to evaluate a function this makes perfect sense and, as we have seen, it is possible to get by with very simple rule definitions. There is one major problem though, it is sometimes very complicated to define functions by pattern matching. We have not seen many examples of this but then we have avoided the problem by only writing function definitions where at most one argument has another pattern than a variable. When we try to define functions using pattern matching on several arguments we immediately run into problems, as seen below. 49