Fork me on GitHub
#clara
<
2018-02-12
>
yyoncho16:02:07

Here is simplified example of what I am trying to accomplish: I have fact FnHolder which contains how the Temperature facts will be compared/processed. I want to have a rule which produces another fact from the FnHolder and the Temperature but it doesn't trigger the depending rules when a new Temperature which doesn't change the produced value(thus I cannot do the accumulation in the body). This behavior is similar to acc/max which does not trigger if a non-maximal Temperature is inserted. Ideally I would have been able to write the following code but it doesn't run since ?fn is not visible in the custom-accum block. Can you advice? code (defrecord Temperature [location temperature]) (defrecord FnHolder [location other-params]) (defrule chaning [?fn <- FnHolder (= location ?loc)] [?t <- (custom-accum ?fn) :from [Temperature]] => ;; insert facts... ) code

mikerod17:02:27

@yyoncho I don’t have an immediate complete answer to that question, but perhaps you could accomplish what you are wanting with a :test condition after the accumulation. Accumulate with something that doesn’t need to be “parameterized”.

mikerod17:02:15

Another possibility is to use a sort of joined fact. I’m not sure how appropriate it will be for you, but it would look like:

mikerod17:02:54

(defrecord Temperature [location temperature])
(defrecord FnHolder [location other-params])
(defrecord TempWithFn [temp fn-holder])

(defrule combine
  [?fn <- FnHolder  (= location ?loc)]
  [?t <- Temperature]
  =>
  (insert (->TempWithFn ?t ?fn)))

(defrule chaning
  [?t <- (custom-accum :fn-holder) :from [TempWithFn]]
  =>
  ;; insert facts...
)

mikerod17:02:35

I think the custom-accum doesn’t really need the :fn-holder key anymore though. it has the whole fact with all that info on it.