I was using some coroutines and was trying to resume one using not:
if not co == nil then `resume end
and the coroutine wouldn't resume. Though co was nil. It was baffling.
So I eventually tried
if co then `resume end
and it worked!
why isn't not (nil == nil), which is logically false when co is nil and true when it is not which is not the same as as nil which is logically false when co is nil and true otherwise?
I use not all the time to negate the logical expression but now I'm worried that maybe some of my code is buggy. Maybe this only has a problem with coroutines? (and I'm 100% sure that the value is nil, because that is what is printed out, unless nil no longer equals nil)
not co == nil is equivalent to (not co) == nil because of operator precedence.
If co is nil, then not co is true and so different from nil.
In fact, the result of not is always true or false, and so never equal to nil.
Write not (co == nil) or co ~= nil.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With