datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
souenzzo 2020-11-18T14:10:51.440Z

Hello Can I do something better then this or-join to create the ?in-cart? value? This do not look like right.

'[:find ?name ?in-cart?
  :keys :item/name :item/in-cart?
  :where
  [?item :item/name ?name]
  (or-join [?item ?in-cart?]
           (and [_ :cart/item ?item]
                [(ground true) ?in-cart?])
           (and (not [_ :cart/item ?item])
                [(ground false) ?in-cart?]))]
Full runnable example here https://gist.github.com/souenzzo/ebd049a99443883ebab180ff019400ba

favila 2020-11-18T14:13:39.440100Z

This is what I would do. Why does it not look right?

favila 2020-11-18T14:15:11.440300Z

I was going to suggest get-else as another possibility, but the reference is in the wrong direction

souenzzo 2020-11-18T14:15:19.440600Z

or > and // and not feels to nested. Not sure if there is some missing? or any other function to help

favila 2020-11-18T14:16:15.440800Z

you could use a named rule, that would eliminate all the nesting

👍 1
favila 2020-11-18T14:17:46.441100Z

'[[(item-in-cart? [?item] ?in-cart?)
   [_ :cart/item ?item]
   [(ground true) ?in-cart?]]
  [(item-in-cart? [?item] ?in-cart?)
   (not [_ :cart/item ?item])
   [(ground false) ?in-cart?]]]

favila 2020-11-18T14:18:26.441300Z

… :where [?item :item/name ?name](item-in-cart? ?item ?in-cart?)

souenzzo 2020-11-18T14:19:50.441500Z

Rules can have the same name, then they will behave as a "or"? 😮 There is more examples/docs about this?

favila 2020-11-18T14:41:33.441700Z

https://docs.datomic.com/on-prem/query.html#rules

favila 2020-11-18T14:41:41.441900Z

> Rules with multiple definitions will evaluate them as different logical paths to the same conclusion (i.e. logical OR). Here’s a rule, again from the Seattle example, which identifies communities that are “social-media”.

favila 2020-11-18T14:42:06.442100Z

This was the only way to express “or” before or, and etc were added

favila 2020-11-18T14:42:28.442300Z

these are actually just syntax sugar for anonymous rules

favila 2020-11-18T14:42:45.442500Z

(with gensym-ed names)

2020-11-18T15:37:50.443800Z

Am I doing something wrong? I want to retract all values of the group attribute:

(d/q '[:find ?group
       :where [17592186048817 :group ?group]]
     db)
=> #{[#uuid"5ede7e84-c6ac-4116-82d4-0f6dfae77b9d"]}
@(d/transact conn [[:db/retract 17592186048817 :group]])
Execution error (IndexOutOfBoundsException) at datomic.db.ProcessInpoint/inject (db.clj:2472).

favila 2020-11-18T15:48:23.443900Z

Maybe double-check your version. This feature is relatively recent

favila 2020-11-18T15:49:47.444500Z

you need those versions or greater

2020-11-18T15:50:20.444700Z

Ah, ok, we are using an older version, thanks much

2020-11-18T15:51:26.444900Z

Yup, that was it, thanks again.