News for hackers. Stuff that matters.
Re:Why Ruby Has Symbols by klibertp on Thursday April 14, 2022 @07:08AM (#31025315)
> 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.

Re:Why Ruby Has Symbols by noneeeed on Thursday April 14, 2022 @07:22AM (#31025406)
It'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.
Re:Why Ruby Has Symbols by TazeTSchnitzel on Thursday April 14, 2022 @07:34AM (#31025497)
You can intern strings without preventing mutability using the copy-on-write principle. PHP does it.
Re:Why Ruby Has Symbols by recursive on Thursday April 14, 2022 @10:32AM (#31027552)
If 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 */
Re:Why Ruby Has Symbols by TazeTSchnitzel on Thursday April 14, 2022 @04:25PM (#31032801)
A language runtime can make that work if it wants to. High-level semantics don't need to constrain the implementation.