Skip to content

Instantly share code, notes, and snippets.

@maxweber
Created December 21, 2016 11:52
Show Gist options
  • Save maxweber/a0027801f2ab94cb7d350c3e6fe703d9 to your computer and use it in GitHub Desktop.
Save maxweber/a0027801f2ab94cb7d350c3e6fe703d9 to your computer and use it in GitHub Desktop.
(ns example
(:require [clara.rules :refer :all]))
(def view-counts
{123 1000})
(def view-event
{:type :view-event
:video 123})
(defquery get-counts
[]
[?count <- :view-count])
(defrule view-count-rule
[:view-event [view-event] (= ?count (get view-counts (:video view-event)))]
=>
(insert! {:type :view-count
:count ?count}))
(defn example []
(-> (mk-session 'example :fact-type-fn :type)
(insert view-event)
(fire-rules)
(query get-counts)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment