DIP58: ".." as a Binary Operator

Mason McGill mmcgill at caltech.edu
Mon Mar 17 13:30:55 PDT 2014


On Monday, 17 March 2014 at 19:58:40 UTC, H. S. Teoh wrote:
> On Mon, Mar 17, 2014 at 07:07:44PM +0000, Mason McGill wrote:
>> On Monday, 17 March 2014 at 17:41:16 UTC, bearophile wrote:
>> >Mason McGill:
>> >
>> >>http://wiki.dlang.org/DIP58
>> >
>> >Seems nice.
>> 
>> Thanks.  There are a few awkward parts to maintain 
>> compatibility,
>> but that seems to be the only way to go.
>> 
>> >But the syntax a..b..step is not very nice.
>> 
>> Do you not like the order?  Because it was actually a..step..b 
>> (like
>> MATLAB/Julia, not like Python).  Or do you not like the 
>> "verbosity"
>> of all those dots (a:step:b would be better)?  Or is it the
>> readability issues if floating point literals were mixed in 
>> there?
> [...]
>
> Not speaking for bearophile here, but I don't like using .. to 
> mean two
> different things (endpoints vs. step).

That's fair.  The rationale was the precedent set by MATLAB, 
Python, and Julia.  One of the benefits of making (a..b) an 
expression is the ability to define functions that operate on the 
result.

Examples:
---------
stride(a..b, 2);
(a..b).by(2);    // I happen to like this spelling.

(a..b).reverse;

(a..b).square; // To define a 2D grid.

(a..b).window(c); // c-length windows of a..b.
                   // Useful for indexing video frames
                   // in a multi-frame analysis.



More information about the Digitalmars-d mailing list