Welcome to the Parallax Discussion Forums, sign-up to participate.

Order operations spin (NOOB question)

Posts: 2
PE Kit lab book v1.2 page 91

if Cog
cogStop(cog~ - 1)

If ~ is on a higher level than - 1 why is - 1 evaluated first?
Reference http://nagasm.org/ASL/Propeller/printedPDF/QuickReference-v15.pdf

• Posts: 21,233
~ is precedence level 0 and X~ is post-clear to 0.

- is precedence level 6 and is subtract.

The key point here is the "post", as in "after".

So what you have in "cogStop(cog~ - 1)" is:

1) Take the value of cog into some internal temporary value.

2) Set the value of cog to zero.

3) Subtract one from that internal temporary value.

4) Pass the temporary value to cogStop as a parameter.
• Posts: 1,374
edited 2016-04-15 - 08:05:40
x~ is evaluated before - 1.

x~ clears x but returns the old value of x. Just like how x++ increments x but returns the old value of x (while ++x increments x but returns the new value instead of the old).
• Posts: 2
Thank you I understand now.