Fork me on GitHub
#clara
<
2017-07-13
>
fmjrey17:07:47

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?

nickowsy17:07:00

hey @fmjrey, have you taken a look at https://github.com/cerner/clara-examples?

fmjrey17:07:41

yes I did, unless I missed it I have only seen query without params

nickowsy17:07:05

ahh, that could be. A very simple example

(defquery get-promotions
  "Query to find promotions for the purchase."
  [:?type]
  [?promotion <- Promotion (= ?type type)])

nickowsy17:07:16

(query session get-promotions :?type :lunch)

nickowsy17:07:49

that example is from the docs. Are you trying to do something more complicated?

fmjrey17:07:08

this is a java based example, which looks like it uses strings as map keys, will try that now

fmjrey19:07:56

I think I found the issue, I use query variables in some nested part of the expression, as the long error message says.

fmjrey19:07:00

Basically this does not work:

(defquery get-feature
  [:?type :?name :?data]
  [?feature <- Feature (= descriptor [?type ?name ?data])])

fmjrey19:07:47

But this does:

(defquery get-feature
  [:?d]
  [?feature <- Feature (= descriptor ?d)])

fmjrey19:07:42

Thanks @nickowsy for trying 🙂

wparker21:07:35

@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 them

wparker21:07:48

the use in the params doesn’t create them, that is for indexing into the query results later

wparker21:07:35

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

wparker21:07:19

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

dadair23:07:25

Is there a way to react to retractions? I'm using facts to generate tree manipulation functions (i.e., if FactA, AddChildToSomeTree), and want to be able to remove that tree node if the Fact is retracted