Logic Programming and Unification Flashcards
7 cards from real Picat practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Logic Programming and Unification flashcards as text
In Picat, how does the `=>` rule differ from a logic predicate clause written with `:-`?
Answer: => commits to the first matching rule (no backtracking into it); :- allows backtracking
A => (deterministic) rule commits once matched — no alternative clauses are tried on failure — while :- clauses participate in full backtracking.
Which Picat built-in decomposes a compound term into its functor and arguments?
Answer: functor/3 and arg/3
functor(T, F, A) extracts functor F and arity A, while arg(N, T, Arg) extracts the Nth argument of T.
What does the Picat goal `T =.. [foo, 1, 2]` do?
Answer: Unifies T with the compound term foo(1,2)
The univ operator =.. constructs or decomposes a term: [foo,1,2] as the right-hand side builds foo(1,2).
In Picat logic predicates, what is the purpose of `call/1` or `call/N`?
Answer: Calls a goal stored in a variable at runtime (meta-call)
call/N allows a term held in a variable to be invoked as a goal, enabling higher-order programming.
What does the `once/1` built-in do in Picat?
Answer: Runs a goal and commits to its first solution, discarding other choice points
once(Goal) succeeds at most once: it runs Goal and keeps only the first solution, cutting away alternatives.
In Picat, which of the following correctly uses assert to add a fact at runtime?
Answer: assert(likes(mary, food))
assert(Fact) dynamically adds Fact to the knowledge base during program execution.
What is 'goal conjunction' in Picat logic predicates, and how is it written?
Answer: Sequential goal execution where both must succeed, written as G1, G2
Conjunction (G1, G2) means G1 must succeed first, then G2 is attempted; if either fails the conjunction fails.