All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reference.language.precedence.html Maven / Gradle / Ivy




    
    Operators precedence
    
    

    
    

    
    

    
    
    
    

    


Operators precedence

Composed mathematical expressions, such as 1 + 3 / 4 - 9 can be evaluated in many ways, depending on which operator: +, / or - is applied first.
While humans can make decisions based on common sense, Prompto has a pre-defined set of rules to ensure the sequence is always the same.
This is called operator precedence. In Prompto, the mathematical operator precedence is as follows:

  • - exp -> minus
  • not exp -> logical not
  • exp * exp -> multiply
  • exp / exp -> divide
  • exp % exp -> remainder
  • exp \ exp -> integer divide
  • exp + exp -> add
  • exp - exp -> subtract
  • exp < exp -> less than
  • exp <= exp -> less than or equal
  • exp > exp -> greater than
  • exp >= exp -> greater than or equal
  • exp = exp -> equal
  • exp ~ exp -> roughly equal
  • exp or exp -> logical or
  • exp and exp -> logical and
This means that in the above expression, the evaluation is performed in the following sequence: 3 / 4, then 1 + 0.75 and finally 1.75 - 9.

Although Prompto precedence is similar to most programming languages, the above list can be hard to remember.
Precedence can become even more complex with Prompto, because it uses a number of keywords as operators, such as in, contains, as and others.
The best way to keep code unambiguous and avoid mistakes is to use parenthesis.

Parenthesis expressions

A parenthesis expression is used to manage precedence.
A parenthesis expression is a code fragment which produces a value, whose type is determined by the enclosed value, and which can then be used as an input for other operations: print, write, method call and so forth.
A parenthesis expression has the form ( exp ).

As you can see, both expressions trigger the same result. But using parenthesis makes it clear for readers what the intent is.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy