This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-07
Channels
- # announcements (11)
- # architecture (2)
- # babashka (84)
- # beginners (226)
- # calva (7)
- # chlorine-clover (4)
- # cider (29)
- # clara (17)
- # clj-kondo (23)
- # cljs-dev (58)
- # cljsrn (60)
- # clojure (172)
- # clojure-europe (24)
- # clojure-finland (2)
- # clojure-italy (6)
- # clojure-nl (8)
- # clojure-spec (4)
- # clojure-uk (22)
- # clojurescript (44)
- # conjure (39)
- # core-async (64)
- # cursive (76)
- # data-science (15)
- # duct (3)
- # emacs (2)
- # events (5)
- # fulcro (30)
- # helix (4)
- # jackdaw (5)
- # juxt (1)
- # kaocha (1)
- # leiningen (4)
- # off-topic (9)
- # pathom (22)
- # re-frame (9)
- # reagent (33)
- # reitit (3)
- # ring (10)
- # ring-swagger (2)
- # shadow-cljs (192)
- # spacemacs (27)
- # specter (2)
- # sql (59)
- # vim (2)
(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/fire-rules
(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/fire-rules
(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
> 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 http://dpaste.com/1QSB24C
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 https://gist.github.com/oskarkv/74cf41ab8937326beabc695711c19618
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.