Querying
(query-prolog rb '(ancestor tom ?who)) ; all solutions
(query-prolog rb '(ancestor tom ?who) :limit 2) ; bounded search
(query-prolog-first rb '(ancestor ?x bob)) ; first solution or NIL
(prolog-succeeds-p rb '(ancestor tom eve)) ; boolean, stops at first proof
;; streaming: the function is called as each solution is proven
(map-prolog-solutions
(lambda (solution) (format t "~&=> ~S~%" solution))
rb '(ancestor tom ?who))
with-prolog-query binds variables from the first solution; prolog-match
dispatches like cond over queries.
Entry points
map-prolog-solutions— the primitive. Calls a function once per solution as it is proven (streaming CPS). Keywords::max-depth,:environment,:project,:limit.query-prolog— collect solutions into a list. Same keywords.query-prolog-first— first solution ornil(searches with:limit 1).prolog-succeeds-p— boolean; stops at the first proof.solution-binding— look one variable up in a solution alist.
Conventions
- a solution is an alist of query-variable bindings; ground success is
nil, so “one ground proof” is(nil)and failure is() :project nilreturns raw proof environments instead:max-depthoptionally bounds user-rule resolution (the default isNIL, meaning unbounded); exhaustion signalsprolog-depth-limit-exceeded;0disables rule expansion entirely, facts still match:limitmust benilor a positive integer