This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-27
Channels
- # announcements (1)
- # aws (8)
- # babashka (77)
- # babashka-sci-dev (8)
- # beginners (29)
- # biff (2)
- # calva (13)
- # cljs-dev (1)
- # clojure (42)
- # clojure-europe (205)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (4)
- # clojurescript (58)
- # conjure (9)
- # data-science (7)
- # datalevin (19)
- # datomic (3)
- # emacs (7)
- # fulcro (15)
- # gratitude (8)
- # lsp (52)
- # meander (3)
- # membrane (92)
- # off-topic (12)
- # re-frame (16)
- # reagent (4)
- # reitit (15)
- # releases (1)
- # sci (30)
- # shadow-cljs (34)
- # tools-deps (5)
- # xtdb (17)
Any stats on clojure usage? How many downloads per month in last 5 years? What is the rate of new people joining slack channel? Looks like universities overselling python to students
The annual State of Clojure survey has a lot of interesting stats https://clojure.org/news/2022/06/02/state-of-clojure-2022
I need to pickle a large map so that I can load it at a later time, kind of like setting an initial condition. Human readable is nice, but not strictly necessary. Seems to me that I could do this:
(do
(spit "my_file.clj" "(ns my-initial-condition)")
(spit "my_file.clj" "(def initial-condition")
(spit "my_file.clj" (str my-map) ;; <--- this is the important line
(spit "my_file.clj" ")"))
Is there any reason why this would be a bad idea?clojure.edn
is the preferred way of storing map data for small files, and storing ns
forms and def
s in a file to mark state seems like it could go wrong in lots of strange ways.
What are you trying to accomplish with this?
I want to save program state periodically, and then give the user the option to load that state when starting
Who are the "users" in this scenario?
What program state needs to be saved? Loading ns
forms and simple def
s is usually fast and doesn't need to be persisted like this. Is there an expensive computation that you need to cache?
expensive computation - yes
I run digital filters on time series data. Startup will take > 15 min with no state loading. I want to reduce startup to a few seconds.
For expensive computation, you can do something like:
(defonce my-result
(if (.exists ( "my-result.edn"))
(clojure.edn/read (io/reader "my-result.edn"))
(let [res (my-expensive-computation)]
(spit "my-result.edn" (pr-str res))
res))
That will make sure your expensive computation only happens once and take advantage of the persisted file if it's available.
Oh cool!
That's awesome
One thing to note with defonce
-it really only does run once per session, which means that if the inputs to my-expensive-computation
have changed, or my-expensive-computation
has different implementation details (e.g. your filter parameters have changed), attempting to redefine the my-result
var will not recompute your results. So you'll need to make those checks yourself.
You can always get around that by binding a new var, of course - just one thing to watch out for when using this approach.
Yeah, I read up on defonce
This is a slick solution
@UFTRLDZEW do I need to import something to get io/reader? When I try just plain io, I get:
No such namespace: io
When I try http://clojure.java.io, I get:
class java.io.BufferedReader cannot be cast to class java.io.PushbackReader
My bad, I wrote that answer without docs handy and forgot about the type conversion issue here: https://clojuredocs.org/clojure.edn/read
Is there a way to coax tools.cli
into requiring the presence of some arg, when parsing, and not just ensuring that a value is provided if the flag is?
Edit, just found: https://clojure.atlassian.net/browse/TCLI-12
Ugh! Looks like I forgot to update the docs/docstrings in several places when I added that. Sorry. It's listed here https://github.com/clojure/tools.cli/blob/master/src/main/clojure/clojure/tools/cli.cljc#L291-L312 but that's a private function which doesn't appear in the API docs so that's not very helpful.
tools.cli
really does need some documentation love. I'll try to find some time to work on it "soon" (but, unfortunately, I've stopped using it in all my projects so it's become a lower priority).
I can fork and update the README.md at least. Should I add something to the existing example (with port number, etc.) or just do a new section?
BTW I got my use case to work with :missing
perfectly
Contrib libraries do not accept PRs so forking and updating isn't going to get accepted back. I need to write some proper documentation for that library -- it's long overdue!
Ah, gotcha, thanks!
I've updated the README and docstrings for this. I'll be making a minor new release this weekend I expect.