lua-users home
lua-l archive

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


> See the code: When it does t[k] =<some other value>, the field t[k] does
> not exist (it was erased two lines earlier), so it is assigning to a
> non-existent field, which is explicitly forbiden.

I see the point now. Undefined behavior is undefined behavior.
On the other hand, why not define it in a different way?
Say:
1. Assigning a value to some key reserves a slot (and fills it with a
value) in a table.
2. Assigning nil to existing value doesn't release a slot for a value.
3. Rehashing may delete reserved slots with nil for a value.
4. Assigning non-nil value to key with reserved slot is guaranteed to reuse it.

Is this the way Lua currently behaves or there's a trick about
toggling array/non-array keys?
Or maybe, these rules add unnecessary limitations for internal
implementations (though these rules extend semantics...)?

P. S. I'm not sure if it good proposal, just kinda too curious:-)