Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

clara-rules

595 views

Published on

I gave a talk about an excellent Clojure/ClojureScript rule engine library at Ichigaya Geek Night September 22 2017. https://ichigayageek.connpass.com/event/65356/

Published in: Software
  • Be the first to comment

  • Be the first to like this

clara-rules

  1. 1. - Cybozu Startups, inc - Write web apps with Clojure/ClojureScript - Since May 2016
  2. 2. - http://qiita.com/iku000888 - http://github.com/iku000888 - https://twitter.com/iku000888
  3. 3. - Rule Engines - About - Are good - Clara-rules - Facts - defrule & defquery - session - serialization - Use from Java - RETE - Application in UI dev
  4. 4. - http://www.clara-rules.org/ - [com.cerner/clara-rules "0.16.0"] - Clojure(JVM) - ClojureScript(Browser etc)
  5. 5. - Historical: - Shortage of devs - Let non devs code domain logic - Lisp! - Prolog! - Branch of AI! - Failed or not debate App Domain Logic Domain Logic
  6. 6. - ANA case - JBoss BRMS - https://japan.zdnet.com/article/35107193/ - ‘作業時間を20〜40%削減’!! - ‘スクラッチ開発と比較すると約3分の1の低コスト’!!
  7. 7. Layers of functions! - Responsibility of each layer? - Border line case? - Change in function params? - Brittle! - Spaghetti! Controller DB View External Service
  8. 8. Controller DB View External Service
  9. 9. Controller DB View External Service session QueriesRules Insert Facts Fire! Q u e r y Q u e r y
  10. 10. - Anything - Typically record or Java Class ;; Clojure (defrecord Item [item-name id price]) //Java public Class Item{ String itemName etc... }
  11. 11. - Match with fact(s) in session - LFS => RHS - Bind variables (LFS) - Join with other facts (LFS) - Create new facts (RHS) (r/defrule tax-item [Item (= ?n item-name) (= ?id id) (= ?p price)] [Tax (= id ?id) (= ?t tax)] => (r/insert! (->TaxedItem ?n ?id (+ ?p (* ?p ?t)))))
  12. 12. - Can take parameter - Accumulators - Cator to result consumers
  13. 13. (require '[clara.rules.accumulators :as acc]) (r/defquery total [] ;; Can accept parameter [?total <- (acc/sum :taxed-price) :from [TaxedItem]])
  14. 14. - App interface - Immutable: ops return new sessions - Insert facts - Fire - Query Results
  15. 15. (-> (r/mk-session);;defsession also (r/insert (->Item "fish" "001" 200)) (r/insert (->Tax "001" 0.08)) (r/insert (->Item "milk" "002" 150)) (r/insert (->Tax "002" 0.28)) (r/fire-rules) (r/query total))
  16. 16. - Advanced - e.g. Hot load rules from a remote server - e.g. Store working session in DB - e.g. Validate rules with hash
  17. 17. Still write rules/queries in Clojure Official website:
  18. 18. - Used by many rule engines - Allows clara-rules to be fast - RETEII, RETEIII - ‘Dramatically faster’ for complex problems - Proprietary! - Bummer!
  19. 19. - Makes code clean - Query -> View(React) - Events -> Facts - Instances - Precept - Fact UI
  20. 20. clara-rules: 1. Helps keep your code clean 2. Can be used to build cool stuff 3. Compelling excuse to introduce Clojure for Java/Scala/etc users
  21. 21. http://qiita.com/iku000888/items/72525cd34cd3c0b44b31
  22. 22. Talks: Clarifying Rules Engines with Clara Rules - Mike Rodriguez - https://www.youtube.com/watch?v=Q_k5MkZmd-o "Retaking Rules for Developers" by Ryan Brush - https://www.youtube.com/watch?v=Z6oVuYmRgkk Midwest.io 2014 - Rules as a Control Structure - Ryan Brush - https://www.youtube.com/watch?v=zs5Rueo42TA

×