[erlang-questions] unicode in string literals

Joe Armstrong <>
Mon Jul 30 14:35:50 CEST 2012


What is a literal string in Erlang? Originally it was a list of
integers, each integer
being a single character code - this made strings very easy to work with

The code

    test() -> "a∞b".

Compiles to code which returns the list
of integers [97,226,136,158,98].

This is very inconvenient. I had expected it to return
[97, 8734, 98]. The length of the list should be 3 not 5
since it contains three unicode characters not five.

Is this a bug or a horrible misfeature?

So how can I make a string with the three characters 'a' 'infinity' 'b'

test() -> "a\x{221e}b"        is ugly

test() -> <<"a∞b"/utf8>>   seems to be a bug
                                            it gives an error in the
shell but is ok in compiled code and
                                            returns
<<97,195,162,194,136,194,158,98>> which is
                                            very strange

test() -> [$a,8734,$b]       is ugly

/Joe



More information about the erlang-questions mailing list