lua-users home
lua-l archive

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

On Thu, Dec 31, 2009 at 1:44 PM, Leo Razoumov <> wrote:
On 2009-12-31, steve donovan <> wrote:
> On Wed, Dec 30, 2009 at 12:05 PM, Philippe Lhoste <> wrote:
>  > Perhaps the comment from ltable.c:
> [..snip..]
>  A map() function could easily generate lots of holes:
>  map(tonumber,{'10','x','20','y'})  --> {10,nil,20,nil}
>  [..snip..]
>  steve d.

I wish that "map" would convert nil to false before pushing it into
resultant array so that it becomes {10, false, 20, false} avoiding
holes and preserving the length. Within conditionals like "if",
"while" etc nil and false are equivalent.


It's not usually helpful using a "normal" value like false to denote "missing" values in an array. What if the function you are mapping works on booleans? Obviously, nil is no good either.

So, for these cases I have a global NULL={} and use that whenever I need a non-nil missing value. It then takes a bit of restraint and care to use the NULL value correctly.