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 :inFrom 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
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)@tonsky Awesome! Thank you, that was the distinction I was missing!