CIS 554 -- Prolog Quiz Name __________________________________

  1. (2 points) Write a Prolog predicate last that you can use to find the last element of a list. It declares that the second parameter is the last element of the list given as the first parameter. The predicate should fail if given an empty list. (Hint: two clauses.)

    last([A], A).                     //  last([A | []], A). also works.
    last([_ | A], B) :- last(A, B).

  2. (1 point) Call your last predicate to find the last element in the list [a, b, c].
    last([a, b, c], X).

  3.  (1 point) What will be the value of X after you call your function as last(X, c).  ?
    [c]               //  1/2 point for c

  4. (1 point) Help the prisoner to escape!
       dynamic locked/1.
       escape :- locked(cell_door), !, write('You are locked in!'), nl, fail.
       escape :- write('You are free!'), nl.
    Do it by completing the following clause:

         pick_lock :- retract(locked(cell_door)).
                   or retract((locked(cell_door))).

  5. (1 point) Briefly define the term "homoiconic."

    The same syntax is used for both program and data.

  6.  (1 point) Turn the following into logical (not Prolog) clause form:
    female(X) ∧ rich(X) ⇒ loves(john, X).

    ¬female(X) ∨ ¬rich(X) ∨ loves(john, X)

  7.  (1 point) Circle the logical statements that, when turned into clause form, require a Skolem function:

         ∀x∀y, p(x, y)      ∀x∃y, p(x, y)       ∃x∀y, p(x, y)       ∃x∃y, p(x, y)

  8. (1 point) How do you indicate a "commit point" in Prolog?     !

  9. (1 point) State the resolution principle.

  10. X ∨ some-literals
    ¬ X ∨ some-other-literals
    some-literals ∨ some-other-literals