Write Term to File

Oliver Bollmann oliver.bollmann@REDACTED
Wed Jan 27 00:24:22 CET 2021


That's true for file:consult, but

the user who want to edit the file will see

{"cn",[28450]}.

and not

{"cn","漢"}.

So, for the user it's different!

What is the right way to save?

Regards,

Oliver


On 27.01.21 00:01, Michał Muskała wrote:
>
> Those two values are exactly the same. Lists of integers representing 
> codepoints and strings are two ways of representing the same value. 
> Reading back with file:consult should reproduce exactly the same values.
>
> $ erl
>
> Erlang/OTP 23 [erts-11.1.5] [source] [64-bit] [smp:16:16] 
> [ds:16:16:10] [async-threads:1] [hipe] [dtrace]
>
> Eshell V11.1.5  (abort with ^G)
>
> 1> {"cn",[28450]} =:= {"cn","漢"}.
>
> true
>
> 2> io:format("~tp.\n",[{"cn","漢"}]).
>
> {"cn",[28450]}.
>
> ok
>
> If you’re asking if you can make io:format print the string 
> representation rather than list one for high-codepoint characters, the 
> answer is you can, by starting the VM in Unicode mode with +pc unicode 
> flag:
>
> $ erl +pc unicode
>
> Erlang/OTP 23 [erts-11.1.5] [source] [64-bit] [smp:16:16] 
> [ds:16:16:10] [async-threads:1] [hipe] [dtrace]
>
> Eshell V11.1.5  (abort with ^G)
>
> 1> io:format("~tp.\n",[{"cn","漢"}]).
>
> {"cn","漢"}.
>
> ok
>
> Michał.
>
> *From: *erlang-questions <erlang-questions-bounces@REDACTED> on 
> behalf of Oliver Bollmann <oliver.bollmann@REDACTED>
> *Date: *Tuesday, 26 January 2021 at 22:52
> *To: *Erlang-Questions Questions <erlang-questions@REDACTED>
> *Subject: *Write Term to File
>
> How can i write term to file, for later using in file:consult?
>
> I do:
>
> R = io_lib:format("~tp.",[{"cn","漢"}]),
> file:write_file(FileName,R)
>
> But this gives:
>
> {"cn",[28450]}.
>
> I need:
>
> {"cn","漢"}.
>
> Any hints?
>
> -- 
> Grüße
> Oliver Bollmann
>
-- 
Grüße
Oliver Bollmann

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210127/bb37a7c2/attachment.htm>


More information about the erlang-questions mailing list