On Jul 6, 2013, at 2:13 PM, Jorge <email@example.com> wrote:
dding nil doesn't change anything here: your loop would also break if some confused person stuck a table or a coroutine into the array. It's already necessary to either check that each value is the type you expect or ensure that unexpected types don't end up in the array to begin with, whether nil is an accepted type or not.I think this is a fundamental difference. Array based algorithms (say binary search, some sorting, or simple traversing) assume that each slot in the array contains something worth looking up, whatever makes sense for the application. Nil is never that, because there is nothing you can do with it. Nil is not something that must have a meaning in the application domain, it's effectively out of band application wise.
Not quiet. We're into devious semantics here, but 'nil' can and does have meaning all over Lua; for example when the libraries return nil+error message they are using nil to convey meaning. There are any number of places where you quite naturally use "if … == nil …". And when you start to work with generic programming, something that means "not any normal value" (i'll skip over what "normal" means for the time being), then 'nil' is very valuable. Except you cannot use it in arrays, so you need a work-around. Hence this entire discussion :)