All Manuals > KnowledgeWorks and Prolog User Guide > Appendix A: Common Prolog

A.8 Common Prolog Macros

Macros may be defined within the logic system using the form:

(defrelmacro <name> <arg-list> <body>)

which is effectively the same as a Common Lisp defmacro. Logic macros are expanded before variable translation so that logic variables may be treated as atoms. defrelmacro forms must have a fixed number of arguments. This allows different predicates with the same name but different arities to be defined. If you want to define a special form with an arbitrary number of arguments, use defrel-special-form-macro.

A.8.1 Example

(defrelmacro append3 (x y z w)
  (let ((iv (make-internal-var)))
  `(and (append ,x ,y ,iv)
        (append ,iv ,z ,w))))
==> (append3 (1) (2) (3) ?y)
 
?Y = (1 2 3)

KnowledgeWorks and Prolog User Guide (Macintosh version) - 01 Dec 2021 19:35:39