Quiz Stuff

Quiz 12; April 18, 2018; 4'; ½ point per answer; 3 points total

  1. What are the names of the four ports of the port model for goal evaluation that we've discussed? Hint: Here's the first letter of each: c, e, r, f (½ point for all four)
  2. We think of backtracking as moving through the goals of a query or rule in a particular direction. What is that direction?
  3. For each of the following queries, indicate whether they succeed or fail.
    ?- length([1,2,3],Len).
    ?- append(A,B,[1,2,3]), writeln(A), fail.
    ?- member(X,[1,2,3]), member(X,[3,4,5]).
    
  4. Write a predicate p(N) that prints the numbers between 1 and N inclusive. It always succeeds.
    ?- p(3).
    1
    2
    3
    true.
    

Answers

  1. What are the names of the four ports of the port model for goal evaluation that we've discussed?
    call, exit, redo, fail
  2. We think of backtracking as moving through the goals of a query or rule in a particular direction. What is that direction?
    right to left
  3. For each of the following queries, indicate whether they succeed or fail.
    ?- length([1,2,3],Len).
    Len = 3.
    
    ?- append(A,B,[1,2,3]), writeln(A), fail.
    []
    [1]
    [1,2]
    [1,2,3]
    false.
    
    ?- member(X,[1,2,3]), member(X,[3,4,5]).
    X = 3 .
    
  4. Write a predicate p(N) that prints the numbers between 1 and N inclusive.
    p(Max) :- between(1,Max,N), writeln(N), fail.
    p(_).