This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-18
Channels
- # admin-announcements (3)
- # alda (1)
- # boot (85)
- # capetown (4)
- # cider (10)
- # clara (16)
- # cljsrn (3)
- # clojars (35)
- # clojure (83)
- # clojure-austin (8)
- # clojure-brasil (4)
- # clojure-canada (16)
- # clojure-greece (2)
- # clojure-ireland (7)
- # clojure-russia (23)
- # clojure-spec (22)
- # clojure-uk (151)
- # clojurescript (97)
- # core-async (10)
- # cursive (1)
- # datascript (7)
- # datomic (21)
- # defnpodcast (13)
- # devcards (3)
- # emacs (4)
- # events (3)
- # hoplon (18)
- # juxt (4)
- # leiningen (7)
- # mount (4)
- # off-topic (2)
- # om (1)
- # onyx (30)
- # planck (6)
- # proton (81)
- # re-frame (3)
- # reagent (9)
- # rum (10)
- # spacemacs (1)
- # specter (6)
- # testing (7)
- # untangled (66)
- # vim (84)
- # yada (23)
Regarding using the fact-type-fn, the automatic field lookup is determined by the type; see https://github.com/rbrush/clara-rules/blob/0.11.1/src/main/clojure/clara/rules/compiler.clj#L152 So right now the auto field access will just be by the record or bean properties. I could conceivably see this is an extension point if there were use-cases for it. However, I don’t see any reason why you can’t use hash bindings for other types. So, for example, something like
I'm actually interested in achieving something similar, is there any kind of field access aside from "auto field access"?
@mattdarling: The fact itself is bound to “this” in the constraints on the RHS (right-hand side) so you can do arbitrary things with it there. So
So the lack of automatic field access shouldn’t prevent you from doing anything functionality, it is purely a bit of syntax sugar
That said, no, I don’t believe anything other than records or beans is supported for that syntax sugar now. I don’t think it would be terribly difficult to change the compiler to make that an extension point, perhaps making clara.rules.compiler/get-fields a multifunction (http://clojuredocs.org/clojure.core/defmulti) if someone was interested in doing so and Ryan agreed (I haven’t thought deeply on the issue though, it is possible there would be a complication I’m not seeing immediately).
Got it working as I wanted with "this", thank you! I thought that was just example syntax, not an existing feature
Ah no, the “this” binding and field bindings for Clojure records and JavaBeans exist already and have for some time; they aren’t an experimental feature or anything like that
I had used the bindings for Clojure records initially, but wanted to introduce a bit of polymorphism, so I switched to maps with a key to indicate their type + made that the fact-type-fn