datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
mtm 2019-09-13T00:16:28.005900Z

how would one go about finding out simply if there were any matches for an arbitrary set of clauses in a find? I'm not interested in binding any solutions to the clause, just the fact that there was actually at least one solution. I'm trying to build a generic "datascript predicate" where a user will pass in their clauses and I'll return true if there is a solution. For example, if the user supplied clause were the [(?get-in... bit of this example:

(ds/q '{:find [?answer]
        :in [?context ?get-in]
        :where [[(?get-in ?context [:foo :tags :quux])]
                [(ground true) ?answer]]}
      {:foo {:tags #{:bar :baz}}} #(get-in %1 %2))

mtm 2019-09-13T00:17:18.006700Z

I would expect the and nature of the full set of clauses to bind ?answer to the empty set, instead I get #{[true]}

unbalanced 2019-09-13T13:52:51.007300Z

I'm confused, that's not the normal datalog syntax..?

unbalanced 2019-09-13T13:53:26.007700Z

you're using standard datascript @mike795?

unbalanced 2019-09-13T13:55:21.008600Z

(ds/q '[:find (seq ?answer)
        :in ?context ?get-in
        :where [[(?get-in ?context [:foo :tags :quux])]
                [(ground true) ?answer]]]
      {:foo {:tags #{:bar :baz}}} #(get-in %1 %2))
would be the conventional equivalent

unbalanced 2019-09-13T14:02:15.009Z

also I think this is maybe kind of what you're looking for?

unbalanced 2019-09-13T14:02:17.009200Z

(ds/q '[:find ?answer
          :in ?context ?get-in
          :where
          [(?get-in ?context [:foo :tags :quux]) ?answer]]
        {:foo {:tags #{:bar :baz}}} #(get-in %1 %2))

unbalanced 2019-09-13T14:02:36.009400Z

that binds to the empty set

souenzzo 2019-09-13T15:20:33.010500Z

@mike795 in #datomic i do [(.invoke ?get-int ?context ...)] but not sure if #datascript behavior like this

souenzzo 2019-09-13T15:21:37.011500Z

@goomba it's the "map datalog syntax". Map syntax is easier to "machines" write/read datalog. "array" syntax is easier to humans write/read

unbalanced 2019-09-13T15:27:30.011800Z

fascinating, I've never seen that before, will have to look into it

2019-09-16T18:44:14.000100Z

As @souenzzo suggests, it's helpful when you're dynamically/programatically constructing queries (e.g. a sophisticated search UI). Modifying clauses in a list is hard to do programatically, but quite straight forward when organized in a map.