This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-12
Channels
- # babashka (4)
- # beginners (49)
- # biff (17)
- # calva (12)
- # cider (5)
- # clojure-czech (1)
- # clojure-europe (3)
- # clojure-norway (3)
- # core-logic (1)
- # cursive (4)
- # data-science (2)
- # datalevin (7)
- # emacs (1)
- # events (6)
- # fulcro (11)
- # helix (7)
- # hyperfiddle (30)
- # lsp (4)
- # podcasts-discuss (1)
- # practicalli (4)
- # releases (1)
- # remote-jobs (7)
- # ring (6)
- # spacemacs (4)
- # tools-deps (5)
Struggling with some aspects of datalog, hope it's OK to ask here -- I'm not sure how much implementations differ. My question is essentially "how do I call a function within a query", but I'm going to spell everything out, because this might be an XY-problem if I'm modelling it all in the wrong way.
My database contains 3 types of entity: items, group-sets, and groups. A group-set defines a number of groups via :group-set/f
, a function that maps items to its groups, i.e. (f item-entity)
returns a valid group/id
. I guess the groupsets are like demographic splits - if the items were people, the groupsets might be "by gender", "by vote", "by age" etc.
I'd like to extract the groups for a given groupset. My current approach is to get the function with one query, and I'm hoping I can apply it in another, something like:
(d/q '[:find ?group ?item
:in $ ?g
:where
[?item :item/id _]
[?group :group/id (?g (d/pull ?item [*]))]]
db group-set-g)
But obviously I don't know how to call the function ?g
, and I'm also not sure if this is the right approach in the first place.You don’t need to use a function for group-set. Model things as data, don’t use function if you don’t have to.
The data's very dynamic, so functions are a must! I've just spent a couple of hours playing around with rules
and aggregators
and they're all cool, but the syntax I needed was [(?f ?thing) ?binding]
-- combined with rules, that will be much cleaner than repeatedly calling d/q
.
One more question! Is it inefficient to define the rule '[[(identity ?x) [_ _ _]]]
? Is there a better way to specify that a rule should do nothing?
Actually, forget that! The rule I wanted is '[[(f ?x ?e) [?x ?a ?v] [?e ?a ?v]]]
to map something to itself, and I guess it's as efficient as it can be! Thank you for your time, and thanks for making such an awesome product ❤️ I was surprised to find so many Datomic features implemented.