Fork me on GitHub
#clara
<
2016-11-25
>
nlessa00:11:53

Hi, is there any way to set an observable to a clara session to get any new insertion/rectraction fo facts? (I am wondering if it would be possible to use a clara session as a source of a stream of facts).

wparker11:11:05

@nlessa Clara only returns new sessions in response to external calls to insert, retract, fire-rules etc. so if you’re looking to listen for changes in response to those actions I’d suggest just querying the session after those calls. It is also possible to add arbitrary listeners to a session - you can see the protocol at https://github.com/cerner/clara-rules/blob/master/src/main/clojure/clara/rules/listener.cljc and an example that simply records all operations listened upon at https://github.com/cerner/clara-rules/blob/master/src/main/clojure/clara/tools/tracing.clj - but keep in mind that listeners often take you into internal implementation details that could change. Also Clara sessions are immutable, in keeping with typical Clojure data structure semantics. Inserting/retracting facts and firing rules returns a new session with the relevant operation applied but leaves the original unchanged. It might be possible to give a better answer if we had a better idea what you’re trying to accomplish.