KnowledgeWorks and Prolog User Guide > 3 Rules > 3.1 Forward chaining > 3.1.2 Forward Chaining Syntax

NextPrevUpTopContentsIndex

3.1.2.1 Example

(defrule move-train :forward
          :context train
          (train ?train position ?train-pos)
          (signal ?signal position ?signal-pos 
           colour green)
          (test (= ?signal-pos (1+ ?train-pos)))
-->
  ((format t "~%Train moving to position ~s" 
              ?signal-pos))
  (assert (signal ?signal colour red))
  (assert (train ?train position ?signal-pos)))

specifies that if there is a train with a green signal directly in front then the train may move on and the signal changes to red.


KnowledgeWorks and Prolog User Guide (Macintosh version) - 22 Dec 2009

NextPrevUpTopContentsIndex