[erlang-questions] Different behaviour of the erl shell and compile:file

Aleksandr Vinokurov aleksandr.vin@REDACTED
Wed Mar 21 05:03:11 CET 2012


Any feedback so far?

I'll do epp.erl patch and new erlc option. 


19.03.2012, в 12:19, Aleksandr Vinokurov <aleksandr.vin@REDACTED> написал(а):

> 
> 
> Hello all,
> 
> I'm investigating Unicode support in Erlang. And have found the difference in behaviour of erl shell and compile:file.
> 
> The erl shell:
> 
> 1. We configure our terminal emulator to use UTF-8
> 2. We set io:setopts({encoding,unicode}).
> 3. Then in the prompt we enter a Unicode string and see the result -- a list of Unicode codepoints:
> (emacs@REDACTED)103> "АБВГД".
> [1040,1041,1042,1043,1044]
> 
> 
> The compile:file:
> 
> 1. We save a file foo in UTF-8 with a function that return a Unicode string bar() -> "АБВГД".
> 2. Now we open an erl shell and run compile:file(foo).
> 3. Finally running foo:bar() we have a list of UTF-8 bytes.
> (emacs@REDACTED)111> foo:bar().
> [208,144,208,145,208,146,208,147,208,148]
> 
> 
> I dug the compile:file/1 and found epp:server/4 where the file is opened with file:open(Name, [read]) and where encoding of the returned IoDevice is not configured.
> 
> Why not to use one of the Unicode recipes from the Unicode usage doc (lib/stdlib-1.18/doc/html/unicode_usage.html) to set io:setopts(F,[{encoding,Type}]) or add an encoding option to the compile:file/2 and erlc?
> 
> What would be your suggestions, honorable all?
> 
> -- 
> Александр Винокуров
> +7 (921) 982-21-43
> @aleksandrvin
> 



More information about the erlang-questions mailing list