This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-05
Channels
- # announcements (1)
- # babashka (7)
- # beginners (60)
- # biff (7)
- # cider (2)
- # clj-kondo (1)
- # clojure (15)
- # clojure-france (1)
- # clojure-norway (1)
- # clojurescript (7)
- # datascript (7)
- # emacs (4)
- # etaoin (1)
- # honeysql (7)
- # interceptors (8)
- # introduce-yourself (3)
- # kaocha (1)
- # off-topic (16)
- # pathom (2)
- # reagent (15)
- # reitit (11)
- # releases (1)
- # slack-help (3)
- # vim (36)
I'm trying to learn how datascript/datomic rules work.
(def conn (ds/create-conn {}))
(ds/transact! conn
[{:id 1 :size 2}
{:id 2 :size 3}])
(def query '[:find ?size
:in $ % ?id
:where
(size ?id ?size)])
(ds/q query (ds/db conn)
'[[(size ?id ?size)
[?x :id ?id]
[?x :size ?size]]]
1)
;;returns #{[2]} (expected)
(ds/q query (ds/db conn)
'[[(size [?id] ?size) ;; require id be bound by enclosing in vector
[?x :id ?id]
[?x :size ?size]]]
1)
;; returns #{[3] [2]}. not sure why.
Why does requiring the ?id
variable be bound in the rule definition prevent the results from being narrowed with the ?id I'm passing in to the query?I didn’t even know could do in-line rule queries like that :thinking_face:
Oh I see
@U064UGEUQ what happens if you transact 3 diatoms there. Do you get all 3 back? If so, maybe [?id]
is resolving truthy? Just a wild guess
Just ran into this issue. I’ve opened a ticket here: https://github.com/tonsky/datascript/issues/441
👍 1