Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Mark Symbol as immutable #25349

Closed
wants to merge 1 commit into from
Closed

RFC: Mark Symbol as immutable #25349

wants to merge 1 commit into from

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 1, 2018

Symbol is a bit odd. On the one hand it is comparable by identity like mutable
types, on the other hand, its identity is entirely determined by its "contents",
like an immutable type. The setting of the mutabl flag is thus a bit arbitrary.
However, while that is the system perspective, from the user perspective, setting it
to immutable seems clearer, since a user associates the symbol value with the symbol
rather than its identity, and that symbol value is immutable.

Brought up here: https://discourse.julialang.org/t/whats-so-mutable-about-symbol-s/8094
I don't care strongly about this though, up for debate.

Symbol is a bit odd. On the one hand it is comparable by identity like mutable
types, on the other hand, its identity is entirely determined by its "contents",
like an immutable type. The setting of the mutabl flag is thus a bit arbitrary.
However, while that is the system perspective, from the user perspective, setting it
to immutable seems clearer, since a user associates the symbol value with the symbol
rather than its identity, and that symbol value is immutable.
@Keno Keno requested review from vtjnash and JeffBezanson January 1, 2018 17:33
@JeffBezanson
Copy link
Member

This might be ok, but creates a potential gotcha where a Symbol's address might be considered insignificant, due to its having no fields and Symbol.size == 0. For example some code might look at the Symbol type and decide it is a singleton.

@vtjnash
Copy link
Member

vtjnash commented Feb 5, 2018

Since any mutable object without fields is identifiable, I think Symbol is now most consistent as-is. Approximately operating as:

mutable struct Symbol
    function Symbol(s::String)
        sym = new()
        symbol_table[sym] = s
        return sym
    end
end
String(s::Symbol) = symbol_table[s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants