Abstract
This chapter describes the built-in predicates for adding clauses to or deleting clauses from the Prolog database and shows how to use them to create and maintain a database of related facts within the overall Prolog database.
After reading this chapter you should be able to:
-
Define a predicate which causes one or more clauses to be added to or deleted from the Prolog database
-
Define predicates to create and manipulate a database of related facts within the Prolog database
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Practical Exercise 8
Practical Exercise 8
-
(1)
Define and test a predicate add_data which reads a series of names of animals (e.g. cat, dog, mouse) entered by the user, terminated by end. It should add a corresponding series of facts, e.g. animal(dog) to the Prolog database, ignoring any names that have already been entered.
-
(2)
Define and test a predicate display_animals which lists the names of all the animals in the database, one per line.
-
(3)
Define and test a predicate remove2 which removes any clauses corresponding to either a dog or a cat from the database, if they are present, and otherwise has no effect.
Rights and permissions
Copyright information
© 2013 Springer-Verlag London
About this chapter
Cite this chapter
Bramer, M. (2013). Changing the Prolog Database. In: Logic Programming with Prolog. Springer, London. https://doi.org/10.1007/978-1-4471-5487-7_8
Download citation
DOI: https://doi.org/10.1007/978-1-4471-5487-7_8
Published:
Publisher Name: Springer, London
Print ISBN: 978-1-4471-5486-0
Online ISBN: 978-1-4471-5487-7
eBook Packages: Computer ScienceComputer Science (R0)