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))
(break-up '(foo bar baz))
(NIL (FOO BAR BAZ))
T
(break-up '(foo bar baz) :all :values)
(NIL (FOO BAR BAZ))
((FOO) (BAR BAZ))
((FOO BAR) (BAZ))
((FOO BAR BAZ) NIL)
(break-up '(foo bar baz) :all :list)
((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.
(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 substituted. All other symbols in sample-expr and return-expr remain unchanged.
KnowledgeWorks and Prolog User Guide (Unix version) - 26 Feb 2015