Shop OBEX P1 Docs P2 Docs Learn Events
>= vs => !!! — Parallax Forums

>= vs => !!!

bulkheadbulkhead Posts: 405
edited 2007-12-03 05:10 in Propeller 1
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!

Comments

  • OzStampOzStamp Posts: 377
    edited 2007-12-02 08:48
    Hi

    => 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
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-12-02 10:02
    => is exactly what you would think it is.

    >= 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
  • hippyhippy Posts: 1,981
    edited 2007-12-03 02:27
    If anyone hasn't worked out the rationality for => and =< rather than the more commonly expected >= and <=, it's all down to allowing "var OP= expr" assignments within conditions and within sub-expressions. If the 'traditional' >= were used, then what does; "if ( X >= Y )" mean ...

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-03 02:40
    Perhaps EQ and its brethren have been reserved for future lexical comparisons, a la Perl! smile.gif

    -Phil
  • hippyhippy Posts: 1,981
    edited 2007-12-03 04:43
    @ Phil : I knew I'd seen it somewhere recent, and if I'm not mistaken EQ and == are two entirely different things. Fortan had .EQ. .NE. etc.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-03 05:10
    Yup. In Perl, at least, eq compares strings, and == compares numbers. So, "00" ne "0", but "00" == "0".

    -Phil
Sign In or Register to comment.