Three simple interface functions call
logic
. They are
any
,
findall
, and
findallset
. Each takes two arguments: a result expression to instantiate and a goal expression.
any
returns the first solution found.
findall
returns all solutions.
findallset
returns all solutions deleting duplicates.
Assuming the definitions for
fact
and
color
from the previous examples.
|(any '(?x is the factorial of 5) '(fact 5 ?x))
|
|(120 IS THE FACTORIAL OF 5)
|
|(findall '(?x is a color) '(color ?x))
|
|((RED IS A COLOR) (BLUE IS A COLOR)
(GREEN IS A COLOR))
|
|(findall '?y '(or (= ?y 5) (= ?y 5)))
|
|(5 5)
|
|(findallset '?y '(or (= ?y 5) (= ?y 5)))
|
|(5)
findall
and
findallset
will hang if a goal expression generates an infinite solution set.
More powerful all solution predicates (
bagof
and
setof
) are available from within Common Prolog.