Iota

H. S. Teoh hsteoh at qfbox.info
Thu Aug 4 22:36:57 UTC 2022


On Thu, Aug 04, 2022 at 09:31:02PM +0000, Paul Backus via Digitalmars-d wrote:
> On Thursday, 4 August 2022 at 19:06:43 UTC, H. S. Teoh wrote:
> > After thinking about this, I think in its barest essentials, the
> > only version of iota we need is the one that takes a single int
> > argument, and that generates that many numbers, starting from 0.
> > Everything else can be built on top of this with other existing
> > library functions.
> 
> Strictly speaking, you don't even need that; all you need is a range
> that generates the natural numbers, and you can write
> 
>     naturals.take(n)
> 
> ...to get the equivalent of iota(n).

You don't even need a library prefab for that. Just do:

	auto r = recurrence!"a[n-1] + 1"(0); // equivalent to `naturals`

You can then tack on .take(n) or whatever else to get what you want.

But having to write this every time you need a number range is rather
annoying. So there's *some* role here for iota to fill.


> That said, I don't think you have to aim for total minimalism to avoid
> generality creep here. You just need to know what iota's purpose for
> inclusion is, so that you can say "no, that's not iota's job; use
> generate/recurrence/something else instead" when someone proposes an
> overly-general enhancement.
>
> I wonder if perhaps iota was vulnerable to generality creep in part
> because it was copied into Phobos from C++'s STL, without a lot of
> thought given to what specific purpose it served in relation to the
> rest of the library.

Perhaps.  But the question now is, where do we go from here?  How do we
improve what we currently have?


T

-- 
War doesn't prove who's right, just who's left. -- BSD Games' Fortune


More information about the Digitalmars-d mailing list