Fork me on GitHub
#clojure
<
2019-05-01
>
dpsutton02:05:08

@hiredman that is a really cool program

devn03:05:14

@hiredman should be knighted, IMHO.

lsund07:05:49

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)

valerauko07:05:37

first that comes to mind is \ (as in let - let\) but people use that for macro-wrapped functions so might be confusing

lsund07:05:54

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

valerauko07:05:20

you can use ' i guess?

(let [foo 12
      foo' (+ foo 1)]
  foo')
=> 13

👍 4
jumpnbrownweasel16:05:27

for cases like this i think it is common/idiomatic to use shadowing -- just reuse foo instead of foo'

noisesmith17:05:07

I've seen both, it's a thing various house styles disagree about in my experience

lsund07:05:11

Thats true

noisesmith17:05:27

suffixing with ' is idiomatic

👌 8
Mario C.18:05:41

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?

Mario C.18:05:26

It seems that, that is the case... But I am not so sure..

noisesmith18:05:39

the go block compiles to a field on the channel itself, if the channel goes out of scope the go block is freed too

noisesmith18:05:10

if you hold onto the channel, whatever go block is parking on it is probably kept around

noisesmith18:05:59

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

Mario C.18:05:29

The channel never goes out of scope

Mario C.18:05:38

so that explains it

noisesmith18:05:05

you can let the go block fall through, or let it park on something that will go out of scope...

Mario C.18:05:28

what do you mean by letting it fall through?

noisesmith18:05:07

exiting from the end of the block without parking or looping

Mario C.18:05:43

Is there way I can have it stop listening or drop the block ?

noisesmith18:05:36

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

noisesmith18:05:57

but there's no clean way to force the block to exit if it wasn't written to do so

Mario C.18:05:44

Is it possible to open up the channel again? Or do I have to make another call to chan?

noisesmith18:05:37

channels can only be closed once

noisesmith18:05:06

if you want to keep the channel, but tell a consumer to close, you could check for a special token like ::close

Mario C.18:05:44

that sounds like its exactly what I need

Mario C.18:05:57

Thanks @noisesmith :thumbsup:

lilactown23:05:19

anyone know what dep to include if I want to use clojure.jdbc with mysql?