This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-01
Channels
- # adventofcode (66)
- # announcements (12)
- # aws (8)
- # babashka (28)
- # beginners (160)
- # cider (28)
- # clara (22)
- # clj-kondo (5)
- # cljdoc (40)
- # clojure (129)
- # clojure-australia (2)
- # clojure-europe (24)
- # clojure-gamedev (19)
- # clojure-nl (5)
- # clojure-norway (15)
- # clojure-sanfrancisco (25)
- # clojure-seattle (2)
- # clojure-spec (13)
- # clojure-uk (29)
- # clojurescript (14)
- # cryogen (5)
- # cursive (7)
- # data-science (1)
- # datascript (5)
- # datomic (8)
- # deps-new (5)
- # emacs (19)
- # events (8)
- # fulcro (32)
- # graalvm (7)
- # helix (9)
- # kaocha (3)
- # lambdaisland (1)
- # london-clojurians (4)
- # malli (5)
- # meander (32)
- # off-topic (143)
- # pathom (4)
- # portal (32)
- # re-frame (7)
- # reagent (33)
- # reitit (2)
- # shadow-cljs (5)
- # spacemacs (4)
- # tools-deps (30)
- # vim (1)
Is there a way to update a record? I want to specifically use this with rules that deal with total amounts. I.e. A previous rule would consume part of the total
Can you give a small example of the use-case? From my knowledge, clara doesn’t play nice with stateful manipulations. That being said, it sounds as if you might be able to use an accumulator, but that depends on the use-case
I go shopping, and I have $100 to spend. I want to buy 10 items, which total $200. Each item has a priority, which items can I buy?
I'm thinking I'm going to have to create a new fact and use an accumulator to sort by priority
I’ve only casually used clara but its seems like having $100 will be a fact and if that fact changes it’d cause the session to undo it’s fired rules and re-fire.
My hope was that it if I could update the root fact with the amount of money left and use salience to trigger rules, and when I ran out of money, the rest of the rules wouldn't trigger
@jeff.engebretsen that's my understanding as well
I think like @ethanc said, the accumulator would take in that $100 fact and 10 item priority list fact and spit out 0-10 items
So it looks like I'll likely need my own reducer here. I only want to include the items I can buy. But I'm not really sure how to pass in a sentinel amount.
(defrule find-what-i-can-get
[:money (= ?amount (:amount this))]
[?items <- (acc/reduce-to-accum
(fn [coll item]
;; some way to access `?amount` variable?
...))])
Is there a way to do this. Or do I need to add the total amount I have available to the items
i'm iterating over?
I guess I could use the combine-fn to sort, but I still can't find a way to pass the ?amount
into that fn to limit which items are put out
Accumulators do not allow access of constraint bound vars. It might require doing some of this logic in RHS of the rule. Something like:
(defrule find-what-i-can-get
[:money (= ?amount (:amount this))]
[?items <- (acc/all) :from [:item (< (:cost this) ?amount)]]
[:test (seq ?items)]
=>
(let [sorted-priority (sort-by ... ?items)
... <reduce logic>]
<insert statement>)