- [Pts 2]
Consider the following program computing the reverse of a list with the method of
the accumulator:
rev(L,M) :- aux(L,M,[]).
aux([],Acc,Acc).
aux([X|L],M,Acc) :- aux(L,M,[X|Acc]).
What is the result produced by the query ?- aux([1,2,3],M,[4,5]). ?
(only one answer, please)
- error
- M = [1,2,3,4,5]
- M = [3,2,1,4,5]
- M = [3,2,1,5,4]
- [Pts 2]
Consider the standard way of representing trees in logic programming,
and the following definition of a predicate p:
p(leaf(X),1).
p(node(T1,X,T2),N) :- p(T1,N1),
p(T2,N2),
N is N1 + N2 + 1.
Consider now the query ?- p(t,N). where t is a term representing
a certain tree.
What is the result returned by it? (only one answer, please)
- N is the height of t
- N is the number of all the nodes in t
- N is the number of all the nodes in t plus 1
- N is the number of all the nodes on the frontier of t
- [Pts 2]
Consider the Prolog query ?- X is 1+Y, Y = 2+3. What is the result returned by it? (only one answer, please)
- error
- X = 6 Y = 5
- X = 6 Y = 2+3
- X = 1+2+3 Y = 2+3
- [Pts 2] Consider the Prolog query ?- not(X=Y).
What is the result returned by it?
(only one answer, please)
- [Pts 2] Assume given the following Prolog program:
nat(0).
nat(N) :- nat(M), N is M+1.
Consider now the
query ?- nat(N), N is N + N. What is the result returned by this query?
(only one answer, please)
- no
- yes
- error because N and N + N cannot be unified
- N = 0; and then the computation enters an infinite loop