6 ms·
> deduplication, which other languages already give you with strings. Aren't Ruby's strings mutable? I'm not sure, but I seem to recall they were/are, in which
by klibertp 5y ago
> deduplication, which other languages already give you with strings.
Aren't Ruby's strings mutable? I'm not sure, but I seem to recall they were/are, in which case you can't really intern them. Python and Java have immutable strings, with the ability to optimize allocations being (probably?) one of the reasons.
On the other hand, Symbols in Ruby seem to be immutable, which allows for their interning.
- noneeeed 5y agoIt's optional. By default strings are mutable, but you can freeze them individually, and you can set a directive that makes all string literals as immutable on a file-by-file basis.
- TazeTSchnitzel 5y agoYou can intern strings without preventing mutability using the copy-on-write principle. PHP does it.
- recursive 5y agoIf you copy before you write, you're not mutating, you're making a new thing. e.g. This pseudo code must stand for mutation to be present. a = ... b = a mutate(a) /* b now mirrors a */
- TazeTSchnitzel 5y agoA language runtime can make that work if it wants to. High-level semantics don't need to constrain the implementation.
- deleted 5y ago[deleted]