clojure-europe

For people in Europe... or elsewhere... UGT https://indieweb.org/Universal_Greeting_Time
mpenet 2020-09-19T00:54:32.036400Z

persistent! should be called on the return value of assoc! not on t.

raymcdermott 2020-09-19T15:18:55.038100Z

I find all the transient / persistent stuff makes the code feel a lot more complex cos it's adding quite a bit of cognitive load

raymcdermott 2020-09-19T15:22:40.039Z

@ordnungswidrig who is obviously a Clojure wiz took 2 tries and @mpenet has issued a correction

orestis 2020-09-19T15:53:31.040500Z

Transients can be quite faster, but the api is exactly the same as the normal data structures - you have to use the return value of assoc!, you don’t mutate in place.

pez 2020-09-19T16:07:33.042300Z

Good morning! I know I'm lazy, but it seems to be the right place to ask what transients are about and why they can be quite faster. I won't take offence if you tell me to google it or just give me a link. πŸ˜ƒ

ordnungswidrig 2020-09-19T16:10:44.044200Z

@orestis the documentation suggests otherwise :thinking_face:

orestis 2020-09-19T16:10:46.044300Z

Transients are mutable versions of collections. They are used when you do a lot of mutation within a single function, but you are not supposed to share them outside.

orestis 2020-09-19T16:12:11.045300Z

> Transients support a parallel set of 'changing' operations, with similar names followed by ! - assoc!, conj! etc. These do the same things as their persistent counterparts except the return values are themselves transient. Note in particular that transients are not designed to be bashed in-place. You must capture and use the return value in the next call. In this way, they support the same code structure as the functional persistent code they replace. As the example will show, this will allow you to easily enhance the performance of a piece of code without structural change.

orestis 2020-09-19T16:12:35.046400Z

The guide is very nicely written: https://clojure.org/reference/transients

πŸ‘ 1
ordnungswidrig 2020-09-19T16:12:47.046800Z

@orestis ok, I stand corrected. The documentation uses a loop which I interpreted wrongly. You were correct, use the return value. (I wonder what happens if you don't)

pez 2020-09-19T16:22:03.049100Z

Thanks @orestis! Much appreciated. So sometimes when I reach for Java data structures for performance reasons I could also consider transients and keep the code looking someone similar to what it would look like using the immutable structures, is that a somewhat correct take on them?

orestis 2020-09-19T16:48:43.051700Z

@pez exactly correct but you have to be careful to not use transients anywhere with threads or anywhere with the assumption of using a persistent data structure. You would usually call transient! at the top of a function and persistent! at the exit.

πŸ‘ 2
mpenet 2020-09-19T17:24:17.056300Z

Most uses of transients I see in the wild are wrong... Either bashing in place or poor substitutes for a simple into call (which will use transients under the hood). There are valid uses cases but most often there's a higher level construct just as good.

πŸ‘ 3
borkdude 2020-09-19T20:04:08.057400Z

> I find all the transient / persistent stuff makes the code feel a lot more complex cos it's adding quite a bit of cognitive load Go figure what would happen if you would write programs directly in Java...

πŸ˜‚ 1
ordnungswidrig 2020-09-19T20:04:54.057700Z

lol

raymcdermott 2020-09-19T21:21:27.058600Z

Goodnight

2020-09-19T21:29:53.059100Z

Terrifying corn 🌽

raymcdermott 2020-09-19T22:01:37.059600Z

Corn is transient

raymcdermott 2020-09-19T22:02:17.060300Z

Trying to stay on topic ;-)