Skip to content
Cameron Purdy edited this page Apr 8, 2020 · 3 revisions

The range operator .. is well-known to programmers in languages including Perl and Swift. The RangeExpression follows the pattern of other binary-operator expressions:

a .. b

Additionally, the syntax can take either of these two forms:

[ a .. b ]
[ a .. b )

The a .. b and [ a .. b ] forms have the same meaning, which is an inclusive range, starting with and including a, and ending with and including b. The form [ a .. b ) specifies an exclusive range, starting with and including a, and ending with but excluding b.

Form @Op Start End
[ a .. b ] .. Inclusive Inclusive
[ a .. b ) ..< Inclusive Exclusive

The forms beginning with the square bracket [ are unrelated to either the ArrayAccessExpression or the ArrayLiteralExpression, despite the visible similarities.

Despite appearing to be a primitive-type operators, Ecstasy has no primitive type system, and the input and output types of the operator are defined entirely by the types against which the operator executes. Specifically, the type of the expression a must have an unambiguously single best operator method for the operator .. (or ..<) with the default method name to() (or toExcluding()) , 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 expression groups to the left, so a .. b .. c is treated as (a .. b) .. c:

    RangeExpression:
        BitwiseExpression
        RangeExpression .. BitwiseExpression
        [ RangeExpression .. BitwiseExpression RangeTermination

    RangeTermination:
        ]
        )