【问题标题】:How does the not clause work in Datomic?not 子句在 Datomic 中如何工作?
【发布时间】:2015-05-14 04:26:44
【问题描述】:

我试图找到两个输入之间的纬度。我的查询:

(defn- latlngs-within-new-bounds
  [db a w]
  (d/q '[:find ?lat
         :in $ ?a ?w
         :where
         [ ?e :location/lat ?lat]
         [(>= ?lat ?a)]
         (not
          [(>= ?lat ?w)])]
       db a w))

我的错误:

3 Unhandled com.google.common.util.concurrent.UncheckedExecutionException
   java.lang.RuntimeException: Unable to resolve symbol: ?lat in this
   context

2 Caused by clojure.lang.Compiler$CompilerException

1 Caused by java.lang.RuntimeException
   Unable to resolve symbol: ?lat in this context

                 Util.java:  221  clojure.lang.Util/runtimeException

如果能帮助我理解我的查询出了什么问题,我们将不胜感激。如果您还可以使用 Datomic 规则来分解每一半的 in-bounds 部分,则可以加分。

【问题讨论】:

  • 你想在这里完成什么:(>= :location/lat ?w)? :location/lat 似乎无法与 ?w 相提并论
  • 你是对的。我已将其重新格式化为更简单的情况和有效的查询。
  • 你真的在执行那个查询吗?由于:in 行中的aw 参数应该是?a?w
  • 是的,我是。是的,我还需要修复其他结构性问题。该错误与这些参数中的任何一个都无关,并且在我修复它时保持不变。

标签: clojure datomic datalog


【解决方案1】:

您的代码似乎适用于无 datomic 的 0.9.5173:

(defn- latlngs-within-new-bounds
  [db a w]
  (d/q '[:find ?lat
         :in $ ?a ?w
         :where
         [ ?e :location/lat ?lat]
         [(>= ?lat ?a)]
         (not
           [(>= ?lat ?w)])]
       db a w))

(latlngs-within-new-bounds
  [[1 :location/lat 1]
   [2 :location/lat 2]
   [3 :location/lat 3]
   [4 :location/lat 4]
   [4 :location/lat 5]]
  2 4)
=> #{[2] [3]}

【讨论】:

  • 我从本地 maven 存储库中删除了 cider-nrepl 并重新运行所有内容,现在它可以工作了。感谢您帮助我调试工具。
猜你喜欢
  • 1970-01-01
  • 2022-01-13
  • 2012-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-25
  • 1970-01-01
相关资源
最近更新 更多