首先我声明:
(deftemplate worker (插槽ID (键入STRING) (默认?DERIVE))
(老虎机工资 (键入FLOAT) (默认?DERIVE)))
然后我补充说:
(断言(工人(id“a”))(工资30.0)))
(断言(工人(id“b”)(工资40.0)))
(断言(工人(id“c”)(工资60.0)))
(断言(工人(id“d”)(工资70.0)))
(断言(工人(id“e”)(工资10.0)))
我如何计算我有多少'工人'?
我怎样才能算出有多少工人的工资超过30?
答案 0 :(得分:3)
使用事实集查询功能:
CLIPS>
(deftemplate worker
(slot id (type STRING) (default ?DERIVE))
(slot salary (type FLOAT) (default ?DERIVE)))
CLIPS> (assert (worker (id "a") (salary 30.0)))
<Fact-1>
CLIPS> (assert (worker (id "b") (salary 40.0)))
<Fact-2>
CLIPS> (assert (worker (id "c") (salary 60.0)))
<Fact-3>
CLIPS> (assert (worker (id "d") (salary 70.0)))
<Fact-4>
CLIPS> (assert (worker (id "e") (salary 10.0)))
<Fact-5>
CLIPS> (find-all-facts ((?f worker)) (> ?f:salary 30.0))
(<Fact-2> <Fact-3> <Fact-4>)
CLIPS> (length$ (find-all-facts ((?f worker)) (> ?f:salary 30.0)))
3
CLIPS> (do-for-all-facts ((?f worker)) (> ?f:salary 30.0) (printout t ?f:id crlf))
b
c
d
CLIPS>