I dun a DIP, possibly the best DIP ever
Steven Schveighoffer
schveiguy at gmail.com
Fri Apr 24 17:10:16 UTC 2020
On 4/24/20 4:03 AM, Walter Bright wrote:
> On a philosophical point, I am generally opposed to adding syntax just
> to support some unusual cases. I am sure one could come up with examples
> where the .... syntax won't work, too. For example, could it work with
> creating a new tuple out of every third tuple member? I'm not looking
> for a specific answer, but for a meta answer of "should we support these
> operations at all with special syntax"?
The point of this is to reduce the amount of "trivial" templates. Every
time a template is instantiated, it consumes memory in the compiler, it
creates more stuff to manage in the symbol tables, and because templates
have to "be the same" for every instantiation, you have weird paradoxes.
One of the fundamental problems with template power in D is that in
order to operate on lists, you need a functional-style recurse or divide
and conquer, which multiplies the number of templates needed by possibly
hundreds or thousands. This takes time, resources, and can result in
things that don't compile or are extremely slow to compile.
What I think this proposal does is to remove an entire class of
recursive templates, and replaces them with simple loops that the
compiler can execute blindfolded with 4 cores tied behind its back with
ease, faster than the template expansions required by e.g. staticMap.
I think the ellipsis version is superior simply because it has more
expressive power (see my posts elsewhere). An ideal proposal would allow
all things to be handled within one expression, but the ellipsis is
better in that it is unambiguous and does not break code.
And actually, with a staticIota-like thing you could do every third
tuple member quite easily.
alias everyThird = staticIota!(2, Tup.length, 3); // start, end, step
alias everyThirdMember = (Tup...[everyThird])...;
staticIota is kind of another primitive that is super-useful, and would
be easy for the compiler to provide. But could be done via CTFE as well.
-Steve
More information about the Digitalmars-d
mailing list