Re: Write Term to File

Oliver Bollmann <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <[email protected]>
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 <[email protected]> on 
> behalf of Oliver Bollmann <[email protected]>
> *Date: *Tuesday, 26 January 2021 at 22:52
> *To: *Erlang-Questions Questions <[email protected]>
> *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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.