This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-13
Channels
- # bangalore-clj (1)
- # beginners (40)
- # boot (22)
- # clara (19)
- # cljs-dev (265)
- # clojure (160)
- # clojure-dev (6)
- # clojure-italy (5)
- # clojure-russia (47)
- # clojure-spec (10)
- # clojure-uk (63)
- # clojurescript (88)
- # core-async (8)
- # cursive (54)
- # datomic (48)
- # emacs (32)
- # garden (3)
- # graphql (29)
- # hoplon (54)
- # jobs (1)
- # klipse (4)
- # luminus (5)
- # lumo (21)
- # mount (5)
- # off-topic (16)
- # om (2)
- # pedestal (10)
- # play-clj (1)
- # portkey (32)
- # re-frame (21)
- # reagent (48)
- # rum (1)
- # spacemacs (4)
- # sql (3)
- # unrepl (5)
Hi, new to clara here, and having difficulties with query parameters, is there an example of query with parameters that I could look at somewhere?
hey @fmjrey, have you taken a look at https://github.com/cerner/clara-examples?
ahh, that could be. A very simple example
(defquery get-promotions
"Query to find promotions for the purchase."
[:?type]
[?promotion <- Promotion (= ?type type)])
yeah I saw that example, and now looking at this: https://github.com/cerner/clara-rules/blob/cbecbdf916625a46ee93e7c84ed411aab3f1dbc1/src/test/clojure/clara/test_java.clj#L51
this is a java based example, which looks like it uses strings as map keys, will try that now
I think I found the issue, I use query variables in some nested part of the expression, as the long error message says.
Basically this does not work:
(defquery get-feature
[:?type :?name :?data]
[?feature <- Feature (= descriptor [?type ?name ?data])])
@fmjrey the params have to be in the query conditions
(defquery get-feature
[:?type :?name :?data]
[?feature <- Feature (= descriptor [?type ?name ?data])])
is trying to use bindings in the Feature condition without creating themthe use in the params doesn’t create them, that is for indexing into the query results later
Basically the query params won’t make an otherwise-invalid query valid, they just control how you’ll view the data later when using the query results
So in the “promotion type” example in the doc, you’ll provide a type to query for, and you’ll only get results back of that type; without the param you’d get back other types as well
This is the key line of code: https://github.com/cerner/clara-rules/blob/master/src/main/clojure/clara/rules/engine.cljc#L1960