lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Instead, table.concat uses a very complex algorithm, partially
> described in PIL section 11.6, in which it creates a stack of strings
> which are concatenated in a tower of hanoi-esque way. What's the point
> of doing that?

There is a misconception in your argument. The "very complex" algorithm
that table.concat uses is not part of table.concat. It is a generic
buffer implementation used by many other functions in the Lua library;
several of them need that kind of "grow-as-you-go" approach that it
supports (e.g., string.gsub and io.read"*a").

Given that we have the buffer implementation available, the actual
implementation of table.concat is quite simple, certainly simpler than
yours. It may not be as fast, but then we have to weight complexity
against performance.

-- Roberto