Fork me on GitHub

Can Datalog pull groups of things satisfying some predicate about the group? For instance: sets of store-items whose prices sum to $20.


@nathansmutz I can only think of a solution for a constant size sets which is easy but not for different sizes in the same query


@nathansmutz you can do that with sub-queries, where the sub does (sum ..) and the super does the <= 20 pseudo:

[:find ?item
 [(datomic.api/q [:find (sum ...) ?item :where ...]) [?val ?item]]
 [(<= ?val 20)]]


you’d have to figure out the right way to pass the vals from sub to super, using the appropriate :find expression etc


@robert-stuttaford Will the subquery generate all subsets of items? I don't understand the pseudo code.


apologies, i was really just showing how you’d assess aggregations in datalog by nesting queries. as for finding sets, ¯\(ツ)


noticing some unexpected behavior with string tempids. this appears to be happening intermittently. when i create a tx that references another entity in the same transaction like this:

(d/transact! conn 
 [{:db/id "user-tempid" :user/username "mitnick"}
  {:db/id "team-tempid"
   :is-kind/team? true
   :team/name "Test team"
   :team/users #{"user-tempid"}}])
about half the time it will resolve to a ref (expected), and the other half it will result in a literal string "user-tempid" (unexpected) in the collection of :team/users anyone else experienced this? peer is 0.9.5561 and transactor is 0.9.5561


i'm deleting and re-creating database across every test run.


example unexpected result:

#:team{:name "Test team", :users ["user-tempid"]}
of query:
(d/q '[:find (pull ?team [:team/name :team/users]) .
       :where [?team :is-kind/team? true]]


Thanks @robert-stuttaford and @yonatanel . That lets me know I'm probably barking up the wrong tree with Datalog for this part of my problem. I was looking into core.logic; but it currently has trouble with arbitrarily sized sets too. It's Hammock Time


@nathansmutz Maybe with recursive rules?