All Manuals > KnowledgeWorks and Prolog User Guide > A Common Prolog > A.13 Adding Built-in Predicates

NextPrevUpTopContentsIndex

A.13.2 The defdetunipred form

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 (Macintosh version) - 26 Feb 2015

NextPrevUpTopContentsIndex