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)
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Practical Exercise 1
Practical Exercise 1
Specimen solutions to all the Practical Exercises are given in Appendix 3.
-
(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.
-
(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:
-
(a)
there is such an animal as a tiger in the database
-
(b)
a cow and a tiger are both in the database (a conjunction of two goals)
-
(c)
a lion is an animal and also a carnivore
-
(d)
a cow is an animal and also a carnivore.
-
(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
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)