Skip to content

Instantly share code, notes, and snippets.

@WilliamParker
Created October 14, 2016 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WilliamParker/fae4b2f10034d504c95a7f4e3b11ef0f to your computer and use it in GitHub Desktop.
Save WilliamParker/fae4b2f10034d504c95a7f4e3b11ef0f to your computer and use it in GitHub Desktop.
(deftest test-two-rules-fire-rhs-retraction-both-impacting-other-with-insertion
(let [r1 (dsl/parse-rule [[?f <- First]
[?cold-facts <- (acc/all) :from [Cold]]]
(do
(retract! ?f)
(insert! (->Hot 50))
(insert-unconditional! (->TemperatureHistory (map :temperature ?cold-facts)))))
r2 (dsl/parse-rule [[?s <- Second]
[?hot-facts <- (acc/all) :from [Hot]]]
(do
(retract! ?s)
(insert! (->Cold 50))
(insert-unconditional! (->TemperatureHistory (map :temperature ?hot-facts)))))
q (dsl/parse-query [] [[TemperatureHistory (= ?temps temperatures)]])
empty-session (mk-session [r1 r2 q] :cache false)]
(-> empty-session
(insert (->Cold 40) (->Hot 60))
(insert (->First) (->Second))
fire-rules
(query q)
println)))
;; Prints ({:?temps (60)} {:?temps (40)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment