Multiple occurances of variable in one clause
Nobody has claimed this yet.
- Dominant language
- Clojure
- Stars
- 5.8k
- Forks
- 318
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied strange-test reproduction and the datascript/q entry point; run it against the reported 0.16.2 behavior. Compare the two query forms, and consider the issue done when the repeated-variable form returns #{[2]} consistently with the explicit equality form, with the regression covered by the test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100