Fork me on GitHub
#datascript
<
2019-09-13
>
mtm00:09:28

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))

mtm00:09:18

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

Lone Ranger13:09:51

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

Lone Ranger13:09:26

you're using standard datascript @mike795?

Lone Ranger13:09:21

(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

Lone Ranger14:09:15

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

Lone Ranger14:09:17

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

Lone Ranger14:09:36

that binds to the empty set

souenzzo15:09:33

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

souenzzo15:09:37

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

Lone Ranger15:09:30

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

metasoarous18:09:14

As @U2J4FRT2T 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.