Skip to main content

2003 | Buch | 5. Auflage

Programming in Prolog

Using the ISO Standard

verfasst von: Prof. William F. Clocksin, Dr. Christopher S. Mellish

Verlag: Springer Berlin Heidelberg

insite
SUCHEN

Über dieses Buch

Originally published in 1981, this was the first textbook on programming in the Prolog language and is still the definitive introductory text on Prolog. Though many Prolog textbooks have been published since, this one has withstood the test of time because of its comprehensiveness, tutorial approach, and emphasis on general programming applications.

Prolog has continued to attract a great deal of interest in the computer science community, and has turned out to be a basis for an important new generation of programming languages and systems for Artificial Intelligence. Since the previous edition of Programming in Prolog, the language has been standardised by the International Organization for Standardization (ISO) and this book has been updated accordingly. The authors have also introduced some new material, clarified some explanations, corrected a number of minor errors, and removed appendices about Prolog systems that are now obsolete.

Inhaltsverzeichnis

Frontmatter
1. Tutorial Introduction
Abstract
Prolog is a computer programming language. Since its beginnings around 1970 Prolog has been chosen by many programmers for applications of symbolic computation, including:
  • relational databases
  • mathematical logic
  • abstract problem solving
  • understanding natural language
  • design automation
  • symbolic equation solving
  • biochemical structure analysis
  • many areas of artificial intelligence
William F. Clocksin, Christopher S. Mellish
2. A Closer Look
Abstract
In this chapter we provide a more complete discussion of the parts of Prolog that were introduced in the previous chapter. Prolog provides ways to structure data as well as ways to structure the order in which attempts are made to satisfy goals. Structuring data involves knowing the syntax by which we can denote data. Structuring the order in which goals are solved involves knowing about backtracking.
William F. Clocksin, Christopher S. Mellish
3. Using Data Structures
Abstract
This definition is cryptic and perhaps outdated. Recursion is now a very popular and powerful technique in the world of non-numerical programming. The idea of recursion is used in two ways. It can be used to describe structures that have other structures as components. It can also be used to describe programs that need to satisfy a copy of themselves before they themselves can succeed. Sometimes, beginners view recursion with some suspicion, because, how is it possible for some relationship to be defined in terms of itself? In Prolog, recursion is the normal and natural way of viewing data structures and programs. We hope that the theme of this chapter recursion, will be made explicit in a comfortable and unobtrusive way.
William F. Clocksin, Christopher S. Mellish
4. Backtracking and the “Cut”
Abstract
Let us summarise what we learned in Chapters 1 and 2 about what can happen to a goal:
1.
An attempt can be made to satisfy a goal. When we satisfy a goal, we search the database from the top. Two things can happen:
a)
A unifying fact (or rule head) can be found. In this case, we say the goal has been matched. We mark the place in the database, and instantiate any previously uninstantiated variables that have unified. If we matched against a rule, we shall first have to attempt to satisfy the subgoals introduced by the rule. If the goal succeeds, we then attempt to satisfy the next goal. In our diagrams, this is the goal in the next box below the arrow. If the original goal appears in a conjunction, this will be the goal to its right in the program.
 
b)
No unifying fact (or rule head) can be found. In this case, we say the goal has failed. We then attempt to re-satisfy the goal in the box above the arrowhead. If the original goal appears in a conjunction, then this will be the goal on its left in the program.
 
 
2.
We can attempt to re-satisfy a goal. First of all, we attempt to re-satisfy each of the subgoals in turn, the arrow retreating up the page. If no subgoal can be re-satisfied in a suitable way, we attempt to find an alternative clause for the goal itself. In this case, we must make uninstantiated any variables that became instantiated when the previous clause was chosen. This is what we mean by “undoing” all the work previously done by this goal. Next, we resume searching the database, but we begin the search from where the goal’s place-marker was previously put. As before, this new “backtracked” goal may either succeed or fail, and either step (a) or (b) above would occur.
 
