3

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.

tropicalmug
  • 225
  • 1
  • 2
  • 6
  • 1
    What are you trying to accomplish here: `(>= :location/lat ?w)`? :location/lat doesn't seem to be comparable to ?w to me – guilespi May 14 '15 at 14:41
  • You are correct. I have reformatted this to be a more minimal case and a valid query. – tropicalmug May 14 '15 at 16:07
  • 1
    Are you actually executing that query? Since the `a` and `w` parameters in the `:in` line should be `?a` and `?w`. – guilespi May 14 '15 at 17:01
  • Yes, I am. Yes, there are other structural things which I need to fix. The error does not pertain to either of those parameters and remains the same when I fix it. – tropicalmug May 15 '15 at 01:31

1 Answers1

1

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]}
Anthony R.
  • 695
  • 4
  • 10
  • I deleted cider-nrepl from my local maven repo and reran everything and it works now. Thanks for your help in debugging my tools. – tropicalmug May 19 '15 at 01:38