All Manuals > KnowledgeWorks and Prolog User Guide > A Common Prolog > A.6 Calling Prolog From Lisp > A.6.2 Interface Functions

NextPrevUpTopContentsIndex

A.6.2.1 any, findall and findallset

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))

returns:

|
|(120 IS THE FACTORIAL OF 5)
|
|(findall '(?x is a color) '(color ?x))

returns:

|
|((RED IS A COLOR) (BLUE IS A COLOR) 
  (GREEN IS A COLOR))
|
|(findall '?y '(or (= ?y 5) (= ?y 5)))

returns:

|
|(5 5)
|
|(findallset '?y '(or (= ?y 5) (= ?y 5)))

returns:

|
|(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.


KnowledgeWorks and Prolog User Guide (Windows version) - 26 Feb 2015

NextPrevUpTopContentsIndex