我是专家系统世界的新手。我正在学习使用CLIPS工具。任何人都可以帮我制作一个程序来添加三个数字? 感谢
答案 0 :(得分:0)
CLIPS>
(deftemplate add
(multislot numbers))
CLIPS>
(defrule add-3-numbers
(add (numbers ?n1 ?n2 ?n3))
=>
(printout t ?n1 " + " ?n2 " + " ?n3 " = " (+ ?n1 ?n2 ?n3) crlf))
CLIPS> (assert (add (numbers 1 2 3)))
<Fact-1>
CLIPS> (assert (add (numbers 2 9 11)))
<Fact-2>
CLIPS> (run)
2 + 9 + 11 = 22
1 + 2 + 3 = 6
CLIPS>
更新:
CLIPS> (clear)
CLIPS>
(defrule add-3-numbers
=>
(printout t "Number 1? ")
(bind ?n1 (read))
(printout t "Number 2? ")
(bind ?n2 (read))
(printout t "Number 3? ")
(bind ?n3 (read))
(printout t ?n1 " + " ?n2 " + " ?n3 " = " (+ ?n1 ?n2 ?n3) crlf))
CLIPS> (reset)
CLIPS> (run)
Number 1? 1
Number 2? 2
Number 3? 3
1 + 2 + 3 = 6
CLIPS> (evenp 3)
FALSE
CLIPS> (oddp 7)
TRUE
CLIPS>