为什么 run* 不适用于 core.logic 中的自然数?
我正在玩 core.logic 的 Peano 算术应用程序
(run* [q] (natural-number one))
Clojure 时,会出现错误,但是,
(run 1 [q] (natural-number one))
(_.0)
按预期成功。这里有一些实施细节吗?
编辑:
我正在运行以下代码:
(ns myns.core
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
(defn s [n]
"Returns n's succeeding natural number"
(llist n []))
(def zero 0)
(def one (s zero))
(def two (s one))
(def three (s two))
(def four (s three))
(def five (s four))
(def six (s five))
(defn natural-number [x]
"A relation where x is a natural number"
(matche [x]
([zero])
([(s ?x)] (natural-number ?x))))
堆栈跟踪是:
clojure.core.logic.LVar cannot be cast to clojure.lang.IFn
[Thrown class java.lang.ClassCastException]
0: myns.core$natural_number$fn__177103$_inc__177104$fn__177113$fn__177114$_inc__177115$fn__177116.invoke(core.clj:194)
1: clojure.core.logic.Substitutions.bind(logic.clj:208)
2: myns.core$natural_number$fn__177103$_inc__177104$fn__177113$fn__177114$_inc__177115.invoke(core.clj:192)
3: clojure.core.logic$eval175682$fn__175691$_inc__175692.invoke(logic.clj:808)
4: clojure.core.logic$eval175682$fn__175683$fn__175684.invoke(logic.clj:813)
5: clojure.lang.LazySeq.sval(LazySeq.java:42)
6: clojure.lang.LazySeq.seq(LazySeq.java:67)
7: clojure.lang.Cons.next(Cons.java:39)
8: clojure.lang.LazySeq.next(LazySeq.java:92)
9: clojure.lang.RT.next(RT.java:580)
project.clj
(defproject myns "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/core.logic "0.6.7"]])
I'm playing around with the Peano arithmetic application of core.logic at GitHub. When I try
(run* [q] (natural-number one))
Clojure spits out an error, however,
(run 1 [q] (natural-number one))
succeeds with (_.0)
as intended. Is there some implementation detail here?
Edit:
I'm running the following code:
(ns myns.core
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
(defn s [n]
"Returns n's succeeding natural number"
(llist n []))
(def zero 0)
(def one (s zero))
(def two (s one))
(def three (s two))
(def four (s three))
(def five (s four))
(def six (s five))
(defn natural-number [x]
"A relation where x is a natural number"
(matche [x]
([zero])
([(s ?x)] (natural-number ?x))))
The stack trace is:
clojure.core.logic.LVar cannot be cast to clojure.lang.IFn
[Thrown class java.lang.ClassCastException]
0: myns.core$natural_number$fn__177103$_inc__177104$fn__177113$fn__177114$_inc__177115$fn__177116.invoke(core.clj:194)
1: clojure.core.logic.Substitutions.bind(logic.clj:208)
2: myns.core$natural_number$fn__177103$_inc__177104$fn__177113$fn__177114$_inc__177115.invoke(core.clj:192)
3: clojure.core.logic$eval175682$fn__175691$_inc__175692.invoke(logic.clj:808)
4: clojure.core.logic$eval175682$fn__175683$fn__175684.invoke(logic.clj:813)
5: clojure.lang.LazySeq.sval(LazySeq.java:42)
6: clojure.lang.LazySeq.seq(LazySeq.java:67)
7: clojure.lang.Cons.next(Cons.java:39)
8: clojure.lang.LazySeq.next(LazySeq.java:92)
9: clojure.lang.RT.next(RT.java:580)
project.clj
(defproject myns "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/core.logic "0.6.7"]])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是 core.logic 0.6.5 和 0.6.7 之间的微妙回归。需要进行更多调查才能找到问题的根源。
与此同时,我重写了后继函数以使用
conso
而不是llist
。我认为这是更惯用的 minikanren/core.logic 代码。
s
现在采用 2 个参数:数字和下一个数字。修订后的代码解决了您的问题。
This looks like a subtle regression between core.logic 0.6.5 and 0.6.7. It requires more investigation to get to the root of the issue.
In the meantime I have rewritten the successor function to use
conso
instead ofllist
.I think it is more idiomatic minikanren/core.logic code.
s
now takes 2 arguments: the number, and the next number.The revised code fixes your issue.