3 ms·
> This is something that you cannot do both a) this safely and b) this efficiently in any other language. This is wrong. Pretty sure you could do this in ATS f
by haskellandchill 6y ago
> This is something that you cannot do both a) this safely and b) this efficiently in any other language.
This is wrong. Pretty sure you could do this in ATS for example.
- brundolf 6y agoI may have overstated that. What I really meant was "any other language that I'm passingly familiar with", which includes the majority of mainstream languages.
- jrpelkonen 6y agoSubstrings in older versions of Java used to reuse the character array of the original string instead making a copy. The flip side is that the original string must be retained in memory until all the substrings have “become garbage”. So there is a trade-off.
- ameliaquining 6y agoThe Rust version has that same tradeoff; the string can't be deallocated until all the tokens' lifetimes have ended. (In this particular use case, that's not really a cost, since you probably need to keep the string available the whole time anyway.) Go, which is garbage-collected, also does the slice-by-reference trick (but fails criterion #1 because it doesn't really have iterators).
- brundolf 6y agoYeah. But there's also a bigger tradeoff which is having garbage collection in the first place. Rust lets you depend on immutability without having garbage collection to clean up the values for you, which is a really special thing.