DIP58: ".." as a Binary Operator
Mason McGill
mmcgill at caltech.edu
Mon Mar 17 16:01:52 PDT 2014
On Monday, 17 March 2014 at 22:26:05 UTC, H. S. Teoh wrote:
> On Mon, Mar 17, 2014 at 11:16:12PM +0100, Robert Schadek wrote:
>> replace .. with : to make lexing easier, please
>
> auto b = arr[(someCondition) ? w:x : y:z];
>
> :-(
>
>
> T
Julia has both the ternary conditional and ":" as an operator.
In practice, they rarely come up in the same expressions, and
when they do, parentheses are an easy solution.
auto b = arr[someCondition ? (w:x) : (y:z)];
However, I think it's worth mentioning that--unless I've missed
something--DIP58 doesn't introduce any parsing issues that aren't
already present inside a SliceExpression:
struct S { void opSlice(real a, real b) {} }
S s;
s[5. .. .5]; // Compiles.
s[5... .5]; // Error.
s[5. ...5]; // Error.
s[5....5]; // Error.
This seems like reasonable behavior, in my opinion.
It seems like ":" and ".." both have their pros and cons, but
".." allows backwards compatibility to be preserved, and I don't
see how ":" can be worked in elegantly without breaking lots of
code.
More information about the Digitalmars-d
mailing list