io_lib:format and ++

Kent Boortz kent@REDACTED
Tue Feb 19 07:54:17 CET 2002


Hal Snyder <hal@REDACTED> writes:

> I don't think io_lib:format is returning a flat character string.
> 
> We have:
> 
> 1> "hello " ++ "there".
> "hello there"
> 
> but:
> 
> 2> io_lib:format("hello ~s", ["there"]).
> [104,101,108,108,111,32,"there"]
> 
> 
> So, cooking long strings with io_lib:format() gave me a surprise when
> the next thing to happen was a regexp:split, which does care about
> depth.
> 
> Bug, or confused programmer?

This is a feature. From the reference manual

  MODULE
       io_lib - IO Library Functions

  DESCRIPTION
       This module contains functions for converting  to  and  from
       strings  (lists of characters). They are used for implement-
       ing the functions in the io module. There  is  no  guarantee
       that the character lists returned from some of the functions
       are flat, they can be deep lists.  lists:flatten/1  is  used
       for generating flat lists.

But the reference manual fr io_lib lack type information for the
functions so it is easy to missinterpret.

kent



More information about the erlang-questions mailing list