Prolog Workshop 5: Facts, Queries and Databases
Getting Started:
We are going to use online Suite ¡°SWISH¡± http://lcas.lincoln.ac.uk/swish/
You can also download a complete copy of the book Mastering Prolog by Rob Lucas
(also available on Blackboard).
Please read Chapter 1 of this book and attempt the following exercises.
Exercises:
1. Create a new empty program in Prolog (click ¡°Program¡± based on ¡°Empty¡± Profile):
Add some simple facts to the Prolog database (on the left-hand side), then use queries to access the database. For example:
man(adam).
man(aristotle).
Perform a query like man(X).
Using the following query, try to understand how the backtracking mechanism
of Prolog works (hint: see pages 25-26 of the book).
man(X), write(X), nl, fail.
2. Now extend the knowledge base to set up the car database, as explained in Section 1.7 of the book. Work through this section and carry out the exercises in Exercises 1b. In particular, make sure you understand how the predicate not(Man1 = Man2) works on page 29.
3. Add suppliers to the car database, as explained in Section 1.8. Work through this section and carry out the exercises in Exercises 1c. Again, play close attention to how the backtracking mechanism is working here, and make sure you understand how variables in your queries are matched to constants in the database (you could try execution tracing by prefix your query with trace, e.g. trace, man(X). , as explained on page 37). Save a copy of the car database ready for the next workshop by copying the content of the editor in the web service into a text file.
When you have finished, please present your answers to the Demonstrator.