Skip to main content

Changing the Prolog Database

  • Chapter
  • First Online:
Logic Programming with Prolog
  • 3282 Accesses

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

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Practical Exercise 8

Practical Exercise 8

  1. (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. (2)

    Define and test a predicate display_animals which lists the names of all the animals in the database, one per line.

  3. (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

Reprints 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)

Publish with us

Policies and ethics