A library called clara-rules was suddenly talked about in me, so I summarized it quickly.
--A library that provides an implementation of the rule engine --Separate domain knowledge from code --Available for both clj / cljs --Naturally available from Java --There is also a video of the lecture by the author himself  [](https://www.youtube.com/watch?v = zs5Rueo42TA) -There is also a video of a more recent lecture
--The origin of the expert system ――It was popular for a while because it was attractive that business users could solve problems without going through programmers when there were not enough programmers, but there was a limit. --clara-rules targets programmers, not business users, from the perspective that practically any rule is code.
--If you have some logic and express it as a function call, you need to explicitly write that it passes / receives the information that the logic needs. --The information required by logic changes → Inevitably refactoring is required --There is no need to write information to be passed / received via rules.
session --Representing the state --Insert / retract to add or remove facts --The fact is represented by an instance of the Clojure record --Apply rules to facts added to the session with fire-rules --Immutable value (insert operation returns new session, old session remains) --Like Clojure --In fact, it is designed to be operated with a threading macro.
--Macro for writing rules
--There is a right side and a left side
--Write some judgment logic on the left side (multiple can be written)
--Describe what happens when the judgment becomes truthy on the right side
--Can cause side effects
--You can also add facts to the current session
(defrecord Num [number]) (defrule is-two [Num (= number 2)] => (println "Two!")) (-> (mk-session) (insert (Num 4))) (fire-rules)) ;;Two!
--Check when you are fine! --Edit request too. .. .. ??
Thanks for the clarification ryanbrush!
(defprotocol IFoo (test-foo [this])) (deftype Foo  IFoo (test-foo [this] true)) (defrule is-foo [Foo (test-foo this;;It looks like a symbol that is automatically bound within the scope )] => (println "is a foo")) (-> (mk-session) (insert (Foo.)) (fire-rules)) ;;is a foo