This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-25
Channels
- # babashka (65)
- # beginners (34)
- # biff (18)
- # calva (8)
- # clara (22)
- # clj-kondo (32)
- # clojure (24)
- # clojure-bay-area (4)
- # clojure-europe (135)
- # clojure-nl (3)
- # clojure-norway (9)
- # clojure-uk (1)
- # clojurescript (11)
- # clojutre (1)
- # core-async (8)
- # cursive (3)
- # datomic (31)
- # emacs (5)
- # fulcro (6)
- # graalvm (5)
- # graphql (3)
- # honeysql (1)
- # introduce-yourself (9)
- # kaocha (1)
- # lsp (65)
- # meander (5)
- # nbb (7)
- # nrepl (2)
- # off-topic (44)
- # rum (3)
- # shadow-cljs (23)
- # specter (1)
- # tools-deps (6)
- # vim (3)
- # xtdb (30)
Can anybody recommend a leveldb-library? There's at least three of them: 1. https://github.com/Factual/clj-leveldb 2. https://github.com/fern-flower-lab/leveldb-clj 3. https://github.com/alekcz/konserve-leveldb
Is there a workaround for making fn* class names shorter? I'm getting exceptions around class names being too long from relatively small code size just because the macros it's working with expand to quite a few nested function literals.
Others can answer more authoritatively, but I know there is a JIRA issue asking about this. I believe the original motivation was for macro-heavy libraries like core.logic
I suspect the only workarounds are to use a file system that supports arbitrarily long file names, or to modify the Clojure compiler in how it constructs class names.
Some of the comments in that http://ask.clojure.org discussion might include other workarounds.
I don't think there is any easy workaround. ultimately, this is going to need to be an alternative naming strategy in the compiler
Thanks, that's good to know
Unfortunately I'm in the same boat with a couple features of farolero, most notably the debugger assertions.
I'd recommend voting on the http://ask.clojure.org issue, and adding a comment about other Clojure library names that lead to a similar issue, for others searching for the issue in future.
I have a function that relies on java.lang.Runtime, and I want to extract that to make the function pure. I've type hinted the arg, but now I'm unsure of how to pass in a fake object that works the same. Any ideas or should I not worry about it?
(defn mem-stats
"Returns a map of current total, free, and used memory in megabytes."
[^java.lang.Runtime rt]
(let [fm (.freeMemory rt)
tm (.totalMemory rt)]
{:total (->MB tm) :free (->MB fm) :used (->MB (- tm fm))}))
But also, in other more complicated situations, how do you create a proxy for a concrete class? I can't seem to get proxy
to work correctly in this instance
You could use definterface
(definterface MyInter
(freeMemory []))
(.freeMemory
(proxy [MyInter] []
(freeMemory [] 123)))
=> 123
(defprotocol RuntimeStats
(free-memory [_])
(total-memory [_]))
(extend-protocol RuntimeStats
java.lang.Runtime
(free-memory [rt] (.freeMemory rt))
(total-memory [rt] (.totalMemory rt)))
(let [real (java.lang.Runtime/getRuntime)
oom (reify RuntimeStats
(free-memory [_] 0)
(total-memory [_] (total-memory real)))]
{:real {:free (free-memory real)
:total (total-memory real)}
:oom {:free (free-memory oom)
:total (total-memory oom)}})
The idea is donโt fake a java.lang.Runtime
, just make that know how to satisfy your needs
Both of these are great, thank you
perhaps worth noting, if java.lang.Runtime was implemented today probably it would implement an interface - it's sort of a modern-day OOP best practice
which Clojure already nudges us to :) by making inheritance difficult (if you wanted to squeeze performance you could subclass Runtime... I'd do it with a plain .java file)
heh This doesn't need any sort of performance tuning, the function is only used in a single spot. Just decided to use it as an opportunity to learn.
yeah I could imagine one wouldn't be invoking this code 1000 times / second ๐ I was simply nerd-sniped into it
Is there a variant of time
that does not return the value of expr?