Hacker News new | past | comments | ask | show | jobs | submit login

That's also the impression I have, the article really has nothing to do with Rust's interior mutability. And Rust wouldn't have the issue in the first place because whether it takes the parameter by reference, mutable reference or value would clearly explain the "contract" to the caller.

It does feel a bit closer to Clojure's transients which I guess it's what it's referring to.

However there are also a number of differences with Clojure:

* Clojure can not completely prevents the caller modifying callee data (at least using "normal" clojure collections, which are persistent)

* creating and reifying transients is O(1)

* the operation is a fairly trivial mapping of #(/ (- % low) (- high low)), which is likely what you'd have done in Clojure




This definitely made me think of Clojure transients. For reference: https://clojure.org/reference/transients

> If a pure function mutates some local data in order to produce an immutable return value, is that ok?

The idea in Clojure is that data is immutable by default but there are function-local mutation APIs specifically for optimization. The contract between caller and callee is still the same, a function never mutates your data, but transients provide improved performance and memory characteristics invisible to the caller.


What is callee data that a caller can access while the callee exists? Is this multithreeaded code?


I don't know if it was autocorrect screwing up or brainfart / fucky fingers (likely the latter I fear), but what I meant to write that clojure can completely prevent the callee from modifying caller data, since it uses persistent collections and persistent collections are naturally immutable.

Sadly by the time I realised the screwup I couldn't edit the comment anymore (one of the really annoying things about HN alongside stripping random characters from comments and the half-assed markup).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: