datascript

seepel 2022-07-22T00:32:56.065849Z

I'm trying to execute a query using the missing? rule should I expect this to work?

(d/q '[:find ?e
       :where (missing? $ ?e :parent)]
     @conn)
I get an error about not passing rules in, do I need push built-in rules myself? If so, where would I find them?
Missing rules var '%' in :in

RJ Sheperd 2022-07-22T16:52:39.364029Z

From the tests, it looks like missing? is a built-in rule: https://github.com/tonsky/datascript/blob/cd129b7a9ef2fc31fa95873c376691f272752832/test/datascript/test/query_fns.cljc#L47-L52

Niki 2022-07-22T21:40:31.098169Z

There are two things: • missing is built-in predicate, not rule. Datomic and DataScript make a distinction between the two. To invoke rule you go (rule-name args...) and to invoke predicate [(pred-name args...)] • predicates should work on existing vars, they can’t define their own. Think of them as function calls. [(missing? $ ?e :parent)] means “from all known ?e that we’ve seen so far, only keep those that return truth in (missing ?e :parent)”. But ?e must already be defined somehow, normally through simple pattern-matching Try

(d/q '[:find ?e
       :where [?e _ _]
              [(missing? $ ?e :parent)]]
     @conn)

seepel 2022-07-22T22:53:51.264699Z

@tonsky Awesome! Thank you, that was the distinction I was missing!