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))
I would expect the and
nature of the full set of clauses to bind ?answer
to the empty set, instead I get #{[true]}
I'm confused, that's not the normal datalog syntax..?
you're using standard datascript @mike795?
(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 equivalentalso I think this is maybe kind of what you're looking for?
(ds/q '[:find ?answer
:in ?context ?get-in
:where
[(?get-in ?context [:foo :tags :quux]) ?answer]]
{:foo {:tags #{:bar :baz}}} #(get-in %1 %2))
that binds to the empty set
@mike795 in #datomic i do [(.invoke ?get-int ?context ...)]
but not sure if #datascript behavior like this
@goomba it's the "map datalog syntax". Map syntax is easier to "machines" write/read datalog. "array" syntax is easier to humans write/read
fascinating, I've never seen that before, will have to look into it
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.