【发布时间】:2018-06-02 06:06:00
【问题描述】:
我在 CLIPS 中编写了这些代码,但它不起作用。它说“局部变量不能被 deffact 访问。”我还想在其他 defrules 中使用 number1 和 number2 的值。如何在规则中将这些变量定义为全局变量?
(deffunction calculation1
(?x ?y)
(+ ?x ?y))
(defrule rule1
=>
(printout t "What is the first number?")
(bind ?number1 (read))
(assert (number-1 ?number1))
(printout t "What is the second number?")
(bind ?number2 (read))
(assert (number-2 ?number2))
(bind ?theirsum (calculation1 ?number1 ?number2))
(printout t "The sum is " ?theirsum crlf))
(deffacts data
(first num1 ?number1
second num2 ?number2))
【问题讨论】: