lua-users home
lua-l archive

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


2012/12/8 Luis Carvalho <lexcarvalho@gmail.com>:
>> It would be nice if table.concat behaved like string.gsub:
>>    table.concat(tbl,sep)
>> would allow `sep` to be not only a string, but also a table or
>> function, indexed or called with the current list index.

> If `sep` depends on the index then isn't it better to simply "merge" tbl and
> a `sep` table and then concat the result?
..
> Alternatively, you might want to have a slightly more general concat
> function that pre-formats table entries:
>
> table.gconcat = function (t, sep, format)

I agree with two of your points:

1. Having `sep` depend only the key and not on the value does not
   add much.
2. An enhanced `concat` function may as well have a different name.

In fact, there is no special reason why an enhanced `concat` should
be in the Lua core.  It could simply be put into a module.

The original proposal arose from wondering where else in the standard
libraries the existing string/table/function idea, already exploited
in `gsub`, could be useful.