This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-01
Channels
- # aws (1)
- # beginners (237)
- # boot (2)
- # calva (6)
- # cider (16)
- # clara (10)
- # clj-kondo (1)
- # cljs-dev (24)
- # clojure (29)
- # clojure-brasil (2)
- # clojure-dev (20)
- # clojure-europe (1)
- # clojure-italy (56)
- # clojure-japan (1)
- # clojure-nl (16)
- # clojure-spec (12)
- # clojure-uk (12)
- # clojurescript (24)
- # clojureverse-ops (3)
- # core-async (3)
- # cursive (21)
- # datascript (5)
- # datomic (82)
- # devops (5)
- # duct (14)
- # emacs (2)
- # fulcro (2)
- # jobs (6)
- # juxt (7)
- # kaocha (6)
- # leiningen (19)
- # luminus (3)
- # nrepl (51)
- # off-topic (208)
- # other-languages (1)
- # re-frame (8)
- # reagent (9)
- # remote-jobs (6)
- # shadow-cljs (37)
- # spacemacs (6)
- # testing (12)
- # tools-deps (25)
Hi guys I hope you like to give minor style suggestions. What is clojure idiomatic to denote a slightly updated value? In Haskell, you usually use apostroph eg
let foo = [1, 2, 3]
foo' = 0 : foo
but in clojure '
is used to quote forms. What is a more idiomatic name for updated-foo
here?
(let [foo '(1 2 3)
updated-foo (conj foo 0)]
updated-foo)
first that comes to mind is \ (as in let - let\) but people use that for macro-wrapped functions so might be confusing
You mean let*
? Yes I've seen it some places but people do indeed find it confusing, also as *foo*
is the convention for dynamic variables
for cases like this i think it is common/idiomatic to use shadowing -- just reuse foo instead of foo'
I've seen both, it's a thing various house styles disagree about in my experience
If I have a React element that sets up a go
block, with a loop
that listens on a channel, in my will-mount
life cycle method; when that component is unmounted... does the go block still live in memory listening on that channel?
the go block compiles to a field on the channel itself, if the channel goes out of scope the go block is freed too
if you hold onto the channel, whatever go block is parking on it is probably kept around
it sounds weird but it works out, if the channel is not visible in any live code, the go block can never wake up again, so it makes sense that it can be freed
you can let the go block fall through, or let it park on something that will go out of scope...
exiting from the end of the block without parking or looping
there's idioms for this - eg. close the channel and write the go block such that if it gets a nil (channel closed) it exits
but there's no clean way to force the block to exit if it wasn't written to do so
Is it possible to open up the channel again? Or do I have to make another call to chan?
channels can only be closed once
if you want to keep the channel, but tell a consumer to close, you could check for a special token like ::close
Thanks @noisesmith :thumbsup: