是否可以在一系列核心呼叫中插入一个clojure语句,” la prolog;

发布于 2025-02-03 07:30:02 字数 1215 浏览 4 评论 0原文

Prolog混合逻辑(易犯错)目标,以及(无误的)过程,例如write/2assert/1。是否可以使用Clojure的Core.logic进行?

例如:

(pldb/with-db myFacts
   (l/run* [x y] 
       (person x)
       (println "we found a person!")
       (likes y x)
   )
)

看来这是行不通的,因为(println ...)是嵌入在核心中的clojure函数。我猜的条件/约束)。

更有趣的是,我希望能够在检查逻辑条件(如Prolog中:

liked(x,y):-
    person(x),
    assertz(likable(x)),
    likes(y,x).

在核心中看起来像这样的逻辑条件)

(pldb/with-db myFacts
   (l/run* [x y] 
       (person x)
       (def newFacts (-> newFacts (pldb/db-fact likeable x)))
       (likes y x)
   )
)

中提出新事实。是关于将程序命令插入约束检查中的过程命令。就像在Prolog中完成的那样。

例如,它的一种具体应用将是通过使用断言在图形递归遍历中收集弧的能力。但是,除非我误会了,否则只有在我们有可能将主张与逻辑条件相混合时,这是可能的。

非常感谢您在此方面的帮助和指导。

更新: 我想我可能已经弄清楚了:包括一个clojure的陈述很好,但必须返回真实;与Prolog不同,这些功能不会自动“成功”。因此,我们需要添加的只是: (l/==(println“ hello”)true)) 听起来正确吗? 仅供参考,这篇文章真的很有帮助: htttps:// https:// ask.clojure.org/index.php/9546/can-core-logic-ask-questions

Prolog mixes logic (fallible) goals, and (infallible) processes like write/2 or assert/1. Is it possible to do so with Clojure's core.logic?

For example:

(pldb/with-db myFacts
   (l/run* [x y] 
       (person x)
       (println "we found a person!")
       (likes y x)
   )
)

It looks like this can't work because (println ...) is a Clojure function embedded in a core.logic run (which is supposed to contain only conditions/constraints I'm guessing).

More interestingly, I would like to be able to assert new facts in the midst of checking logical conditions like in Prolog:

liked(x,y):-
    person(x),
    assertz(likable(x)),
    likes(y,x).

Which would approximatively look like this in core.logic I'm guessing:

(pldb/with-db myFacts
   (l/run* [x y] 
       (person x)
       (def newFacts (-> newFacts (pldb/db-fact likeable x)))
       (likes y x)
   )
)

Those examples are silly but, in general, the question is about inserting procedural commands in the midst of constraint checking in core.logic like it is done in Prolog.

One concrete application of that, for instance, would be the capability to collect arcs in the recursive traversal of a graph by using assertion. But, unless I am mistaken, that's only possible if we have the possible to mix assertion with logical conditions.

Thank you very much for your help and guidance in this.

UPDATE:
I think I might have figured it out: including a Clojure statement is fine but it must return true ; unlike in Prolog, those functions don't automatically "succeed". So all we need to add is:
(l/== (println "hello") true))
Does it sound correct?
FYI, this post was really helpful: https://ask.clojure.org/index.php/9546/can-core-logic-ask-questions

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文