Erlang prints (some) lists as strings

Per Hedeland per@REDACTED
Thu Nov 11 01:19:08 CET 1999


>That's about what it will take, since Erlang doesn't have a "character" data
>type, and the shell has to guess whether any given integer in a list is
>meant to be a number or text.

Or more precisely, the shell uses the 'p' (or to be pedantic, 'P')
control character(*), that asks for the guessing, when printing its
output - you don't have to do that in your program:

1> L=[111,111,111].      
"ooo"
2> io:format("~w~n",[L]).
[111,111,111]
ok
3> io:format("~p~n",[L]).
"ooo"
ok

--Per Hedeland
per@REDACTED


(*): From the io(3) man page:

            w:  Writes data with the  standard  syntax.  This  is
                used  to  output  Erlang terms. Atoms are printed
                within  quotes  if  they  contain  embedded  non-
                printable  characters,  and floats are printed in
                the default g format.

            p:  Writes the data with standard syntax in the  same
                way   as  ~w,  but  breaks  terms  whose  printed
                representation is longer than one line into  many
                lines  and  indents  each  line sensibly. It also
                tries to detect lists of printable characters and
                to output these as strings.



More information about the erlang-questions mailing list