那就是问题,想象一下我有两个规则。第二条规则取决于第一条规则。 例如:
(deftemplate person
(slot name (type STRING))
(slot age (type STRING))
)
(deffacts start
(person(name "Mike")(age "20"))
(person(name "Laura")(age "22"))
(person(name "Dean")(age "22"))
(person(name "Charlie")(age "22"))
)
(defrule filterage
(person (name ?n)(age ?a))
(test (eq ?a "22"))
=>
(assert (is-equal-to-22 ?n))
)
(defrule creategroup
(is-equal-to-22 ?c)
=>
(assert (is-in-22-years-old-group ?c))
)
正如预期的那样,第二条规则会随时触发规则1中的某些内容。
那么,我怎样才能使第二条规则等到所有人都被创建,而不使用声明显着性
答案 0 :(得分:1)
CLIPS (6.31 2/3/18)
CLIPS> (defmodule MAIN (export ?ALL))
CLIPS> (defmodule FILTER (import MAIN ?ALL))
CLIPS> (defmodule CREATE (import MAIN ?ALL))
CLIPS>
(deftemplate MAIN::av ; attribute value
(slot a)
(slot v))
CLIPS>
(deftemplate MAIN::person
(slot name)
(slot age))
CLIPS>
(deffacts MAIN::start
(person (name "Mike") (age 20))
(person (name "Laura") (age 22))
(person (name "Dean") (age 22))
(person (name "Charlie") (age 22)))
CLIPS>
(defrule MAIN::start
=>
(focus FILTER CREATE))
CLIPS>
(defrule FILTER::filterage
(person (name ?n) (age 22))
=>
(assert (av (a is-equal-to-22) (v ?n))))
CLIPS>
(defrule CREATE::creategroup
(av (a is-equal-to-22) (v ?c))
=>
(assert (av (a is-in-22-years-old-group) (v ?c))))
CLIPS> (watch rules)
CLIPS> (reset)
CLIPS> (run)
FIRE 1 start: *
FIRE 2 filterage: f-4
FIRE 3 filterage: f-3
FIRE 4 filterage: f-2
FIRE 5 creategroup: f-7
FIRE 6 creategroup: f-6
FIRE 7 creategroup: f-5
CLIPS>