Skip to content

additive expression

Cameron Purdy edited this page Apr 7, 2020 · 1 revision

The + and - binary operators are well-known, representing addition and subtraction. The corresponding expressions use the common forms:

a + b
a - b

The operators and their corresponding default method names are as follows:

Op Default method name Description
+ add addition
- sub subtraction

Despite appearing to be primitive-type operators, Ecstasy has no primitive type system, and the input and output types of these operators are defined entirely by the types against which the operators execute. Specifically, the type of the expression a must have an unambiguously single best operator method (selected by the operator symbol and method name) that takes an argument of the type of expression b. The implicit type of the expression is the return type of the operator method.

The execution of the expression is an invocation of the selected operator method, against a target reference yielded by the expression a, passing one argument as yielded by the expression b; the result of the expression is the return value from the operator method.

The expression short-circuits if either expression a or b short-circuits.

The expression uses the default left-to-right definite assignment rules:

  • The VAS before a is the VAS before the expression.
  • The VAS before b is the VAS after a.
  • The VAS after the expression is the VAS after b.

These expressions group to the left, so for example, a + b + c is treated as (a + b) + c:

    AdditiveExpression:
        MultiplicativeExpression
        AdditiveExpression + MultiplicativeExpression
        AdditiveExpression - MultiplicativeExpression