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

NextPrevUpTopContentsIndex

A.6.2.2 deflogfun

A different interface is available for predicates which will be called often from Lisp. The macro deflogfun may be used to generate normal Lisp functions that run with precompiled goals.

(deflogfun break-up (y) (append ?a ?b y) (?a ?b))

then:

(break-up '(foo bar baz))

returns:

(NIL (FOO BAR BAZ))
T
(break-up '(foo bar baz) :all :values)

returns:

(NIL (FOO BAR BAZ))
((FOO) (BAR BAZ))
((FOO BAR) (BAZ))
((FOO BAR BAZ) NIL)
(break-up '(foo bar baz) :all :list)

returns:

((NIL (FOO BAR BAZ)) 
 ((FOO) (BAR BAZ)) 
 ((FOO BAR) (BAZ))
 ((FOO BAR BAZ) NIL))
T

The generated function works like the Lisp functions any and findall, returning solutions to a prolog expression.

The form

(deflogfun name args sample-expr return-expr )

defines a Lisp function called name , whose lambda list is the list args . The function will also take a keyword argument :all . If the function is called with :all nil (the default), then it returns the first solution, like any. If the function is called with :all t , then it returns a list of all the solutions, like findall. If the function is called with :all :values , then it returns multiple values, with one value per solution.

The sample-expr is like the second argument to any, that is, it is the prolog query expression. The return-expr is like the first argument to clog:any , that is, it defines how the result will be formed from the results of the query. If any of the symbols mention in args appears in sample-expr or return-expr , then its value is subsituted. All other symbols in sample-expr and return-expr remain unchanged.


KnowledgeWorks and Prolog User Guide (Unix version) - 22 Dec 2009

NextPrevUpTopContentsIndex