[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Separator in table concatenation
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sun, 9 Dec 2012 06:51:39 +0200
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.