Write Term to File

Michał Muskała michal@REDACTED
Wed Jan 27 00:01:49 CET 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210126/918d250d/attachment.htm>


More information about the erlang-questions mailing list