This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-25
Channels
- # asami (5)
- # babashka (38)
- # beginners (116)
- # calva (65)
- # chlorine-clover (4)
- # cider (8)
- # cljfx (6)
- # cljsrn (7)
- # clojure (18)
- # clojure-australia (1)
- # clojure-europe (49)
- # clojure-spec (6)
- # clojure-uk (4)
- # clojurescript (3)
- # clojureverse-ops (13)
- # core-async (2)
- # cryogen (1)
- # cursive (9)
- # datahike (32)
- # fulcro (3)
- # gratitude (17)
- # malli (4)
- # music (3)
- # nrepl (8)
- # off-topic (14)
- # releases (2)
- # rewrite-clj (3)
- # shadow-cljs (4)
- # vrac (1)
- # xtdb (4)
Can I check if a symbol resolves to a class without possibly running its class initializer?
library question: Is there a different idiom for this kind of code:
(let [result (computation)]
(finalizer)
result)
so that I can write something like
(finalizing
(computation)
(finalizer))
You can implement this on your own, with using with-open
as an inspiration. Although its finalizer is hard-coded.
thanks p-himik, I was mostly asking if there's an idiom for this already in the standard library. If not, for my usecase I can probably just use the let, since it happens only once
I'm 80% sure there's nothing like that. It would require a macro, and none of the macros in clojure/core.clj
do that.
It's also more often used in the "create an object, mutate it, and return it" context, which might be confusing here.
Try/Finally is the way to go.
(try (computation)
(finally (finalizer)))
It'll run the finally clause even if the code inside the try throws an exception, so cleanup is guaranteed to happen.@meditans
does ->
do what you want?
https://clojuredocs.org/clojure.core/-%3E
It would pass result
to (finalizer)
and replace the value of the whole form with the value returned from (finalizer).
Huh, Slack randomly decided to reshuffle a few characters in my message after I have already typed them. Distributed stuff is fun.
just say no to mutation 🙈
Sometimes it is a necessary evil, for a truly immutable program is also a truly useless one. :)
"but it's puure!!1" lol
Yeah, that's true, side-effects are what we want...
Mutation