Skip to content

Instantly share code, notes, and snippets.

@oakes
Last active February 12, 2021 14:30
Show Gist options
  • Save oakes/f2c19782f9b540de4eee09712472d825 to your computer and use it in GitHub Desktop.
Save oakes/f2c19782f9b540de4eee09712472d825 to your computer and use it in GitHub Desktop.
{:deps {net.sekao/odoyle-rules {:mvn/version "RELEASE"}}}
;; this is a test of https://github.com/raquo/Airstream#frp-glitches
;; with my rules engine: https://github.com/oakes/odoyle-rules
;;
;; run `clj -M glitch.clj` and it will print:
;;
;; [-2 false]
;; [2 true]
(require '[odoyle.rules :as o])
(def rules
(o/ruleset
{::is-positive
[:what
[::number ::any any-num]
:then
(o/insert! ::number ::positive? (pos? any-num))]
::doubled-numbers
[:what
[::number ::any any-num]
:then
(o/insert! ::number ::doubled (* 2 any-num))]
::combined
[:what
[::number ::positive? positive?]
[::number ::doubled doubled]
:then
(o/insert! ::number ::combined [doubled positive?])]
::print-combined
[:what
[::number ::combined combined]
:then
(println combined)]}))
(def session
(-> (reduce o/add-rule (o/->session) rules)
(o/insert ::number ::any -1)
o/fire-rules
(o/insert ::number ::any 1)
o/fire-rules))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment