Erlang does have problems

Scott Lystig Fritchie fritchie@REDACTED
Thu Aug 31 05:01:39 CEST 2006


>>>>> "bi" == Bob Ippolito <bob@REDACTED> writes:

bi> I'm also not terribly convinced that lists are better for
bi> concatenation, because adding data to the end of a list requires a
bi> lot of copying and that's the most common operation in my
bi> experience.

Oh?  At last check, "X = [A, B]" executed in O(1) time regardless of
the sizes of A & B.  As far as I/O lists are concerned,
[<<"fo">>, [[], $o], [[[<<"ba">>]], <<"r">>]] yields the same effect as
<<"foobar">>.

If whatever library you're working can only tolerate "flat" lists(*),
then you're limited to O(length(A)) concatenation (lists:append/2, A
++ B, etc).

Richard O'Keefe's contributions to the "Strings (was: Re: are Mnesia
tables immutable?)" thread on this mailing list(**) are quite
informative and, IMO, should be mandatory reading for "strings"
people.

-Scott

(*) 1> lists:flatten([<<"fo">>, [[], $o], [[[<<"ba">>]], <<"r">>]]).
    [<<"fo">>, 111, <<"ba">>, <<"r">>]

(**) That thread took place (roughly) between 27 June and 06 July,
2006.



More information about the erlang-questions mailing list