Skip to content

Commit b92f791

Browse files
authored
feat: implement hierarchy loaders, fact loaders, update deps (#2)
* wip: hierarchy work in progress * feat: more progress implementing def'd hierarchies and facts * fix: fix rule loading tests and fact loading handling of functions * chore: update deps * feat: linter updates and add defdata macro
1 parent bee29ff commit b92f791

File tree

10 files changed

+397
-75
lines changed

10 files changed

+397
-75
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
This is a history of changes to k13labs/clara-rules.
22

33
# 1.4.0-SNAPSHOT
4+
* include linter fixes for `defrule` and `defquery` which were not processing docstrings correctly.
45
* `defrule` now defines rules as functions with two arities, no args returns the rule map, and 2 args is the compiled RHS.
56
* `clojure.lang.Fn` now implements `clara.rules.compiler/IRuleSource`, and returns a single rule by invoking the like `(a-rule)`.
67
* add built-in support to serialize `clojure.lang.Var` so that a rule handler var can be serialized correctly.
78
* add function `clara.rules.compiler/load-rules-from-source` to simplify loading rules
9+
* add `defhierarchy` macro to define hierarchies of facts allowing to easily establish parent/child relationships.
10+
* add `defdata` macro to define facts and collections of facts in namespaces allowing to easily embed and insert them during mk-session.
11+
* rename `clear-ns-productions!` to `clear-ns-vars!` since now there are ns-installed vars that are not productions.
812

913
# 1.3.2
1014
* Enhance memory add-activations implementation by replacing get/set with compute!

clj-kondo/clj-kondo.exports/clara/rules/config.edn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{:lint-as {clara.rules/defsession clojure.core/def
2+
clara.rules/defhierarchy clojure.core/def
3+
clara.rules/defdata clojure.core/def
24
clara.rules.platform/eager-for clojure.core/for
35
clara.rules.platform/compute-for clojure.core/for}
46
:hooks {:analyze-call {clara.rules/defquery hooks.clara-rules/analyze-defquery-macro

deps.edn

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
:deps/prep-lib {:alias :build
33
:fn compile-main-java
44
:ensure "target/main/classes"}
5-
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
6-
org.clojure/core.cache {:mvn/version "1.0.225"}
5+
:deps {org.clojure/clojure {:mvn/version "1.11.2"}
6+
org.clojure/core.cache {:mvn/version "1.1.234"}
77
org.clj-commons/digest {:mvn/version "1.4.100"}
8-
com.github.k13labs/futurama {:mvn/version "1.0.2"}
9-
com.cnuernber/ham-fisted {:mvn/version "2.016"}
8+
com.github.k13labs/futurama {:mvn/version "1.0.3"}
9+
com.cnuernber/ham-fisted {:mvn/version "2.017"}
1010
prismatic/schema {:mvn/version "1.4.1"}
11-
org.clojure/data.fressian {:mvn/version "1.0.0"}}
11+
org.clojure/data.fressian {:mvn/version "1.1.0"}}
1212

1313
;for more examples of aliases see: https://github.com/seancorfield/dot-clojure
1414
:aliases
1515
{:build {:paths ["tool"]
16-
:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}}
16+
:deps {io.github.clojure/tools.build {:mvn/version "0.10.0"}}
1717
:ns-default build}
1818
:dev {:extra-paths ["dev"]
1919
:extra-deps {reloaded.repl/reloaded.repl {:mvn/version "0.2.4"}
20-
org.clojure/math.combinatorics {:mvn/version "0.1.3"}
20+
org.clojure/math.combinatorics {:mvn/version "0.3.0"}
2121
criterium/criterium {:mvn/version "0.4.6"}}}
2222

23-
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2023.12.15"}}
23+
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.03.05"}}
2424
:main-opts ["-m" "clj-kondo.main"]}
2525

2626
:test {:extra-paths ["src/test/clojure" "target/test/classes"]
27-
:extra-deps {lambdaisland/kaocha {:mvn/version "1.80.1274"}
27+
:extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}
2828
lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}
2929
lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"}
3030
org.clojure/test.check {:mvn/version "1.1.1"}
31-
pjstadig/humane-test-output {:mvn/version "0.10.0"}}}
31+
pjstadig/humane-test-output {:mvn/version "0.11.0"}}}
3232

3333
:runner {:main-opts ["-e" "(println \"warn-on-reflection =\" (set! *warn-on-reflection* true))"
3434
"-m" "kaocha.runner"]
3535
:exec-fn kaocha.runner/exec-fn}
3636

3737

38-
:repl {:extra-deps {nrepl/nrepl {:mvn/version "1.1.0"}
39-
cider/cider-nrepl {:mvn/version "0.44.0"}}
38+
:repl {:extra-deps {nrepl/nrepl {:mvn/version "1.1.1"}
39+
cider/cider-nrepl {:mvn/version "0.46.0"}}
4040
:main-opts ["-e" "(println \"warn-on-reflection =\" (set! *warn-on-reflection* true))"
4141
"-m" "nrepl.cmdline" "--interactive"
4242
"--middleware" "[\"cider.nrepl/cider-middleware\"]"]}
@@ -47,20 +47,16 @@
4747
:format-check {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}
4848
:main-opts ["-m" "cljfmt.main" "check" "src" "dev"]}
4949

50-
:outdated {:extra-deps {olical/depot {:mvn/version "2.3.0"}
51-
rewrite-clj/rewrite-clj {:mvn/version "0.6.1"}}
52-
:main-opts ["-m" "depot.outdated.main"]}
53-
54-
:jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.0.216"}}
50+
:jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
5551
:exec-fn hf.depstar/jar
5652
:exec-args {:jar "build/clara-rules.jar"}}
5753

