CLIPS:从事实模板中打印槽值?

时间:2017-04-24 17:46:50

标签: clips

如果名单上的人有蓝眼睛,我们必须浏览一个人名单并打印出“名字有蓝眼睛”。 我们打印了3次,因为列表中的3个人都有蓝眼睛,但我们无法弄清楚如何访问事实的名字变量槽。

到目前为止,这是代码:

(deftemplate person (slot first-name) (slot eye-color)(slot hair-color) 
(slot hgt) (slot wgt)
)

(deffacts some-people "people involved"
     (person (first-name kevin) (eye-color blue) (hgt 175) (wgt 93))
     (person (first-name john) (eye-color brown) (hgt 190) (wgt 80))
     (person (first-name smith) (eye-color hazel) (hgt 165) (wgt 75))
     (person (first-name tom) (eye-color brown) (hgt 172) (wgt 77))
     (person (first-name alan) (eye-color blue) (hgt 190) (wgt 83)) 
     (person (first-name patricia) (eye-color blue) (hgt 175) (wgt 55))
     (person (first-name Leena) (eye-color brown) (hgt 176) (wgt 60))
     (person (first-name michael) (eye-color hazel) (hgt 190) (wgt 88))
     (person (first-name robert) (eye-color grey) (hgt 170) (wgt 77))
     (person (first-name judy) (eye-color hazel) (hgt 170) (wgt 76))
)

(defrule blueEyes "Print people with blue eyes"
 (person (eye-color blue))
 =>
 (printout t ??whatgoeshere?? " has-blue-eyes" crlf))

感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

(defrule blueEyes "Print people with blue eyes"
  (person (first-name ?name) (eye-color blue))
  =>
  (printout t ?name " has blue eyes" crlf))