lua-users home
lua-l archive

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




Il gio 15 mar 2018, 23:13 Tim Hill <drtimhill@gmail.com> ha scritto:


On Mar 14, 2018, at 2:40 PM, pocomane <pocomane_7a@pocomane.com> wrote:


```
local t = {1}
t[1] = undef
print('1', t[1] == undef)
print('2', t[1] == nil)
```

Why are both true? I know why, I am just anticipating the discussion
that will substitute the # ones. Then someone will ask "But, can we
just make case-2 to be false?". Than someone else will replace, "No
because It will mean to make undef a value”

As Roberto notes, “undef” is NOT a value, you can’t use it in an equality check. It’s just a magic syntax that is allowed ONLY as the RHS of a table element assignment. (I think…)

—Tim

In the first Roberto's message about undef it is explained what the "Comparison" syntax would do with the new keyword.

So, I think my code is quite correct. Also because I run it at least two time before post it here (interactively and batch).

And as already said, I know why it works that way and it is not a surprise to me. I just want to stress new strangeness that will puzzle the future Lua users, like # does right now.

Finally, since multiple time the discussion ended in the same (sterile) way, I want to make one point clear. And I will do it with a sophisticated method pioneered by Roberto's:

I KNOW UNDEF IS NOT A VALUE. I KNOW IT IS A KEYWORD. I KNOW THE IMPLICATIONS OF THIS FACT.