Order operations spin (NOOB question)

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


  • ~ 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.
  • ElectrodudeElectrodude 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).
  • Thank you I understand now.
Sign In or Register to comment.