This version of Learn Prolog Now! embeds SWI SH , SWI-Prolog for SHaring. The current version rewrites the Learn Prolog Now! HTML on the fly, recognising source code and example queries. It is not yet good at recognising the relations between source code fragments and queries. Also Learn Prolog Now! needs some updating to be more compatible with SWI-Prolog. All sources are on GitHub:
LearnPrologNow LPN SWISH Proxy SWISH

1.3 Exercises

Exercise  1.1 Which of the following sequences of characters are atoms, which are variables, and which are neither?

  1. vINCENT
  2. Footmassage
  3. variable23
  4. Variable2000
  5. big_kahuna_burger
  6. ’big  kahuna  burger’
  7. big  kahuna  burger
  8. ’Jules’
  9. _Jules
  10. ’_Jules’

Exercise  1.2 Which of the following sequences of characters are atoms, which are variables, which are complex terms, and which are not terms at all? Give the functor and arity of each complex term.

  1. loves(Vincent,mia)
  2. ’loves(Vincent,mia)’
  3. Butch(boxer)
  4. boxer(Butch)
  5. and(big(burger),kahuna(burger))
  6. and(big(X),kahuna(X))
  7. _and(big(X),kahuna(X))
  8. (Butch  kills  Vincent)
  9. kills(Butch  Vincent)
  10. kills(Butch,Vincent

Exercise  1.3 How many facts, rules, clauses, and predicates are there in the following knowledge base? What are the heads of the rules, and what are the goals they contain?

woman(vincent).
woman(mia).
man(jules).
person(X):- man(X); woman(X).
loves(X,Y):- father(X,Y).
father(Y,Z):- man(Y), son(Z,Y).
father(Y,Z):- man(Y), daughter(Z,Y).

Exercise  1.4 Represent the following in Prolog:

  1. Butch is a killer.
  2. Mia and Marsellus are married.
  3. Zed is dead.
  4. Marsellus kills everyone who gives Mia a footmassage.
  5. Mia loves everyone who is a good dancer.
  6. Jules eats anything that is nutritious or tasty.

Exercise  1.5 Suppose we are working with the following knowledge base:

wizard(ron).
hasWand(harry).
quidditchPlayer(harry).
wizard(X):- hasBroom(X), hasWand(X).
hasBroom(X):- quidditchPlayer(X).

How does Prolog respond to the following queries?

  1. wizard(ron).
  2. witch(ron).
  3. wizard(hermione).
  4. witch(hermione).
  5. wizard(harry).
  6. wizard(Y).
  7. witch(Y).

eXTReMe Tracker
© 2006-2012 Patrick Blackburn, Johan Bos, Kristina Striegnitz