I dun a DIP, possibly the best DIP ever

Manu turkeyman at gmail.com
Wed Apr 22 15:17:19 UTC 2020


On Thu, Apr 23, 2020 at 12:55 AM Steven Schveighoffer via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On 4/22/20 9:45 AM, WebFreak001 wrote:
> > if
> > f(Items.x...)
> > works then what about
> > f(Items.MemberTup...) ?
>
> I would expect an expansion as Manu described, where the natural
> expansion of Items becomes Items[0].MemberTup, Items[1].MemberTup, ...
>

And of course, tuples in tuples auto-flatten according to current D
semantics.

However, there are some ambiguities that I'm not sure have been solved.
> What about templates that expand to tuples? Are the results of those
> tuples part of the ... expansion?
>
> What about:
>
> alias F!(T...) = AliasSeq!(T, T);
>
> Consider this expansion:
>
> alias t = AliasSeq!(int, char);
>
> F!(F!t))...
>

The expansion is evaluated from the leaf upwards... your question is valid,
and this is the case we've discussed quite a lot.
I'm basically just interested to run it and see what happens naturally!

Does it mean:
>
> F!(F!int), F!(F!char)) => int, int, int, int, char, char, char, char
>
> or does it mean:
>
> F!(AliasSeq!(int, char, int, char))... => int, char, int, char, int,
> char, int, char
>
> In other words, what if part of the expression *creates* a tuple. Is
> that the thing that gets expanded? I would have to say no, right?
> Otherwise, the whole thing might be expanded and the ... trivially applied.
>
> So that means things like (assuming G does something similar but not
> identical to F:
>
> F!(G!int)... would have to be the same as F!(G!int). This might be very
> confusing to someone expecting the inner tuple to be done before the
> expansion is considered.
>
> I don't know how to DIP-ify this idea. But it definitely needs to be
> talked about.


I have thought about how to discuss this in the DIP; I describe the
semantic, and what happens is what happens.
This will work, and something will happen... when we implement
TemplateInstance, we'll find out exactly what it is :P
What I will do is show what such a nested tuple does when code works in the
DIP to instantiate TemplateInstances.

It's basically the same thing as what you showed above with:
Items[0].MemberTup, Items[1].MemberTup, ...
In general, in D currently, nested tuples flatten. Evaluate from the leaf
upwards. Your answer will materialise.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200423/ea0adc7c/attachment.htm>


More information about the Digitalmars-d mailing list