This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
[Question] not and ~=
Post Reply
Return to board index
Post by
Wildhorn
Just wanted to know. Do "not" and "~= nil" are the samething?
Like does:
if not Var1 then
end
is the same than:
if Var1 ~= nil then
end
Post by
213828
This post was from a user who has deleted their account.
Post by
Wanderingfox
Logical operators
Lua provides the logical operators and, or and not. In Lua both nil and the boolean value false represent false in a logical expression. Anything that is not false (either nil or false) is true. There are more notes on the implications of this at the end of this page.
> = false==nil -- although they represent the same thing they are not equivalent
false
> = true==false, true~=false
false true
> = 1==0
false
> = does_this_exist -- test to see if variable "does_this_exist" exists. no, false.
nil
not
The keyword not inverts a logical expression value:
> = true, false, not true, not false
true false false true
> = not nil -- nil represents false
true
> = not not true -- true is not not true!
true
> = not "foo" -- anything not false or nil is true
false
Post by
Wildhorn
@emeral:
Ahem
@fox: Thanks, but im still unsure for the part (which was the purpose of my question):
> = not "foo" -- anything not false or nil is true
false
My English prevent me to get it right i think...
"anything not false or nil is true" means which one between:
1) not false = true, not nil = true
2) not false = true, nil = true
For "not Var1". If Var1 is equal to 1, what will it return and if it is equal to nil, what will it return?
It seems so simple, but for some reason, it doesnt want to get right in my head and it !@#$ me off hard.
Post by
Wanderingfox
anything that is not nil or false is true. That is to say that not "foo" will return false because "foo" is true, so nil is false, false is false, and everything else is true.
Your specific example:
var = 1
var is true
not var is false
var ~= nil is true
var == nil is false
Post by
Wildhorn
In other words I wanted to know is about that freaking confusing sentence: "anything that is not nil or false is true"
Was it:
1) (not nil) or (false)
2) not (nil or false)
I find that English has the tendency to skip words which make some sentence to have 2 possible meaning.
Post by
Wikipedia
Something that isn't nil or false will return true.
Think it was somewhat clearer.
Post by
Wanderingfox
In other words I wanted to know is about that freaking confusing sentence: "anything that is not nil or false is true"
Was it:
1) (not nil) or (false)
2) not (nil or false)
I find that English has the tendency to skip words which make some sentence to have 2 possible meaning.
You'd have a hell of a time with Japanese when whole parts of the conversation are implied XD
Post by
Wildhorn
Thats why I do not speak Japenese :P
@Wiki: Thanks alot, it was the answer that I needed to make it very clear.
Post by
pelf
You can also think about it in terms of an existence check.
if (something)
can be read as "if something exists and it's true". That's kind of what goes through my head when I'm reading those things in languages where nil/null is false.
Post by
RedwoodElf
Makes you wonder why so many Anime androids exist...an AI needs to have everything explicitly stated...robots don't do "implied" instructions.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.