All Manuals > KnowledgeWorks and Prolog User Guide > 7 Reference Guide

with-rule-actions Macro

Summary

Allows rule syntax to be embedded in Lisp code.

Package

kw

Signature

with-rule-actions bound-variables &body body => successp

Arguments
bound-variables
A list of variables (each starting with ?).
body
A rule body.
Values
successp
A boolean.
Description

The macro with-rule-actions macro enables rule syntax to be embedded within Lisp.

body is executed just as if it were the right hand side of a forward or backward chaining rule. All variables in body (each starting with ?) are taken to be unbound unless found in the list bound-variables, in which case its value is taken from the Lisp variable of the same name. with-rule-actions is similar to the function any but can be compiled for efficiency.

successp is t if the body succeeds (that is, all clauses are successfully executed) or nil if any of the clauses fail.

Any subgoals that match the object base will only find objects from the current inferencing state.

Examples
(defun my-fn (?x)
  "prints all the lists which append to give ?x and
   then returns NIL"
  (with-rule-actions (?x)
    (append ?a ?b ?x)
    ((format t "~%~S and ~S append to give ~S"
             ?a ?b ?x))
    (fail)))
See also

any


KnowledgeWorks and Prolog User Guide (Windows version) - 01 Dec 2021 19:36:03