Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ jobs:
with:
cli: '1.12.4.1582'

- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Install ClojureCLR
run: |
dotnet tool install --global Clojure.Main --version 1.12.2
dotnet tool install --global Clojure.Cljr --version 0.1.0-alpha11
echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"

- uses: actions/cache@v5.0.2
with:
path: ~/.m2
Expand Down
10 changes: 9 additions & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@
[:url "https://opensource.org/license/epl-1-0/"]]]]}]
(merge defaults opts)))

(defn clr-test
"Run the test suite on ClojureCLR via cljr."
[opts]
(let [{:keys [exit]} (b/process {:command-args ["cljr" "-X:test"]})]
(when-not (zero? exit) (System/exit exit))
opts))

(defn tests
[opts]
(-> opts
(cb/run-task [:dev :test])
(cb/run-task [:dev :cljs-test])))
(cb/run-task [:dev :cljs-test])
(clr-test)))

(defn copy-clj-kondo-config
"copy clj-kondo definition to local dev env"
Expand Down
7 changes: 7 additions & 0 deletions deps-clr.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{:paths ["src"]
:aliases
{:test {:extra-paths ["test"]
:extra-deps {io.github.dmiller/test-runner {:git/tag "v0.5.3clr"
:git/sha "ae91dd2727bbf70eb3a6d869a19953de3819dfbc"}}
:exec-fn cognitect.test-runner.api/test
:exec-args {:dirs ["test"]}}}}
37 changes: 24 additions & 13 deletions src/robertluo/fun_map.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
(:require
[robertluo.fun-map.core :as core]
[robertluo.fun-map.wrapper :as wrapper]
#?(:clj
#?(:cljs nil
:default
[robertluo.fun-map.helper :as helper])))

(defn fun-map
Expand Down Expand Up @@ -44,8 +45,7 @@
(core/fun-map? m))

(comment
(fun-map {:a 1 :b 5 :c (wrapper/fun-wrapper (fn [m _] (let [a (get m :a) b (get m :b)] (+ a b))))})
)
(fun-map {:a 1 :b 5 :c (wrapper/fun-wrapper (fn [m _] (let [a (get m :a) b (get m :b)] (+ a b))))}))

(defmacro fw
"Returns a FunctionWrapper of an anonymous function defined by body.
Expand Down Expand Up @@ -85,12 +85,14 @@
[arg-map & body]
(helper/make-fw-wrapper `wrapper/fun-wrapper [:trace :cache] arg-map body))

#?(:clj
#?(:cljs nil
:default
(defmethod helper/fw-impl :trace
[{:keys [f options]}]
`(wrapper/trace-wrapper ~f ~(:trace options))))

#?(:clj
#?(:cljs nil
:default
(defmethod helper/fw-impl :cache
[{:keys [f options arg-map]}]
(let [focus (when-let [focus (:focus options)]
Expand All @@ -115,11 +117,10 @@
(let [focus (mapv (comp symbol name) args)]
`(fw {:keys ~args
:focus ~focus}
~@body)))
~@body)))

(comment
(macroexpand-1 '(fnk [a :ns/b] (+ a b)))
)
(macroexpand-1 '(fnk [a :ns/b] (+ a b))))

;;;;;; life cycle map

Expand All @@ -139,6 +140,11 @@
java.io.Closeable
(halt! [this]
(.close this)))
:cljr
(extend-protocol Haltable
System.IDisposable
(halt! [this]
(.Dispose this)))
:cljs
(extend-protocol Haltable
core/DelegatedMap
Expand Down Expand Up @@ -168,16 +174,20 @@
;;;;;;;;;;; Utilities

(deftype CloseableValue [value close-fn]
#?(:clj clojure.lang.IDeref :cljs IDeref)
#?(:clj (deref [_] value)
:cljs (-deref [_] value))
#?(:cljs IDeref :default clojure.lang.IDeref)
#?(:cljs (-deref [_] value)
:default (deref [_] value))
Haltable
(halt! [_]
(close-fn))
#?@(:clj
[java.io.Closeable
(close [this]
(halt! this))]))
(halt! this))]
:cljr
[System.IDisposable
(Dispose [this]
(halt! this))]))

(defn closeable
"Returns a wrapped plain value which implements IDeref, Haltable, and (in CLJ)
Expand All @@ -193,7 +203,8 @@
[r close-fn]
(->CloseableValue r close-fn))

#?(:clj
#?(:cljs nil
:default
(defn lookup
"Returns a ILookup object for calling f on k"
[f]
Expand Down
Loading
Loading