Negation and Control in Prolog
暂无分享,去创建一个
We investigate ways of bringing PROLOG closer to the ideals of logic programming, by improving its facilities for negation and control. The forms of negation available in conventional PROLOG systems are implemented unsoundly, and can lead to incorrect solutions. We discuss several ways in which negation as failure can be implemented soundly. The main forms of negation considered are not, not-equals, if-then-else and all solutions predicates. The specification and implementation of all solutions predicates is examined in detail. Allowing quantifiers in negated calls is an extension which is easily implemented and we stress its desirability, for all forms of negation. We propose other enhancements to current implementations, to prevent the computation aborting or looping infinitely, and also outline a new technique for implementing negation by program transformation. Finally, we suggest what forms of negation should be implemented in future PROLOG systems. The poor control facilities of conventional PROLOG lead to infinite loops and inefficiency. More flexible computation rules can often overcome these problems. We first introduce control primitives for database and recursive predicates, then show how control information can be generated automatically, using these primitives. Automatically reordering subgoals in clauses is also considered. This allows programmers to concentrate more on the logic of a problem, making programming simpler. We give examples using several different styles of programming. The implications of automatic control for the design of control primitives is also discussed. Next, we re-examine the theoretical foundations of PROLOG systems with flexible computation rules. The SLD resolution model is extended, to correct a previous over-simplification. The extension also brings to light a much greater flexibility of computation rules, which has previously been overlooked. A rule which behaves like intelligent backtracking is given as an example. Finally, we take an overview of the many approaches to control in PROLOG. Some general principles for evaluating and classifying control rules are given. These show the deficiencies of current systems more clearly. We make suggestions for future implementations of PROLOG with extra control facilities.