Picat Logic Programming and Unification 4 — Questions and Answers
Question 1: In Picat, what is a 'choice point' in the context of logic programming?
- A variable that can hold multiple types
- A saved execution state that Picat can return to on backtracking (Correct answer)
- A syntax marker for conditional branches
- A pointer to an imported module
Correct answer: A saved execution state that Picat can return to on backtracking
A choice point is a snapshot of the interpreter state saved when multiple clauses can match, allowing resumption on failure.
Question 2: How does Picat's cut (`!`) affect choice points in a logic predicate?
- Removes only the innermost choice point
- Removes all choice points created since the parent call, committing to the current clause (Correct answer)
- Has no effect in Picat (it's a Prolog-only feature)
- Forces immediate success of the enclosing predicate
Correct answer: Removes all choice points created since the parent call, committing to the current clause
Cut removes all choice points for the predicate that contains it, preventing backtracking into alternative clauses.
Question 3: In Picat unification, which of the following is a valid unification of a list?
- [H|T] = [1,2,3] → H=1, T=[2,3] (Correct answer)
- [H|T] = [1,2,3] → H=[1,2], T=3
- [H|T] = [] → H=[], T=[]
- [H|T] = [1] → H=1, T=1
Correct answer: [H|T] = [1,2,3] → H=1, T=[2,3]
List unification [H|T] = [1,2,3] binds the head H to 1 and the tail T to the remaining list [2,3].
Question 4: What does `findall(X, member(X,[1,2,3]), Bag)` return in Picat?
- Bag = [1]
- Bag = [1,2,3] (Correct answer)
- Bag = [[1],[2],[3]]
- An error because findall is not in Picat
Correct answer: Bag = [1,2,3]
findall/3 collects all X that satisfy the goal into Bag, so Bag = [1,2,3].
Question 5: In Picat, what distinguishes `bagof/3` from `findall/3`?
- bagof groups results by unbound variables and fails if there are no solutions; findall never fails (Correct answer)
- bagof always returns sorted results; findall returns unsorted
- findall supports grouping; bagof does not
- They are identical in behavior
Correct answer: bagof groups results by unbound variables and fails if there are no solutions; findall never fails
bagof/3 fails when the goal has no solutions and can group answers by free variables, unlike findall/3 which always succeeds with [] on no solutions.
Question 6: What is the meaning of a 'ground' term in Picat logic programming?
- A term that is syntactically valid
- A term that contains no unbound variables (Correct answer)
- A term that evaluates to a number
- A term defined at the top level of a module
Correct answer: A term that contains no unbound variables
A ground term has no free (uninstantiated) variables — every part of the term is fully bound.
Question 7: Which Picat predicate tests whether a term is currently an unbound variable?
- atom(X)
- var(X) (Correct answer)
- free(X)
- unbound(X)
Correct answer: var(X)
var(X) succeeds if X is currently an uninstantiated (unbound) variable at the time of the call.
In Picat, what is a 'choice point' in the context of logic programming?