Iota

Steven Schveighoffer schveiguy at gmail.com
Fri Aug 5 15:31:18 UTC 2022


On 8/5/22 11:20 AM, Paul Backus wrote:
> On Friday, 5 August 2022 at 00:12:40 UTC, Steven Schveighoffer wrote:
>> As for the floating point thing, `foreach(i; 0.5 .. 7.6)` works, it 
>> should too for `iota`.
> 
> Argument by analogy like this is exactly what leads to generality creep 
> in the first place. You can just as easily say, "`for (auto i = start; i 
> < end; i++)` works for any type that overloads `<` and `++`, so 
> `iota(start, end)` should do the same", and then you end up with the 
> exact problem OP describes.

This isn't "argument by analogy". We have facilities built into the 
language which support an interface of "x to y". If iota is going to be 
the range equivalent, it should at least support that for all types that 
are supported for built-in range expressions.

A consistent API is important.

As for working with arbitrary types, I don't see a problem with it. If 
you define ++ on your type or += 1, and it doesn't mean the same as 
every other type that defines that, then it's on you for not following 
the conventions. D is a language which uses the introspected abilities 
of things to define whether they are compatible.

-Steve


More information about the Digitalmars-d mailing list