举个例子,我有:
(deftemplate Animal
(slot has-feathers (default FALSE))
(slot name (default "George"))
)
在规则中我有:
(defrule bird-test
?a <-(Animal (has-feathers ?))
=>
(printout t ?a.name " is a bird" crlf)
"Add slot 'bird' to ?a or Animal"
)
我该怎么做?并提前谢谢
编辑:谢谢你们!我想我明白我需要做什么。
答案 0 :(得分:0)
In addition to Ernest's proposal of providing the slot up front, you might also consider a multislot which can act as a container for all sorts of properties your rules might detect for an Animal.
(deftemplate Animal
(slot name)
(slot has-feathers)
(multislot props)...)
You can write the
(defrule bird-test
(declare (no-loop TRUE))
?a <-(Animal (has-feathers TRUE)(props $?ex ))
=>
(modify ?a (props $?ex isBird))
(printout t ?a.name "'s props: " ?a.props crlf)
)
Alternatively, a very general kind of deftemplate can be used to express all kinds or properties dynamically:
(deftemplate is-a
(slot thing)
(slot property))
But this goes beyond a mere answer.