Fork me on GitHub
#datomic
<
2020-11-18
>
souenzzo14:11:51

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

favila14:11:39

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

favila14:11:11

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

souenzzo14:11:19

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

favila14:11:15

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

👍 3
favila14:11:46

'[[(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?]]]

favila14:11:26

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

souenzzo14:11:50

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

favila14:11:41

> 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”.

favila14:11:06

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

favila14:11:28

these are actually just syntax sugar for anonymous rules

favila14:11:45

(with gensym-ed names)

manutter5115:11:50

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).

favila15:11:23

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

favila15:11:47

you need those versions or greater

manutter5115:11:20

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

manutter5115:11:26

Yup, that was it, thanks again.