lua-users home
lua-l archive

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


> > t[i]=undef is a special syntax form that means "remove the key 'i'
> > from table 't'".
> 
> But it seems like an assignment.  Wouldn't be better to create a special
> syntax for removing a key from a table instead pretending it as an
> assingment?
> 
> You should have considered a pair of functions, such as table.undefine(t,
> i) to undefine a key, and table.defined(t, i) to check whether the table
> has the key.  Why did you choose the assignment?

Mainly because of compatibility with older versions. As I said, I like
the idea of using 't[i]=undef' even in older versions, as a idiom to
better document things being removed from a table.

We fully agree that it may be confusing; that is why we are testing it
in this work release.

A new syntax (such as "delete a[k]" or anything like that) would be
the worst for compatibility, as new programs using it would not even
compile in older Lua. Functions are not that bad; with something
like

      table.undefine = table.undefine or function(t,k) t[k] = nil end

we get compatibility in older Lua. But with 't[i=undef' we have
compatibility without any work :-)

-- Roberto