Fork me on GitHub

(cr/defquery my-query
  [:?x :?y]
  [?p <- (acc/all) :from [Player]])

(defn oktest []
  (-> (cr/mk-session)
    (cr/insert (->Player 0 0 0))
    (cr/insert (->Player 1 2 3))
    (cr/query my-query :?x 0 :?y 0)))
This does not produce any results. But if I use ?x and ?y in the query, e.g. (= ?x x) and same for y then it does produce results. This is kind of surprising since in normal functions one doesn't have to use the args. Is there any particular reason for this? Same if I remove the arguments :?x and :?y from the query but keep them in the call to cr/query, then the query doesn't produce any results. Also a bit confusing.


And apparently this doesn't work. I'm confused about queries.

(cr/defquery my-query
  [:?x :?y]
  [?p <- (acc/all) :from [Player (> x ?x) (> y ?y)]])

(defn oktest []
  (-> (cr/mk-session)
    (cr/insert (->Player 1 1 1))
    (cr/insert (->Player 2 2 2))
    (cr/query my-query :?x 0 :?y 0)))


What can and should the arguments be used for? Only for testing equality? I don't get it.


@oskarkv perhaps try it all again with (cr/mk-session :cache false) just to make sure


It sounds like you are describing 3 variations you have tested


> What can and should the arguments be used for? Only for testing equality? I don’t get it. this should not be the case


In the last case I get this error


That's the one with (> x ?x) as constraints


I restarted Clojure and added :cache false but nothing was different


So with (= x ?x) I get results if I pass in the correct arguments. With (> x ?x) I get an error. Not using ?x at all in the query body produce no results although I think it should. Having an empty args vector in the query but passing args in when calling produce no results either. And finally using no args in the query or when calling I get results again. I am very confused.


clarax.queriestest> (q1test)
with (= ?x x)
({:?x 1, :?y 1, :?p [{:x 1, :y 1, :z 1}]})
clarax.queriestest> (q2test)
with no ?x or ?y in body
clarax.queriestest> (q3test)
with no argsvector
clarax.queriestest> (q4test)
argsvector but no args passed in
({:?p [{:x 1, :y 1, :z 1} {:x 2, :y 2, :z 2}]})
clarax.queriestest> (q5test)
no args whatsoever
({:?p [{:x 1, :y 1, :z 1} {:x 2, :y 2, :z 2}]})
clarax.queriestest> (q6test)
with (> x ?x)
Execution error (ExceptionInfo) at clara.rules.compiler/eval18474$sort-conditions$fn (compiler.clj:847).
I used this source I'm using Clara 0.20.0 I would have expected at least q2 with no args in the body to return something, and also the last one with (> x ?x) to work.


@oskarkv I will take a look at this in a bit. My gut reaction as to why this isn’t acting as expected is due to the implementation of how queries are executed directly on clara’s internal memory.


It’d be interesting if it’s not working for non =.


Perhaps that was its original intent though


I was under the assumption that queries never support heavier logic than equality, as its the job of the rules to do more complex filtering and joining logic… Might be a poor assumption on my part but it sure seems like bound variables are the contract


at least in its current implementation