我试着在一个学校项目的剪辑中编写以下代码(尽管我不明白为什么AI是用这种语言完成的):
(deftemplate blood
(slot bt)
(multislot acc))
(deffacts acceptance
(blood (bt 0) (acc 0 0))
(blood (bt A) (acc 0 A))
(blood (bt B) (acc 0 B))
(blood (bt AB) (acc 0 A B AB)))
(defrule reading-input
=>
(printout t "Bloodtype of patient? ")
(assert (patient (read)))
(printout t "Bloodtype of donor? ")
(assert (donor (read))))
(defrule check-acceptance
(patient ?patient)
(donor ?donor)
(blood (bt ?bt1) (acc ?acc1))
(test (member$ ?donor ?acc1))
=>
(printout t "Transfusion is safe" crlf))由于某些原因,它不会打印任何输入、A和A或其他任何内容。我也尝试过使用if then else语句,但结果是一样的。
[prev code]
(blood (bt ?bt1) (acc ?acc1))
=>
(if (eq ?patient ?bt1)
then
(printout t ?bt1)
else
(printout t ?donor)))这个想法是写一个程序,打印输血是否安全。
发布于 2021-11-24 02:52:36
修改您的血液模式,使bt插槽仅限于患者的血型,并将变量acc1更改为多字段变量,以便它将绑定到acc插槽中的所有值:
(defrule check-acceptance
(patient ?patient)
(donor ?donor)
(blood (bt ?patient) (acc $?acc1))
(test (member$ ?donor ?acc1))
=>
(printout t "Transfusion is safe" crlf))https://stackoverflow.com/questions/70086152
复制相似问题