Iota

John Colvin john.loughran.colvin at gmail.com
Sat Aug 6 13:38:47 UTC 2022


On Friday, 5 August 2022 at 15:31:18 UTC, Steven Schveighoffer 
wrote:
> 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

I think that deserves to be a guiding principle that motivates 
the design rather than a hard constraint. Imo nothing 
particularly bad happens here if iota is slightly more limited. I 
don’t really have an overall opinion on the “what should iota 
take” topic though.


More information about the Digitalmars-d mailing list