Convert symbols to strings

1,731 views
Skip to first unread message

Jonathan Malmaud

unread,
Dec 6, 2013, 1:38:32 PM12/6/13
to juli...@googlegroups.com
Was there a design decision to not have something like
convert(::Type{UTF8String}, x::Symbol) = string(x)?

Seems like it would be convenient. 

Stefan Karpinski

unread,
Dec 7, 2013, 11:27:28 AM12/7/13
to Julia Dev
No, I can't think of a reason not to do that.

Kevin Squire

unread,
Dec 7, 2013, 11:44:57 AM12/7/13
to juli...@googlegroups.com
Hi Jonathan, 

Just for curiosity, how would you be using this?  Not objecting, but I can't figure out where I would use it.

Kevin

Jonathan Malmaud

unread,
Dec 7, 2013, 1:59:55 PM12/7/13
to juli...@googlegroups.com
It just came up because I was trying to create a dataframe from a dictionary, where the keys in my dictionary were symbols containing the intended column names. The dataframe constructor apparently tries to use convert to get a string form of the keys it's passed, so it threw an error.

Kevin Squire

unread,
Dec 7, 2013, 4:28:38 PM12/7/13
to juli...@googlegroups.com
Okay, that makes perfect sense now. 

Cheers, Kevin

Michel Lesoinne

unread,
Aug 28, 2014, 12:25:29 PM8/28/14
to juli...@googlegroups.com
Has there been action on this? How can I get the string corresponding to a symbol?

Tim Holy

unread,
Aug 28, 2014, 2:25:20 PM8/28/14
to juli...@googlegroups.com
Does string(:x) do what you want, or are you thinking of something different?

--Tim

Michel Lesoinne

unread,
Aug 28, 2014, 2:51:44 PM8/28/14
to juli...@googlegroups.com
It does. Sorry for the noise, I had tried String(:x) and that fails.

Tim Holy

unread,
Aug 28, 2014, 2:57:28 PM8/28/14
to juli...@googlegroups.com
I asked it as a question because I've sometimes wondered if there's need for a
more efficient converter, something along the lines of what bytestring does
given a Ptr{Uint8}.

--Tim

Steven G. Johnson

unread,
Aug 29, 2014, 9:27:24 AM8/29/14
to juli...@googlegroups.com
If you convert(Ptr{Uint8}, :somesymbol), it is quite efficient -- it just gives you a pointer to the internal symbol representation in memory, without making a copy or converting to a string first.

Tim Holy

unread,
Aug 29, 2014, 9:30:25 AM8/29/14
to juli...@googlegroups.com
I hadn't noticed the convert(Ptr{Uint8}, :somesymbol) method, that's exactly
what I had in mind. Very nice.

--Tim
Reply all
Reply to author
Forward
0 new messages