Fork me on GitHub
#clara
<
2020-01-08
>
iagwanderson14:01:50

is it possible to remove a rule from a session before firing it? I say that because I have a namespace with 10 rules and I want to run 9 of them. I would prefer to insert all the namespace and remove the single one

ethanc16:01:30

@iagwanderson, Currently there is no way to add/remove rules from the rulebase after the session has been created

mikerod16:01:31

@iagwanderson as I think you already know you can pass a collection of rules to make a session too.

mikerod16:01:47

However it’s more of a “white list”. And you seem to want a “black list”

iagwanderson16:01:01

exactly, just to avoid typing too much

mikerod16:01:05

You can list rule names in a vector in a var as well with :production-seq metadata. But still doesn’t help you. You can do dynamic stuff to make session to if you use the clara.rules.compiler/mk-session* which is a fn instead of macro

mikerod16:01:43

Doing that you could do some manual dynamic stuff with clj ns-publics where you removed the rules you didn’t want.

iagwanderson16:01:01

uhmmm... interesting...

mikerod16:01:13

Or depending on what you’re doing. You could comment out your rule you don’t want and reload ensuring the ns has the old var removed. Hah.

mikerod16:01:33

With ns-unmap I believe.

iagwanderson16:01:31

hah.. this option is not possible here 😕 but I will try the dynamic one later. This is more a convenience than a requirement right now

iagwanderson16:01:01

do you think this functionality would be welcome to clara.core? I can try to implement it as a side project here

iagwanderson16:01:11

I'm making a real investment in this library in my project, so I wish to learn the internals better some time 😃

mikerod17:01:38

@iagwanderson it seems reasonable to think there could be support for ignoring certain rules. mk-session supports options so it could be added there perhaps. Or maybe rules could just be marked with metadata when wanting something like this.

iagwanderson11:01:32

I was thinking in this API:

(defrecord Values [id])

  (defrule testing->include
    [?value <- Values [v] (= ?id (:id v))]
    =>
    (println "INCLUDING!!! " ?value))

  (defrule testing->exclude
    [?value <- Values [v] (= ?id (:id v))]
    =>
    (println "EXCLUDING!!! " ?value))

  
  (def session-without (rl/mk-session 'clara.rules.compiler/testing->include
                                      'clara.rules.compiler/testing->exclude
                                      :blacklist ['clara.rules.compiler/testing->exclude]))

iagwanderson11:01:11

I already have a working solution to this problem. I am touching only the clara.rules.compiler/mk-session function. There are many tests namespaces in the project. I was thinking to add a new one with tests to this specific functionality, what you suggests?

iagwanderson13:01:55

Weird, when I add a new test file to the common folder I get this error from lein test command.

clojure.lang.ExceptionInfo: failed compiling file:src/test/common/clara/test_common.cljc {:file #object[.File 0x1085a882 "src/test/common/clara/test_common.cljc"]}