Open

Description
We noticed generated rules in our inspection results when using a compound negation rule. I don't think this is expected, and may be a result of an exception being thrown. Here is a simple test to reproduce:
(defrecord RuleTest [color state])
(defquery class-query
"Return all results"
[]
[?result <- ClaraResultWrapper])
(defrule joeMamaRule
"joeMamaRule"
[:not
[:and
[RuleTest (= "orange" color)]
[RuleTest (= "liquid" state)]
]]
=>
(print "****Rule Executed****\n"))
(defn -main
[]
(clarainspector/explain-activations (-> (mk-session [joeMamaRule class-query])
(insert (->RuleTest "orange" "liquid"))
(fire-rules))))
Running this will produce the unexpected behavior, but also indicates an exception had occurred:
rule myrule.test/joeMamaRule__G__7701
executed
(clara.rules/insert! (clara.rules.engine/->NegationResult myrule.test/joeMamaRule__G__7701))
with bindings
{}
because
Exception in thread "main" java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap, compiling:(/private/var/folders/4l/t6wwdv9177dbp7x8swwwk7vmkg8vlj/T/form-init2501212382920230134.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap
at clojure.lang.RT.nthFrom(RT.java:947)
at clojure.lang.RT.nth(RT.java:897)
at clara.tools.inspect$explain_activation.invokeStatic(inspect.clj:197)
at clara.tools.inspect$explain_activation.invoke(inspect.clj:193)
at clara.tools.inspect$explain_activations.invokeStatic(inspect.clj:232)
at clara.tools.inspect$explain_activations.doInvoke(inspect.clj:212)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at myrule.test$_main.invokeStatic(test.clj:73)
at myrule.test$_main.invoke(test.clj:70)
at clojure.lang.Var.invoke(Var.java:375)
at user$eval5.invokeStatic(form-init2501212382920230134.clj:1)
at user$eval5.invoke(form-init2501212382920230134.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6927)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.load(Compiler.java:7379)
... 14 more
This result only occurs when both/all parts of the AND
logic evaluate to true, making the compound negation false (effectively not triggering the rule). If only one/some (or none) of the AND
logic evaluates to true, the rule is triggered as expected, and the inspection results are as expected, meaning they only include our defined rule and no generated rules.