[erlang-questions] Strings as Lists

Bjorn Gustavsson bjorn@REDACTED
Wed Feb 13 07:58:51 CET 2008


Kevin Scaldeferri <kevin@REDACTED> writes:

> On Feb 12, 2008, at 2:13 PM, Robert Virding wrote:
> 
> Hold on... lists aren't really a particular convenient or efficient  
> data structure for working with strings.  First off, I append to  
> strings a lot more than I prepend to them.

You can append by building a deep list and only flatten it at the end.

        NewString = [AListOfChars|AnotherListOfChars]

or
        NewString = [AListOfChars,ACharacter]

Or you can simply do a recursion (not tail-recursion) and use
the '++' operator. That will be efficient, because the recursion will
ensure that the '++' operators are executed in a right-to-left order.

/Bjorn
-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list