嵌套多个如果是else语句
我正在尝试制定一个剪辑程序,以吸收患者和捐助者的血型,并在医生输血前进是否返回。当我加载程序时,我在最后会得到一个错误的标志。有其他方法可以嵌套在当时的语句中吗?
; define template
(deftemplate blood-type
(slot blood))
(deftemplate patients
(slot receiver)
(slot donor))
; reading input
(defrule reading-input
=>
(printout t "Enter the receiver/patient blood type: ")
(assert (receiver (read)))
(printout t "Enter the donor's blood type: ")
(assert (donor (read))))
; checking for valid input
(defrule checking-input
(receiver ?receiver)
(donor ?donor)
=>
(if (and (eq ?receiver O) (eq ?donor O))
then
if (and (eq ?receiver A) (eq ?donor A))
then
(if (and (eq ?receiver A)(eq ?donor O))
then
(if (and (eq ?receiver B) (eq ?donor B))
then
(if (and (eq ?receiver B) (eq ?donor O))
then
(if (and (eq ?receiver AB) (eq ?donor AB))
then
(if (and (eq ?receiver AB) (eq ?donor A))
then
(if (and (eq ?receiver AB) (eq ?donor B))
then
(if (and (eq ?receiver AB) (eq ?donor O))
then (printout t "Continue with Transfusion" crlf)
else (printout t "Stop transfusion" crlf))))))))))
I'm trying to make a CLIPS program that takes in a patient's and donor's blood type and returns if the doctor should go forward with the transfusion. When I load in the program, I get a FALSE flag at the very end. Is there another way that I can nest in the If-Then statements?
; define template
(deftemplate blood-type
(slot blood))
(deftemplate patients
(slot receiver)
(slot donor))
; reading input
(defrule reading-input
=>
(printout t "Enter the receiver/patient blood type: ")
(assert (receiver (read)))
(printout t "Enter the donor's blood type: ")
(assert (donor (read))))
; checking for valid input
(defrule checking-input
(receiver ?receiver)
(donor ?donor)
=>
(if (and (eq ?receiver O) (eq ?donor O))
then
if (and (eq ?receiver A) (eq ?donor A))
then
(if (and (eq ?receiver A)(eq ?donor O))
then
(if (and (eq ?receiver B) (eq ?donor B))
then
(if (and (eq ?receiver B) (eq ?donor O))
then
(if (and (eq ?receiver AB) (eq ?donor AB))
then
(if (and (eq ?receiver AB) (eq ?donor A))
then
(if (and (eq ?receiver AB) (eq ?donor B))
then
(if (and (eq ?receiver AB) (eq ?donor O))
then (printout t "Continue with Transfusion" crlf)
else (printout t "Stop transfusion" crlf))))))))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的条件筑巢非常复杂。您可以在没有任何嵌套的情况下获得正确的结果:
如果这是用于课堂分配的,则可能会使用不使用有意义的方式使用模式匹配的方法获得失败的成绩。
Your nesting of conditions is unnecessarily complex. You can achieve the correct results without any nesting:
If this is for a class assignment, you might get a failing grade using an approach that doesn't utilize pattern matching in a meaningful way.