|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
symbol to stringHi all,
scala> 'test.toString res0: String = 'test I think it would be more natural if it returned 'test.name, just: res0: String = test It looks like a very trivial issue, but there are for example glitches in some serialization libraries that don't handle Symbol and it would be nice to have it directly as a proper String. Ruby (a darn elegant language) handles it perfectly: >> :test.to_s => "test" Is there some reason why the Symbol string representation still includes the quote? Why would we want to have it that way? (afaics there's no way to "monkey patch" this behaviour) Francisco |
|
|
Re: symbol to stringOn Tue, Nov 3, 2009 at 7:14 AM, francisco treacy <francisco.treacy@...> wrote: Hi all, Here's why toString makes sense the way it is: scala> List('hello, 'world) res0: List[Symbol] = List('hello, 'world) If toString represents the human readable version of the thing, keeping the tick makes sense because the above is a List of Symbol and that's clear from the result ( List('hello, 'world) ) Personally, I was cranky about Symbol.toString's behavior when I first started using it... then I realized that Symbol's performance is anti-optimized in Scala (I could find no case where using Symbol was faster than using String) so I gave up on Symbol all together. Not much help, I know, but it's my experience.
-- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics |
|
|
Re: symbol to stringHi David, thanks for your answer.
I'd like to make it clear that I love using Symbols mostly for code readability (apart from the fact they are interned). class Test(database: Symbol) { private implicit val db = :/(hostname, port) / database // toString is called everywhere, i'd like to avoid having to call "database.name" (...) } > Here's why toString makes sense the way it is: > > scala> List('hello, 'world) > res0: List[Symbol] = List('hello, 'world) Personally I don't think it makes sense to keep the tick. What about the following? scala> List("1", "2") res9: List[java.lang.String] = List(1, 2) scala> List(1, 2) res10: List[Int] = List(1, 2) You can only tell the type of those lists by reading the actual type, not by the toString representation. I have a patch, do you know where/how should I send it? Francisco 2009/11/3 David Pollak <feeder.of.the.bears@...>: > > > On Tue, Nov 3, 2009 at 7:14 AM, francisco treacy > <francisco.treacy@...> wrote: >> >> Hi all, >> >> scala> 'test.toString >> res0: String = 'test >> >> I think it would be more natural if it returned 'test.name, just: >> res0: String = test > > Here's why toString makes sense the way it is: > > scala> List('hello, 'world) > res0: List[Symbol] = List('hello, 'world) > > > If toString represents the human readable version of the thing, keeping the > tick makes sense because the above is a List of Symbol and that's clear from > the result ( List('hello, 'world) ) > > Personally, I was cranky about Symbol.toString's behavior when I first > started using it... then I realized that Symbol's performance is > anti-optimized in Scala (I could find no case where using Symbol was faster > than using String) so I gave up on Symbol all together. > > Not much help, I know, but it's my experience. > >> >> It looks like a very trivial issue, but there are for example glitches >> in some serialization libraries that don't handle Symbol and it would >> be nice to have it directly as a proper String. >> >> Ruby (a darn elegant language) handles it perfectly: >> >> >> :test.to_s >> => "test" >> >> Is there some reason why the Symbol string representation still >> includes the quote? Why would we want to have it that way? >> (afaics there's no way to "monkey patch" this behaviour) >> >> Francisco > > > > -- > Lift, the simply functional web framework http://liftweb.net > Beginning Scala http://www.apress.com/book/view/1430219890 > Follow me: http://twitter.com/dpp > Surf the harmonics > |
|
|
Re: symbol to stringOn Tue, Nov 3, 2009 at 8:24 AM, David Pollak <feeder.of.the.bears@...> wrote: Personally, I was cranky about Symbol.toString's behavior when I first started using it... then I realized that Symbol's performance is anti-optimized in Scala (I could find no case where using Symbol was faster than using String) so I gave up on Symbol all together. Hopefully ticket 2384 will fix that. |
| Free embeddable forum powered by Nabble | Forum Help |