This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-24
Channels
- # announcements (3)
- # babashka (23)
- # beginners (35)
- # cider (3)
- # clara (3)
- # clj-kondo (14)
- # cljdoc (1)
- # cljs-dev (1)
- # clojure (82)
- # clojure-austin (9)
- # clojure-europe (5)
- # clojurescript (23)
- # conjure (62)
- # cursive (73)
- # defnpodcast (1)
- # emacs (3)
- # ethereum (1)
- # gratitude (1)
- # hyperfiddle (12)
- # introduce-yourself (1)
- # leiningen (2)
- # lsp (44)
- # malli (7)
- # polylith (2)
- # portal (17)
- # re-frame (5)
- # reitit (3)
- # sci (8)
- # shadow-cljs (5)
- # tools-build (11)
hey everyone, pretty new to clara rules here - using it to do something similar to the shopping example but more complicated. are there some common code smells / antipatterns to avoid when writing rules? for example, i found myself using 'test' at first for scenarios where there was a more elegant option.
Perhaps avoid putting logic in the RHS? Also try to avoid thinking about your logic in a way that is similar to a case statement, which is inherently ordered. Split the apparent case statement into separate rules with all necessary conditions. If multiple rules are firing where only one should either add more conditions to make them clearly mutually exclusive or implement query logic detecting "conflicting" or "inconclusive" results.
Also perhaps avoid facts with long names such as thisAndThisAndThat. These names suggest there may be a more "primitive" and useful fact hiding in there that can be used with rule conditions providing the equivalent "And" parts to infer more facts as required :)