8 karma · joined Aug 1, 2024 (2y ago) · 10 submissions
comment 1y ago · link · parent
Rust APIs are largely built around references. If you were to put a Vec<T> (dynamic array) into a pointerless Gc<T>, you would be almost entirely unable to access its contents. The only way to access it would be swap it with an empty Vec, access it, then swap it back a-la Cell. You wouldn't even be able to clone the Vec without storing a dummy version in its place during the call.
https://doc.rust-lang.org/stable/std/cell/struct.Cell.html#m...
comment 1y ago · link · parent
I guess you've not written much python, or just not used any custom types in lists if you have.
class Thing:
def __init__(self, a, b):
self.a = a; self.b = b
def __eq__(me, them):
return me.a == them.a and me.b == them.b
>>>[1, 2, Thing(6, "Hi")] == [1, 2, Thing(6, "Hi")]
True
>>>[1, 2, Thing(6, "Hi")] == [1, 2, Thing(6, "Hello")]
False
In this case, the builtins are syntax, namely the `==` operator. There's a uniform syntax for comparing two objects for equality.comment 1y ago · link · parent
Here the compiler "register allocates" i for some reads but not for others.
i gets stack allocated, but some uses of it act as though they were register allocated.
comment 1y ago · link · parent
import Control.Lens
baseLens --> nextIndex = baseLens . ix nextIndex
assocIn structure keyLens newValue = set keyLens newValue structure
It works like so: setTo256 structure = assocIn structure (ix 0 --> 0 --> 0) 256
-- setTo256 [[[1]], [[2]]] returns [[[256]], [[2]]]comment 2y ago · link · parent