6 ms·
there's no reason you couldn't do a clojure in rust but the main implementation benefits from GC and making it easy to call host (java) methods. as far as i kn
by harrison_clarke 2y ago
there's no reason you couldn't do a clojure in rust
but the main implementation benefits from GC and making it easy to call host (java) methods. as far as i know, the core clojure data structures are kinda hard if you don't have a GC
- packetlost 2y agoLisps almost universally require or expect GC.
- pjmlp 2y agoYes, although the Common Lisp derived ones, and the old ones from Xerox, Symbolics, TI and co, also have other capabilities available, especially for the low level programming part, and all common data structures, not only lists.
- TransAtlToonz 2y agoThe only mature, production-used exception of which I can think is Naughty Dog's Game Oriented Object Lisp/Game Oriented Assembly Lisp. EDIT: I was wrong, wikipedia claims there are basic GC functions. I can't speak to the details, but I imagine that whatever they have would attempt to lift allocations out of the hot path/use arena allocation or some similar mechanism. That said, people have strong opinions on whether reference counting counts as GC. I say it does, but others are vehement that it does not. If it does not count as GC, I think Interlisp-D would qualify.
- JonChesterfield 2y agoThe hashed trie structure is definitely more annoying to write without a general garbage collector. Reference counting it works though, and comes with the magic trick that a reference count of one means you're the only reference to it, i.e. only one thread can see it, thus mutation is safe. Encoding that in the lifetime rules of rust might be a nuisance. Works very well in C.
- kibwen 2y agoRust has provisions for safely existing outside of the lifetime rules, which exist largely to accommodate refcounting schemes. You'd likely be using an Arc<RwLock<T>> here. Otherwise you can implement something on your own and express whatever C-style shenanigans you have in mind via the primitives in std::cell or std::sync.
- harrison_clarke 2y agoyou could do it in rust with Arc<T>.get_mut if you're implementing the clojure data structures, you wouldn't use a cell inside. semantically, they're immutable, and the operations on them all return copies that share nodes with the old one. if you know the old one won't be used, you can cheat and mutate it instead the issue with using Arc for these data structures is that it's a fatter pointer (costs memory, causes cache pressure), and it requires atomics/fences. they also generate a ton of garbage in typical use-cases (unless you can do the mutation optimization). languages with a compacting GC also usually get a faster allocator it's basically ideal conditions for a GC to outperform reference counting
- kibwen 2y agoI don't doubt that a good GC can generally outperform a simple refcounting scheme, but when it comes to the aforementioned count-of-one optimization, Rust already gives you that out of the box by dint of the fact that owned values are moved by default and bumping the refcount is an explicit operation, which means that in any given scope you can simply pass the handle on if you're done with it and subsequent functions can access it without needing to touch the counter at all.
- harrison_clarke 2y agorust is definitely better than other languages for refcounting, since you don't pay for it on reads