>= vs => !!!
bulkhead
Posts: 405
What is the difference? In terms of actually evaluating two numbers, they appear to work the same, but the ">=" caused a really strange error in my program, but after changing it to "=>" it worked. Before I go into detail about my code, is there a difference?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm new to the propeller!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm new to the propeller!
Comments
=> or =>= is valid in SPIN "is equal or greater" page 157 of the manual..
the other way ">= is not valid syntax...
Can't really comment as to what actually happens when the editor lets you compile "Invalid syntax"
But yes it does sometimes do strange things...
cheers Ron Melbourne OZ
>= is a valid operator, but it not at all what you would think it is.
X >= Y is the same as X := X>Y
If they ever seem to work the same in a particular program it'll only ever be a fluke.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Prop Room Robotics - my web store for Roomba spare parts in the UK
Is it "if ( ( X > Y ) or ( X == Y ) )" or is it "if ( X := X > Y )" ?
The compiler has no way of determining what was intended.
Because the decision was taken to allow all binary operators in 'var OP= expr', including comparisons, the only way to achieve that is to rearrange the two ambiguous operators >= and <= to => and =<
So the choice is, no conditional operators in shortcut assignments allowing the traditional >= and <=, or allowing them with the result that we see in Spin.
An alternative approach could have been to use names, EQ, NE, GT, LT, GE, LE, and there'd be no ambiguity because the trailing = would be there or not, but I am sure there would be objections to that style.
Post Edited (hippy) : 12/3/2007 2:37:24 AM GMT
-Phil
-Phil