[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Empty? No. Array? No. Has? Yes.
- From: Eike Decker <zet23t@...>
- Date: Wed, 3 Jul 2013 23:39:10 +0200
2013/7/3 Andrew Starks <email@example.com>:
> Also, what does type(t[#t +1]) return? "nil(undefined)"?
> That would break any place where you were checking for nil, amongst
> other possible value types.
No. Because the type() returns "nil" as well as type(nil) returns
"nil" - it's not like type(true) would return "boolean(true)" :)
As I wrote: The nil value would behave as it does right now - it only
bears an invisible flag that is only exposed by a newly introduced
function - and the fact that table values don't get deleted if they
have a defined nil value. That allows using a "has(t,k)" function that
checks if it's the "right" nil value.
Actually, if table keys get deleted as they are deleted right now on
nil assignment, no matter if it's a defined or undefined nil value,
this concept is totally compatible with plain Lua. It would at least
allow a programmer to distinguish nil values that were returned on
purpose or that just denote a lack of a value.