Operators

GoMelan supports many basic operators.

In our language, operators are subject to the rules of operator precedence, ensuring calculations are performed in the intended sequence.

Basic Operators in GoMelan

GoMelan supports various basic operators that can be applied to numeric types, such as Int and Float. It's essential to ensure that the types are consistent throughout the calculation.

Becareful, to apply these operators, all the types should be the same across the whole calculation. For example if you want to do

var:Float=0.1+2;

Please consider converting your types var:Float=0.1+ intToFloat(2);

Arithmetic Operators

  • Addition (+):

    result: Float = 2.5 + 3.8;
  • Subtraction (-):

    difference: Int = 10 - 4;
  • Multiplication (*):

    product: Float = 4.0 * 2.5;
  • Division (/):

    quotient: Int = 15 / 3;

Comparison Operators

  • Equal (==):

    isEqual: Bool = 5 == 5;
  • Not Equal (!=):

    notEqual: Bool = 10 != 5;
  • Greater Than (>):

    isGreaterThan: Bool = 8 > 5;
  • Less Than (<):

    isLessThan: Bool = 3 < 7;
  • Greater Than or Equal To (>=):

    isGreaterOrEqual: Bool = 6 >= 6;
  • Less Than or Equal To (<=):

    isLessOrEqual: Bool = 9 <= 10;

Logical Operators

  • Logical AND (&&):

    result: Bool = true && false;
  • Logical OR (||):

    result: Bool = true || false;
  • Logical NOT (!):

    notResult: Bool = !true;

Last updated