Is this totally right? ref is parametric but not necessarily itself mutable, but can be mutable or immutable depending on what it infers no? Your example is helpful though in understanding this.
Iāve been playing with mojo for a few months now, and ref is still super intimidating. Everytime I see ref used, I subconsciously read it as why are they specifying ref on an entity that is already a reference?.
Bear with me as I try to walk through this, see if I understand correctly:
The reason element is mutable here is not because ref is mutable, but because ref infers the mutability of some_list which is mutable.
for ref element in some_list:
print(element) # mutable
Its just a little confusing to understand because by default in for loops element is immutable, so why doesnāt ref just infer the element mutability and keep the immutability property. I understand that ref infers the mutability of some_list, but it doesnāt read (pun[1]) that way to me. Additionally, reading the docs, ref also acts as either indicating a return value should be a reference with some im/mutability, or replaces a preexisting reference specifier like read / mut / owned.
Am I understanding this correctly?
Iām in favor of including read/mut as part of the bindings, at least so beginners are thrown for less of a loop (pun[2]?). Tossing mut before element involves less context / brain cells I guess.
Maybe my issue is that ref and its relationship to how read / mut / owned are used feels inconsistent. Like, ref in some parts of mojo is simply a generic / customizable version of read / mut / owned, but then other places like returns, loops, with, auto-deref, itās its own concept / entity.
I think the goal of ref is its a parametric version of read / mut / (owned?)? But right now we cant use read / mut beyond function args, so ref feels like it does/is something completely different.