William F. Clocksin, Christopher S. Mellish
5. Input and Output
Abstract
Thus far, the only means we have seen of providing information to a Prolog program has been by asking questions of the Prolog system. Also, the only method of finding out what a variable stands for at some point in the satisfaction of a goal has been by asking a question in such a way that Prolog will display the answer in the “X = answer” form. Much of the time, such direct interaction with questions is all that is required to ensure that a program is working properly. However, for many occasions it is useful to write a Prolog program that initiates a conversation with you by itself.
William F. Clocksin, Christopher S. Mellish
6. Built-in Predicates
Abstract
In this chapter we introduce some of the built-in predicates that a Prolog system might provide. What do we mean when we say that a predicate is built-in?We mean that the predicate’s definition is provided in advance by the Prolog system, instead of by your own clauses. Built-in predicates may provide facilities that cannot beobtained by definitions in pure Prolog. Or they may provide convenient facilities just to save the programmer from having to define them. We have already encountered some built-in predicates: the predicates for reading and writing discussed in Chapter5. Also, the “cut” can be regarded as a built-in predicate.
William F. Clocksin, Christopher S. Mellish
7. More Example Programs
Abstract
Each section of this chapter deals with a particular application of Prolog programming. We suggest that you read all of the sections in this chapter. Do not be concerned if you do not understand the purpose of a program because you are not acquainted with the particular application. For example, only those readers who have been introduced to Calculus will appreciate the value of symbolic differentiation. Read it anyway, because the program for finding symbolic derivatives demonstrates how to use pattern matching to transform one kind of structure (an arithmetic expression) into another one. What is important is to gain an understanding of programming techniques available to the Prolog programmer, regardless of the particular application.
William F. Clocksin, Christopher S. Mellish
8. Debugging Prolog Programs
Abstract
By his point you will have used and modified many of the example programs described earlier, and you will have written programs of your own. It is now relevant to consider what to do when your program does not behave as intended. Such problems with programs are known as “bugs”, and the process of removing bugs from programs is known as “debugging”. We believe that a convenient approach to programming is what could be described as “preventative programming”. To paraphrase an old proverb, “an ounce of careful programming is worth a pound of debugging”.In this chapter we shall attempt to describe some techniques for debugging, but we shall start with a discussion of how to try to prevent bugs from infesting your programs.We realise that such a problem is unsolved in general, but we simply wish to convey some informal techniques that have helped other Prolog programmers.
William F. Clocksin, Christopher S. Mellish
9. Using Prolog Grammar Rules
Abstract
Sentences in a language such as English are much more than just arbitrary sequences of words. We cannot string together any set of words and make a reasonable sentence. At the very least, the result must conform to what we consider to be grammatical.
William F. Clocksin, Christopher S. Mellish
10. The Relation of Prolog to Logic
Abstract
The programming language Prolog was invented by Alain Colmerauer and his associates around 1970. It was the first attempt at the design of a practical programming language that would enable a programmer to specify tasks in logic, instead of in terms of conventional programming constructs about what the machine should do when. This motivation explains the name of the language, for “Prolog” means Programming in Logic.
William F. Clocksin, Christopher S. Mellish
11. Projects in Prolog
Abstract
This chapter contains a list of projects that you may wish to undertake in order to exercise your programming ability. Some of the projects are easy, but some may be appropriate as “term projects” as a part of a course in Prolog. The easier projects should be used to supplement the exercises in the previous chapters. The projects are in no particular order, although those in Section 11.2 are more open ended and ambitious, and will require some knowledge or background reading in various areas of artificial intelligence and computer science. A few of the projects assume knowledge about some particular field of study, so if you are not a mathematical physicist, do not feel discouraged if you cannot write a program to differentiate three dimensional vector fields.
William F. Clocksin, Christopher S. Mellish
Backmatter
Metadaten
Titel
Programming in Prolog
verfasst von
Prof. William F. Clocksin
Dr. Christopher S. Mellish
Copyright-Jahr
2003
Verlag
Springer Berlin Heidelberg
Electronic ISBN
978-3-642-55481-0
Print ISBN
978-3-540-00678-7
DOI
https://doi.org/10.1007/978-3-642-55481-0