58-
:install-maven {:extra-deps {slipset/deps-deploy {:mvn/version "0.1.5"}}
54+
:install-maven {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.2"}}
5955
:exec-fn deps-deploy.deps-deploy/deploy
6056
:exec-args {:installer :local
6157
:artifact "build/clara-rules.jar"}}
6258

63-
:deploy-maven {:replace-deps {slipset/deps-deploy {:mvn/version "0.1.5"}}
59+
:deploy-maven {:replace-deps {slipset/deps-deploy {:mvn/version "0.2.2"}}
6460
:exec-fn deps-deploy.deps-deploy/deploy
6561
:exec-args {:installer :remote
6662
:artifact "build/clara-rules.jar"}}}

dev/user.clj

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
(ns user
2+
(:refer-clojure :exclude [derive underive])
23
(:require [criterium.core :refer [report-result
34
quick-benchmark] :as crit]
45
[clara.rules.platform :refer [compute-for]]
56
[clojure.core.async :refer [go timeout <!]]
6-
[clara.rules :refer [defrule mk-session clear-ns-productions!]]
7+
[clara.rules :refer [defrule defquery defdata defhierarchy
8+
insert! insert insert-all fire-rules query
9+
mk-session clear-ns-vars!
10+
derive! underive!]]
711
[clara.rules.compiler :as com]
812
[clojure.core.cache.wrapped :as cache]
913
[schema.core :as sc]
@@ -12,10 +16,42 @@
1216
(:import [java.util.concurrent CompletableFuture]))
1317

1418
(comment
19+
(clear-ns-vars!)
1520
(add-tap #'println)
1621
(remove-tap #'println)
1722
(tap> "foobar"))
1823

24+
(defhierarchy foobar
25+
(derive! :thing/foo :thing/that)
26+
(doseq [x (range 20)]
27+
(derive! [:thing/foo (- 20 x)] [:thing/that (- 20 x)]))
28+
(derive! :thing/bar :thing/that))
29+
30+
(defrule return-a-thing
31+
[:thing/that [{:keys [value]}] (= value ?value)]
32+
=>
33+
(insert! {:type :thing/result
34+
:value ?value}))
35+
36+
(defquery query-a-thing
37+
[]
38+
[?output <- :thing/result])
39+
40+
(defdata foo
41+
{:type :thing/foo
42+
:value 1})
43+
44+
(defdata bar
45+
[{:type :thing/bar
46+
:value 2}
47+
{:type :thing/bar
48+
:value 3}])
49+
50+
(time
51+
(-> (mk-session 'user :fact-type-fn :type)
52+
(fire-rules)
53+
(query query-a-thing)))
54+
1955
(def session-cache
2056
(cache/lru-cache-factory {}))
2157

@@ -69,7 +105,7 @@
69105
~@fact-rules))))
70106

71107
(comment
72-
(clear-ns-productions!)
108+
(clear-ns-vars!)
73109
(mk-types 2500)
74110
(def rules
75111
(mk-rules 2500))
@@ -81,7 +117,7 @@
81117

82118
(time
83119
(mk-session 'user [(conj rules {:ns-name (ns-name *ns*)
84-
:lhs [{:type :foobar16
120+
:lhs [{:type :foobar1
85121
:constraints []}]
86122
:rhs `(println ~(str :foobar))})]
87123
:cache session-cache

pom.xml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@
2222
<dependency>
2323
<groupId>org.clojure</groupId>
2424
<artifactId>clojure</artifactId>
25-
<version>1.10.3</version>
25+
<version>1.11.2</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.cnuernber</groupId>
29+
<artifactId>ham-fisted</artifactId>
30+
<version>2.017</version>
2631
</dependency>
2732
<dependency>
2833
<groupId>org.clojure</groupId>
29-
<artifactId>core.cache</artifactId>
30-
<version>1.0.225</version>
34+
<artifactId>data.fressian</artifactId>
35+
<version>1.1.0</version>
3136
</dependency>
3237
<dependency>
33-
<groupId>org.clj-commons</groupId>
34-
<artifactId>digest</artifactId>
35-
<version>1.4.100</version>
38+
<groupId>prismatic</groupId>
39+
<artifactId>schema</artifactId>
40+
<version>1.4.1</version>
3641
</dependency>
3742
<dependency>
3843
<groupId>com.github.k13labs</groupId>
3944
<artifactId>futurama</artifactId>
40-
<version>1.0.2</version>
45+
<version>1.0.3</version>
4146
</dependency>
4247
<dependency>
43-
<groupId>com.cnuernber</groupId>
44-
<artifactId>ham-fisted</artifactId>
45-
<version>2.016</version>
46-
</dependency>
47-
<dependency>
48-
<groupId>prismatic</groupId>
49-
<artifactId>schema</artifactId>
50-
<version>1.4.1</version>
48+
<groupId>org.clj-commons</groupId>
49+
<artifactId>digest</artifactId>
50+
<version>1.4.100</version>
5151
</dependency>
5252
<dependency>
5353
<groupId>org.clojure</groupId>
54-
<artifactId>data.fressian</artifactId>
55-
<version>1.0.0</version>
54+
<artifactId>core.cache</artifactId>
55+
<version>1.1.234</version>
5656
</dependency>
5757
</dependencies>
5858
<build>

0 commit comments

Comments
 (0)