tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.49k stars 309 forks source link

Rules - Required bindings doesn't evaluate correctly #441

Open rjsheperd opened 1 year ago

rjsheperd commented 1 year ago

Attempting to follow the Datomic Rules with required bindings documentation and discovered this bug in DataScript.

Here's a short example:

 (d/q '[:find ?need
            :in $ % ?name
            :where (needs ?name ?need)]
    '[["george" :wants :foo]
      ["george" :needs :foo]
      ["sally"  :needs :bar]]
    '[[(needs ?name ?need) [?name :needs ?need]]] "george")
;; => #{[:foo]} (expected)

;; Now try with ?name being a required binding by placing it in brackets
;; -- (needs ?name ?need) -> (needs [?name] ?need)

(d/q '[:find ?need
            :in $ % ?name
            :where (needs ?name ?need)]
    '[["george" :wants :foo]
      ["george" :needs :foo]
      ["sally"  :needs :bar]]
    '[[(needs [?name] ?need) [?name :needs ?need]]] "george")
;; => #{[:foo :bar]} (incorrect)

It may be that the required binding version is always evaluating to true.

tonsky commented 1 year ago

I don’t think we support this. There’s some work in the parser but it’s not used in current query impl. There are no tests on this either