Tuesday, 12 May 2015

Q23,paper3 ,j 12. Which one of the following prolog programs correctly implement “if G succeeds then execute goal P else execute goal θ ?”


(A) if-else (G, P, θ) :- !, call(G), call(P). if-else (G, P, θ) :- call(θ).
(B) if-else (G, P, θ) :- call(G), !, call(P). if-else (G, P, θ) :- call(θ).
(C) if-else (G, P, θ) :- call(G), call(P), !. if-else (G, P,θ) :- call(θ).
(D) All of the above
Answer(C) In prolog,! operator is used for pruning the other search path.In option C, if G succeeds then it will call p and prune the rest search. If G fails then it will backtrack further and checks next predicate.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.