| >Can you think of any other languages? Yes. E.g. every language where you can pass pointers can do this. Reference are a construct around pointers. >Of the ones I listed, I use all of, and am continuously frustrated by this limitation. Why? This is only a limitation for a few basic types. All the language you mention allow you to modify objects passed to a function. If it ever were any issue though you can always return the modified object and overwrite the original. a = modify(a) works even if you can only pass a value. In practice this should never be a limitation, certainly I have never encountered it as one. |
Hint: Python and Javascript will use the type passed to determine mutability. Kotlin will let you pass a mutableStateFlow etc that can be used for, e.g., top-level data structure, but not an arbitrary variable. (e.g. a data structure field, or free variable).
The most popular languages, outside of C and C++, cannot pass pointers. And, raw pointers are not ideal; they lose type safety, memory safety etc.
There are always canonical patterns for a given language to write a function like I did. I find them to be universally more complicated and less explicit/versatile than what I posted; they require code to permeate beyond the function signature.