Skip to main content

Getting Started

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

Abstract

This chapter shows how to write simple Prolog programs, load them into the Prolog database and enter goals that can be evaluated using them. It also introduces basic terminology and the different types of data object (terms).

After reading this chapter you should be able to:

  • Write and load a simple Prolog program

  • Enter goals at the Prolog system prompt

  • Understand the basic terminology of the Prolog language

  • Distinguish between different types of term (data objects)

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 1

Practical Exercise 1

Specimen solutions to all the Practical Exercises are given in Appendix 3.

  1. (1)

    Create a disk file animals.pl containing Animals Program 1 (leaving out the comments). Start up Prolog and load your program.

Test your program with the queries given in the text and some others of your own.

  1. (2)

    Write a program to put facts indicating that a lion, a tiger and a cow are animals into the database and to record that two of them (lion and tiger) are carnivores.

Save your program to a disk file and load it. Check that the database is correct using listing.

Enter goals to test whether:

  1. (a)

    there is such an animal as a tiger in the database

  2. (b)

    a cow and a tiger are both in the database (a conjunction of two goals)

  3. (c)

    a lion is an animal and also a carnivore

  4. (d)

    a cow is an animal and also a carnivore.

  1. (3)

    Try to predict what Prolog will output in response to each of the following goals, and then try them.

  • ?-write(hello).

  • ?-write(Hello).

  • ?-write('Hello!').

  • ?-write('Hello!'),nl.

  • ?-100=100.

  • ?-100=1000/10.

  • ?-100 is 1000/10.

  • ?-1000 is 100*10.

  • ?-2 is (5+7)/6.

  • ?-74 is (5+7)*6.

Rights and permissions

Reprints and permissions

Copyright information

© 2013 Springer-Verlag London

About this chapter

Cite this chapter

Bramer, M. (2013). Getting Started. In: Logic Programming with Prolog. Springer, London. https://doi.org/10.1007/978-1-4471-5487-7_1

Download citation

  • DOI: https://doi.org/10.1007/978-1-4471-5487-7_1

  • 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