forked from oracle-samples/clara-rules
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: test building graalvm app using clara rules (#8)
- Loading branch information
Showing
5 changed files
with
116 additions
and
23 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[plugins] | ||
clojure = "https://github.com/asdf-community/asdf-clojure.git" | ||
[tools] | ||
java = "graalvm-22.3.1+java11" | ||
clojure = "1.11" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(ns clara.main | ||
(:require | ||
[clara.rules :refer [defrule | ||
insert! | ||
insert | ||
defquery | ||
defhierarchy | ||
defsession | ||
query | ||
fire-rules-async] :as r] | ||
[futurama.core :refer [!<! !<!! async]]) | ||
(:gen-class) | ||
(:import | ||
[java.util.concurrent CompletableFuture])) | ||
|
||
(defrule simple-transform-rule | ||
"simple rule that transforms an input into a result" | ||
[:my/input [{:keys [value]}] | ||
(= value ?value)] | ||
=> | ||
(insert! {:fact/type :my/result | ||
:result ?value})) | ||
|
||
(defquery simple-output-query | ||
"simple query that returns an output fact" | ||
[] | ||
[?output <- :my/output]) | ||
|
||
(defhierarchy simple-hierarchy | ||
"simple hierarchy of facts" | ||
:my/thing :my/input | ||
:my/result :my/output | ||
:my/input :my/fact | ||
:my/output :my/fact) | ||
|
||
(defsession my-session | ||
'clara.main | ||
:fact-type-fn :fact/type) | ||
|
||
(defn -main | ||
"this is a test to compile a bunch of async code into native code, pretty nasty" | ||
[& args] | ||
(println | ||
"async result:" | ||
(!<!! | ||
(async | ||
(let [session (!<! (-> my-session | ||
(insert {:fact/type :my/thing | ||
:value args}) | ||
(fire-rules-async)))] | ||
(query session simple-output-query)))))) |
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