Common Prolog provides several special forms for adding new predicates written in Lisp. Each one is described below, with an example.
The syntax of this form is:
(defdetpred <name> <num-args> <body>)
which defines a simple predicate that just runs Lisp code and does not have to unify any variables. Arguments are referenced with: (special-arg <num>). The body succeeds by default, but if a failure case arises, use: (detpred-fail <name> <num-args>).
For example:
(defdetpred my-integer 1 (unless (integerp (special-arg 0)) (detpred-fail my-integer 1)))
The syntax of this form is:
(defdetunipred <name> <num-args> <unifier1 unifier2> 
              <aux-vars> <body>)
defdetunipred is used when the defined predicate needs to unify values with arguments (or unify in general). The body is executed and, if successful, (that is, detpred-fail has not been called) unification is performed on the two unifiers. (If more than two items need to be unified, cons up lists of items to unify).
For example:
(defdetunipred my-arg 3 (temp1 temp2) 
         (temp1 temp2 index term value)
         (setf index (special-arg 0)
               term (special-arg 1)
               value (special-arg 2))
         (unless (and (numberp index)
                      (plusp index)
                      (or (and (term-p term)
                               (< index (length term)))
                          (and (consp term) 
                               (< index 3))))
                 (detpred-fail my-arg 3))
         (if (consp term)
             (setf temp1 (if (= index 1)
                             (car term)
                             (cdr term)))
            (setf temp1 (term-ref term index)))
         (setf temp2 value))
KnowledgeWorks and Prolog User Guide (Windows version) - 18 Feb 2025 15:37:34