clara

http://www.clara-rules.org/
david_clojurian 2019-02-02T11:31:47.101800Z

Hello everyone, I have a problem with clara rules and I hope you can help me. To resolve components that are productive I create facts of dependencies and mark components that are used by productive components as productive as well. Right when I have a loop in the dependency chain, clara rules ends up in a endless loop while firing rules. Here is the code:

(ns clara.error
  (:require [clara.rules :refer :all]))

(defrecord DependsOn [element dep])
(defrecord Productive [element])

(defrule productive
  ""
  [DependsOn (= ?element1 element) (= ?element2 dep)]
  [Productive (= ?element1 element)]
  =>
  (insert! (->Productive ?element2)))

; Works
(as-> (mk-session 'clara.error) $
      (apply insert $ [(->Productive "A")])
      (apply insert $ [(->DependsOn "A" "B")
                       (->DependsOn "B" "C")
                       (->DependsOn "C" "D")])
      (fire-rules $))

; ends in a loop
(as-> (mk-session 'clara.error) $
      (apply insert $ [(->Productive "A")])
      (apply insert $ [(->DependsOn "A" "B")
                       (->DependsOn "B" "C")
                       (->DependsOn "C" "A")])
      (fire-rules $))
The approach of clara rules is awesome. That's why I hope we can find the problem so I can continue using clara rules. Thanks in advance.