Forum: Ruby Ruby 2.0: Symbol uniqueness?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
912c61d9da47754de7039f4271334a9f?d=identicon&s=25 MenTaLguY (Guest)
on 2006-05-05 18:18
(Received via mailing list)
I just learned yesterday that different string values can intern to the
same symbols; for example:

 p "!".intern == "!@".intern # => true
 p "-(unary)".intern == "-@".intern # => true

There aren't many such cases, but it makes life awkward if you're
writing code where two such strings are valid input (e.g. "!" and "!@"
are both valid, if unusual, identifiers in Scheme s-expressions).

This seems to be a side-effect of the current implementation of unary
operators in Ruby 1.x -- is it slated for change in Ruby 2.0?

I think it'd be nice if Ruby symbols were guaranteed to uniquely
represent string values, and x.intern.to_s == x were an invariant for
non-empty strings.

-mental
573b9499030e1ccb867ef80f0ff1ac49?d=identicon&s=25 Justin Bailey (Guest)
on 2006-05-05 18:45
(Received via mailing list)
This may be a question for the Ruby Core list?
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2006-05-08 14:09
(Received via mailing list)
MenTaLguY <mental@rydia.net> writes:

> I think it'd be nice if Ruby symbols were guaranteed to uniquely
> represent string values, and x.intern.to_s == x were an invariant
> for non-empty strings.

+1
55814285012fcdabeb354a89e40a8522?d=identicon&s=25 Shad Sterling (Guest)
on 2006-05-11 20:43
(Received via mailing list)
On 5/5/06, MenTaLguY <mental@rydia.net> wrote:
>
> I think it'd be nice if Ruby symbols were guaranteed to uniquely represent
> string values, and x.intern.to_s == x were an invariant for non-empty
> strings.


+1


-mental
>
>

--

Shad Sterling
me@shadsterling.com
http://shadsterling.com
This topic is locked and can not be replied to.