This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-20
Channels
- # announcements (16)
- # babashka (104)
- # beginners (77)
- # bristol-clojurians (1)
- # calva (3)
- # chlorine-clover (50)
- # cider (19)
- # clojure (73)
- # clojure-australia (1)
- # clojure-europe (37)
- # clojure-france (3)
- # clojure-nl (3)
- # clojure-norway (13)
- # clojure-spec (21)
- # clojure-uk (79)
- # clojurescript (225)
- # conjure (102)
- # cursive (11)
- # datascript (1)
- # datomic (1)
- # defnpodcast (1)
- # events (3)
- # figwheel-main (2)
- # fulcro (49)
- # ghostwheel (10)
- # helix (1)
- # kaocha (17)
- # leiningen (10)
- # meander (1)
- # off-topic (26)
- # other-lisps (3)
- # pathom (5)
- # re-frame (40)
- # reagent (6)
- # reitit (33)
- # shadow-cljs (107)
- # testing (3)
- # tools-deps (68)
- # xtdb (16)
- # yada (3)
Is it possible to pass a db into a rule? As a very simple example, I have this query:
(let [db0 (d/db-with (d/empty-db) [{:name "Mark" :color :red}])
db1 (d/db-with (d/empty-db) [{:first-name "Mark" :food :pizza}])
db2 (d/db-with (d/empty-db) [{:src :name :dst :first-name}])]
(d/q
'[:find ?n ?c ?f
:in $0 $1 $2
:where
[$0 ?e ?src-key ?n]
[$0 ?e :color ?c]
[$2 ?m :src ?src-key]
[$2 ?m :dst ?dst-key]
[$1 ?t ?dst-key ?n]
[$1 ?t :food ?f]]
db0 db1 db2))
I want to capture the src/dst mapping as a rule, basically using db2 to hold the relationships between db0 and db1. I tried the following approach without success:
(let [db0 (d/db-with (d/empty-db) [{:name "Mark" :color :red}])
db1 (d/db-with (d/empty-db) [{:first-name "Mark" :food :pizza}])
db-join (d/db-with (d/empty-db) [{:src :name :dst :first-name}])]
(d/q
'[:find ?n ?c ?f
:in $0 $1 $2 %
:where
[$0 ?e ?src-key ?n]
[$0 ?e :color ?c]
(rosetta-stone $2 ?src-key ?dst-key)
[$1 ?t ?dst-key ?n]
[$1 ?t :food ?f]]
db-join
db0
db1
'(((rosetta-stone $ ?src-key? dst-key)
[$ ?e :src ?src-key]
[$ ?e :dst ?dst-key]))))
This results in:
Execution error (ExceptionInfo) at datascript.parser/parse-rule-expr (parser.cljc:462).
Cannot parse rule-expr arguments, expected [ (variable | constant | '_')+ ]
I've tried a couple different permutations of this to no effect. Any ideas? Thanks!