Next Prev Up Top Contents Index

defrule

Macro
Syntax

defrule rule-name direction &rest body

Arguments

rule-name is a symbol. direction is :forward or :backward . The body is described in Chapter 3, Rules.

Description

Defines a rule of the given name (which must be distinct from any other rule name, context name or KnowledgeWorks class name). If direction is :forward a forward chaining rule is defined, if :backward a backward chaining rule is defined. A full description is given in Rules.

Values

rule-name is returned.

Examples
(defrule move-train :forward :context trains
  (train ?train position ?train-pos)
  (signal ?signal position ?signal-pos colour green)
  (test (= ?signal-pos (1+ ?train-pos)))
  -->
  ((format t "~%Train moving to ~S" ?signal-pos))
  (assert (signal ?signal colour red))
  (assert (train ?train position ?signal-pos)))
(defrule link-exists :backward
  ((link-exists ?town1 ?town2)
   <--
   (or (link ?link town1 ?town1 town2 ?town2)
       (link ?link town2 ?town1 town1 ?town2))
   (cut))
  ((link-exists ?town1 ?town2)
   <--
   (route-exists ?town1 ?town2)))

LispWorks KnowledgeWorks and Prolog User Guide - 14 Dec 2001

Next Prev Up Top Contents Index