Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple occurances of variable in one clause #240

Open
jonasseglare opened this issue Nov 14, 2017 · 1 comment
Open

Multiple occurances of variable in one clause #240

jonasseglare opened this issue Nov 14, 2017 · 1 comment

Comments

@jonasseglare
Copy link

Thanks for making this library public. I am currently experimenting with Datascript and came across some strange behaviour. Either I am doing something wrong, or maybe it is a bug in Datascript. The problem is best illustrated with unit test that I wrote:

(deftest strange-test
  (let [schema {:db/id {:db/unique :db.unique/identity}
                :expr/depends-on {:db/type :db.type/ref
                            :db/cardinality :db.cardinality/many}}
        conn (datascript/create-conn schema)]
    (datascript/transact!
     conn
     [{:db/id 1}
      {:db/id 2}
      {:db/id 3}
      [:db/add 3 :expr/depends-on 1]
      [:db/add 3 :expr/depends-on 2]
      [:db/add 2 :expr/depends-on 2]])

    ;; Find expressions that depend on themselves.
    ;; This test *fails* but I would expect it to pass. Is it a bug in Datascript?
    (is (= #{[2]}
           (datascript/q
            '[:find ?x
              :where
              [?x :expr/depends-on ?x]]
            @conn)))

    ;; But this, more bulky version, works. It passes, as I expect.
    (is (= #{[2]}
           (datascript/q
            '[:find ?x
              :where
              [?x :expr/depends-on ?y]
              [(= ?x ?y)]]
            @conn)))))

This first is form fails, but I would expect it to pass. The second is form passes, as I would expect. I would expect both to pass.

The Datascript version is 0.16.2.
The error message in the unit test is

Fail in strange-test
expected: (=
 #{[2]}
 (datascript/q '[:find ?x :where [?x :expr/depends-on ?x]] @conn))
  actual: (not (= #{[2]} #{[2] [1]}))

Did I misunderstand something about how Datascript works, or is this a bug? Thank you.

@tonsky
Copy link
Owner

tonsky commented Nov 14, 2017

Hm. I remember hitting it but can’t find any code or even an issue. Let’s consider this a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants