This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clara.test-rules> (clara.rules/defrule lost-game | |
[?ships <- (acc/count) :from [Ship]] | |
[?destroyed <- (acc/count) :from [Destroyed]] | |
[:test (= ?ships ?destroyed)] | |
=> | |
(insert! (->Loser))) | |
#'clara.test-rules/lost-game | |
clara.test-rules> (-> (mk-session [lost-game]) .rulebase :alpha-roots (get Ship)) | |
({:env nil, | |
:children |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (throw (ex-info "Deliberate exception" {:hello :world})) | |
ExceptionInfo Deliberate exception clojure.core/ex-info (core.clj:4617) | |
user=> *e | |
#error { | |
:cause "Deliberate exception" | |
:data {:hello :world} | |
:via | |
[{:type clojure.lang.ExceptionInfo | |
:message "Deliberate exception" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (require 'clara.test-rules) | |
nil | |
user> (in-ns 'clara.test-rules) | |
#namespace[clara.test-rules] | |
clara.test-rules> (defquery query1 | |
"Doc here" | |
[] | |
[?fact <- :a]) | |
#'clara.test-rules/query1 | |
clara.test-rules> (-> (mk-session [query1] :fact-type-fn :clara-fact-type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clara.test-rules> (com/clear-session-cache!) | |
{} | |
clara.test-rules> (defrule first->second-rule | |
[First] | |
=> | |
(insert! (->Second))) | |
#'clara.test-rules/first->second-rule | |
clara.test-rules> (defquery second-query | |
[] | |
[Second]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn constant-accum [v] | |
(accumulate | |
:initial-value v | |
:reduce-fn (constantly v) | |
:combine-fn (constantly v) | |
:retract-fn (constantly v) | |
:convert-return-fn identity)) | |
(deftest nil-accumulate-node-test | |
(let [r1 (dsl/parse-rule [[?r <- (constant-accum nil) :from [Cold]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package clara.benchmark; | |
import java.util.Iterator; | |
/** | |
* Benchmark interface. | |
*/ | |
public interface IBenchmark<T, E> { | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clara.test-rules> (defrule arule [clojure.lang.Keyword (= :a)] => (println "I fired")) | |
#'clara.test-rules/arule | |
clara.test-rules> (-> (mk-session [arule]) (insert :a) (fire-rules)) | |
I fired | |
#object[clara.rules.engine.LocalSession 0x2c848a4e "clara.rules.engine.LocalSession@2c848a4e"] | |
clara.test-rules> (-> (mk-session [arule]) (insert :b) (fire-rules)) | |
I fired | |
#object[clara.rules.engine.LocalSession 0x107e6fae "clara.rules.engine.LocalSession@107e6fae"] | |
clara.test-rules> (defrule arule2 [clojure.lang.Keyword (= this :a)] => (println "I fired")) | |
#'clara.test-rules/arule2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Determine the relative performance of turning a vector into a list | |
;; and popping items off the list versus just using the vector. | |
;; The list approach is asymptotically faster, but the idea is to determine | |
;; at what point the overhead of creating a new list is worth it. | |
(defn time-list [n] | |
(let [init-vec (mapv (constantly 1) | |
(range n))] | |
(time (loop [l (into () init-vec)] | |
(let [r (rest l) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clara.examples.duplicates | |
(:require [clara.rules.accumulators :as acc] | |
[clara.rules :refer :all] | |
[clara.rules.compiler :as c])) | |
(defrecord Temperature [t]) | |
(defrecord Cold [t]) | |
(defrule is-cold? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package unmap_test; | |
import clojure.lang.AFn; | |
import clojure.lang.Compiler; | |
import clojure.lang.IFn; | |
import clojure.lang.IPersistentMap; | |
import clojure.lang.Keyword; | |
import clojure.lang.LockingTransaction; | |
import clojure.lang.RT; | |
import clojure.lang.Symbol; |
NewerOlder