3 ms·
The notation of head ← n for "n is stored in head" was mainly responsible for my confusion in reading CLRS for the first time. Even now, it really breaks the fl
by quadrifoliate 4y ago
The notation of head ← n for "n is stored in head" was mainly responsible for my confusion in reading CLRS for the first time. Even now, it really breaks the flow of reading this pseudocode for me, and I'm not quite sure why.
Has anyone else struggled with this, and have suggestions on how to rewire my brain so the notation "flows" better?
- pasquinelli 4y agoit's just a different symbol from the usual assignment operator, that is to say "put the value you're referring to as `n` in the variable `head`", just like `head = n` in most languages with assignment. the only reason for the arrow is if you're using `=` for true equality, as in `head` is always the same as the value `n`, or if you wanted to use `=` to mean `equals?`, a boolean test for momentary equality. i don't know if any of that helps, it all just comes down to recognizing the symbol and interpreting it correctly.
- deredede 4y agoI have no tips, but I share the pain. My intuitive reaction when seeing an arrow is that it changes the text direction, and I do not give semantic meaning to the arrow direction. Iow, my brain essentially treats `a <- b` and `b -> a` identically. This is the usual way that directional operators work in maths: comparisons, set membership and inclusion, implication (to be fair the symmetric version is rare enough), etc.
- derekbaker783 4y agoThere are programming languages where that syntax is used for assignments to mutable vars (F# being one example). Maybe play around with a language that uses that syntax? https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/values/#mutable-variables https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
- quadrifoliate 4y agoThis is an excellent suggestion! I was going to say that the only place I have seen arrows used are either struct membership in C or the fat arrow function in JS, and neither of those go from right to left. So playing around with F# might help.