Fork me on GitHub
#clojure-dev
<
2020-05-10
>
vlaaad05:05:41

You can achieve same performance with multiple arities of vswap! function

vlaaad05:05:39

(vswap! (volatile! (prn 1)) identity)

vlaaad05:05:57

Prints "1" twice

serioga09:05:54

@vlaaad As I see vswap! is implemented as macro just to assign the type hint to volatile and avoid reflection on .reset and .deref invocations

vlaaad09:05:09

You can doo all that without making vswap! a macro

serioga10:05:04

> Prints "1" twice looks like it is not designed to work with volatiles which you cannot access directly 🙂

vlaaad10:05:22

the discussion in the comments seems to be derailed because of :inline in the patch...

ghadi12:05:31

@vlaaad what is the problem you are experiencing?

vlaaad15:05:54

Actually, I thought I have a problem, but I'm not. I had a volatile in a map, and wanted to update value inside the volatile like that (update my-map :volatile vswap! my-other-fn), but that was a mistake since vswap! returns a value, not a volatile

hiredman15:05:10

Just use an atom, you get a function for swap and as a bonus it is race free under contention, volatile is not

vlaaad16:05:22

I know when to choose atoms and when to choose volatiles :)

vlaaad15:05:54

Actually, I thought I have a problem, but I'm not. I had a volatile in a map, and wanted to update value inside the volatile like that (update my-map :volatile vswap! my-other-fn), but that was a mistake since vswap! returns a value, not a volatile