lua-users home
lua-l archive

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

On Thu, Dec 24, 2009 at 8:48 PM, David Manura <> wrote:
> The split function obviously belongs, but it is also a function easy
> to misimplement.

Yes, it's easy to get the simple cases working, but then the edge
cases start to bite...very useful to work from an existing standard in
this case.

> BTW, split functions often provide a "limit" parameter.  This can
> control whether something like "a,b,c," splits into {"a", "b,c,"},
> {"a", "b", "c"}, or {"a", "b", "c", ""}.

Again, good documentation is key!

Altogether good reasons for needing a community-approved, road-tested,
standards-compliant version.

Even the apparently simple functions require thought. For instance,
the payload of a map function is not complicated, but some iteration
choices are more optimal than other (ipairs slower than using a
numeric for, for instance). Also, need to decide on standard error
strategy up front; it must clearly indicate when its arguments are not
valid, and we need to decide whether it just throws that error or
returns nil,msg.  As a _user_ of Penlight, I've found inconsistency
and vagueness in this department can be very irritating.  Personally
I'm tending to 'throw error' immediately, but this is not appropriate
in a short script, where a third option is more end-user-friendly:
error message and terminate immediately.

This is an area where I miss the Perlism 'call_something() or die()';
maybe in a short user script a general 'die_on_error()' global
setting? These things are so much a matter of taste and intended
application. If try..except was available as sugar for pcall, then
this would not require so much agonizing.

steve d.