在断言新事实时维护 CLIPS 运行
mantain CLIPS running when asserting new facts
在断言新事实的同时保持 CLIPS 运行ning 是可能的吗?
example of execution
是否有可能不必在每个 assert 命令后进行 (运行) 来测试该程序?我的意思是,只制作一个 (运行),然后在我插入新事实时自动触发规则。
提前致谢!
您可以使用辅助函数来执行断言和后续 运行:
CLIPS (6.4 2/9/21)
CLIPS>
(deffunction push (?value)
(assert-string (str-cat "(push-value " ?value ")"))
(run))
CLIPS>
(deffunction assert* (?value)
(assert-string ?value)
(run))
CLIPS>
(defrule push-to-stack
?s <- (stack $?stack)
?p <- (push-value ?v)
=>
(println "Pushing value " ?v)
(retract ?s ?p)
(assert (stack ?v ?stack)))
CLIPS> (assert (stack))
<Fact-1>
CLIPS> (push 3)
Pushing value 3
CLIPS> (assert* "(push-value 4)")
Pushing value 4
CLIPS>
为了测试,您也可以创建一个包含命令的文件(如下),然后使用批处理命令自动执行文件中的所有命令。
(assert (stack))
(assert (push-value 3))
(assert (run))
(assert (push-value 4))
(run)
(assert (push-value 9))
(assert (push-value 2))
(run)
在断言新事实的同时保持 CLIPS 运行ning 是可能的吗?
example of execution
是否有可能不必在每个 assert 命令后进行 (运行) 来测试该程序?我的意思是,只制作一个 (运行),然后在我插入新事实时自动触发规则。
提前致谢!
您可以使用辅助函数来执行断言和后续 运行:
CLIPS (6.4 2/9/21)
CLIPS>
(deffunction push (?value)
(assert-string (str-cat "(push-value " ?value ")"))
(run))
CLIPS>
(deffunction assert* (?value)
(assert-string ?value)
(run))
CLIPS>
(defrule push-to-stack
?s <- (stack $?stack)
?p <- (push-value ?v)
=>
(println "Pushing value " ?v)
(retract ?s ?p)
(assert (stack ?v ?stack)))
CLIPS> (assert (stack))
<Fact-1>
CLIPS> (push 3)
Pushing value 3
CLIPS> (assert* "(push-value 4)")
Pushing value 4
CLIPS>
为了测试,您也可以创建一个包含命令的文件(如下),然后使用批处理命令自动执行文件中的所有命令。
(assert (stack))
(assert (push-value 3))
(assert (run))
(assert (push-value 4))
(run)
(assert (push-value 9))
(assert (push-value 2))
(run)