Iota

React react at react.js
Thu Aug 4 16:28:14 UTC 2022


I saw Ali's presentation on 'iota'.

I don't want to start another thread about why D has some issues, 
despite the ammunition provided by the simple fact that you need 
37 slides to explain a simple function. If you ask me, it is 
enough to provide iota for int and maybe long, the rest can be 
obtained using map & co if you insist. Maybe I want dates. Or 
fluffy bears.

What I want to highlight, it's the fact that iota seems flawed: 
it assumes that every type supporting increment operators will 
generate a nice, consecutive, ordered sequence of values.

Iota specialises on floating point values exactly because of the 
problem above, but assumes that *any* other type will nicely 
behave as long you can put a ++ near a value.

We can ignore the hypotetical situation in which someone will 
find an unusual usage of ++ (probably there is one person that 
never imagined that << can be used for console output), but we 
already have a candidate where iota will fail: CustomFloat from 
std.numeric.

```dlang
import std;
void main()
{
     CustomFloat!16 cb = 0.98;
     CustomFloat!16 ce = 1.98099;
     auto x = iota(cb, ce);
     foreach (y; x)
         writeln(y);
     //outputs 0.97998, 1.98047
     //outputs 0.97998 only if ce is 1.98098
}
```




More information about the Digitalmars-d mailing list