Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the not clause work in Datomic?

I am trying to find latitudes which fall between two inputs. My query:

(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))

My error:

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

Any help with understanding what's wrong with my query would be appreciated. Bonus points if you can also use Datomic rules to factor out the in-bounds part of each half.

like image 464
tropicalmug Avatar asked Jan 30 '26 09:01

tropicalmug


1 Answers

Your code seems to work for me with datomic-free 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]}
like image 174
Anthony R. Avatar answered Feb 03 '26 00:02

Anthony R.