[erlang-questions] cookbook entry #1 - unicode/UTF-8 strings

Bob Ippolito bob@REDACTED
Wed Oct 19 13:23:27 CEST 2011


On Wed, Oct 19, 2011 at 3:14 AM, Joe Armstrong <erlang@REDACTED> wrote:
> cookbook # 1 - draft 1
>
> Question 4)  Can string literals be improved on?
>
> I hope so -- In Html I can say (I hope) €
>
> I'd like to say:
>
>      X = "10€" in Erlang
>
>      People who know far more about this than I do can tell me if this
> is OK

In Python you can use the syntax u"\N{EURO SIGN}" which is equivalent
to u"\u20ac" (in Python 3 the string literal would not be prefixed
with u). This would require that Erlang ship with a big database of
all the mappings (in Python this is the unicodedata module), but it
would be doable.

In mochiweb there's a module mochiweb_charref that can convert any
HTML5 entity such as € to code points (or lists of code points in
some newer cases). I think it would be quite interesting if Erlang
would natively support this much smaller table of useful and easier to
remember names of characters. Perhaps someone could experiment with it
in a parse transform?

io:format("~ts ~ts ~ts~n", [[mochiweb_charref:charref(S)] || S <-
["euro", "NotEqual", "#x24"]]).
€ ≠ $

-bob



More information about the erlang-questions mailing list