lua-users home
lua-l archive

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


On Fri, Jun 28, 2013 at 2:57 AM, Tim Hill <drtimhill@gmail.com> wrote:
I'm going to get shot for suggesting this… (hides under bed)

Nah, it's a perenial issue.  But it always ends up complicating the language, which we don't tend to like...

I've been writing a lot of Lua code recently, some of it quite generic in nature. One thing I frequently come up against is the need to handle data polymorphically in tables. And an effect of this is to hit against the overloaded use of "nil" in Lua.

OK, now if you're storing objects, why not the old standby `false`?  It strikes me as unusual to have containers of genuinely unrelated values - generally I like to put Cats and Dogs in separate tables, unless they do share some common behaviour. For tables, strings and userdata, `false` has the right semantics - because it's false.

for _,o in ipairs(list) do
  if o then
    -- do something!
  end
end

There's an issue of course if you're found of standard map and filter operations.

steve d.