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

NextPrevUpTopContentsIndex

A.6.2.3 with-prolog

A final interface mechanism is with-prolog. with-prolog allows one to embed prolog into an arbitrary lisp function. Lisp variables are referenced in Prolog using " ? . <name> ".

(defun palindromep (x)
  (with-prolog
    (append ?a (?b . ?c) ?.x) ; note "?.x" reference
    (or (reverse ?a ?c)
        (reverse ?a (?b . ?c)))))
(palindromep '(yes no maybe))

returns:

NIL (palindromep '(yes no maybe no yes))

returns:

T

The body of a with-prolog returns t if it succeeds and a non-local exit is not executed. It returns nil on failure.


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

NextPrevUpTopContentsIndex