Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
squirreltown
Level 9

If not

Is there a difference between these two statements?

if not m.motionbit = invalid

if m.motionbit <> invalid


thanks
Kinetics Screensavers
0 Kudos
6 REPLIES 6\
EnTerr
Level 11

Re: If not

"squirreltown" wrote:
Is there a difference between these two statements?
if not m.motionbit[x] = invalid

if m.motionbit[x] <> invalid


No, they are the same.
"not" has lower precedence than comparison so things are allright.
You can use "da" in console to look at the bytecode when in doubt.
0 Kudos
TheEndless
Level 9

Re: If not

Potentially. Depends on the type of "m.motionbit". If it were a boolean, for instance, then your first statement would compare it's inverse to invalid (which would probably cause a type mismatch). There is no difference between these two statements, though:

if not (m.motionbit[x] = invalid)

if m.motionbit[x] <> invalid

Note the parentheses enforce the priority of how the expression is evaluated, so the equality gets evaluated prior to having the "Not" applied to it.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
squirreltown
Level 9

Re: If not

Fascinating. Thank you both.
Kinetics Screensavers
0 Kudos
EnTerr
Level 11

Re: If not

"TheEndless" wrote:
Potentially. Depends on the type of "m.motionbit". If it were a boolean, for instance, then your first statement would compare it's inverse to invalid

Nope - it does not depend at all on the value.
Operations are performed in order of precedence, as provided in TFM. In the case of if not m.motionbit = invalid then ..., dot-operator has highest priority and goes first, followed by [], followed by comparison operator, and NOT is last. In other words, it is the same as this (which by the way works too):
if (not ( ( (m.motionbit)[x] ) = invalid) ) then ...

The order/precedence of the operations has been done in such a way to minimize need for parenthesis in day-to-day coding.
0 Kudos
TheEndless
Level 9

Re: If not

"EnTerr" wrote:
"TheEndless" wrote:
Potentially. Depends on the type of "m.motionbit". If it were a boolean, for instance, then your first statement would compare it's inverse to invalid

Nope - it does not depend at all on the value.
Operations are performed in order of precedence, as provided in TFM. In the case of if not m.motionbit = invalid then ..., dot-operator has highest priority and goes first, followed by [], followed by comparison operator, and NOT is last. In other words, it is the same as this (which by the way works too):
if (not ( ( (m.motionbit)[x] ) = invalid) ) then ...

The order/precedence of the operations has been done in such a way to minimize need for parenthesis in day-to-day coding.

I guess I should have tried it first. But I think the better question is why would you want to "Not" a check for equality, instead of directly checking for inequality? What's the use-case in which you'd want/need to do that?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
EnTerr
Level 11

Re: If not

Well, docendo discimus.
It's useful to understand how expressions are evaluated/calculated in principle. There is some order and logic in how B/S works - aside from the half-documented, no-type-checks roComponents - or i would have forsaken it by now as "another PHP / mySQL". I am quite interested where the VM underneath comes from but doubt someone will tell me.

And of course, "when in doubt - use parenthesis".
0 Kudos