在断言新事实时保持 CLIPS 运行

发布于 2025-01-13 03:27:07 字数 200 浏览 0 评论 0原文

是否可以在断言新事实的同时保持 CLIPS 运行?

执行示例

之后可能不需要 make(运行)来测试该程序每个断言命令?我的意思是,只创建一个(运行),然后当我插入新事实时自动触发规则。

提前致谢!

It's possible to keep CLIPS running while asserting new facts?

example of execution

It would be possible not to have to make (run) to test this program after each assert command? I mean, making only one (run) and then, fire the rules automatically when i insert new facts.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请你别敷衍 2025-01-20 03:27:07

您可以使用辅助函数来执行断言和后续运行:

         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)

You can use helper functions to perform both the assertion and the subsequent run:

         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> 

For testing, you can also create a file containing the commands (as follows), and then use the batch command to automatically execute all the commands in your file.

(assert (stack))
(assert (push-value 3))
(assert (run))
(assert (push-value 4))
(run)
(assert (push-value 9))
(assert (push-value 2))
(run)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文