Fork me on GitHub
#datomic
<
2017-03-11
>
nathansmutz02:03:49

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

yonatanel09:03:52

@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

robert-stuttaford10:03:37

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

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

robert-stuttaford10:03:29

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

yonatanel11:03:53

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

robert-stuttaford11:03:58

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

devth20:03:28

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

devth20:03:31

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

devth20:03:26

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]]
     db)

nathansmutz20:03:07

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

yonatanel23:03:32

@nathansmutz Maybe with recursive rules?