<div dir="ltr"><div dir="ltr">On Thu, Apr 23, 2020 at 2:10 AM Steven Schveighoffer via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 4/22/20 11:17 AM, Manu wrote:<br>
> <br>
> I have thought about how to discuss this in the DIP; I describe the <br>
> semantic, and what happens is what happens.<br>
> This will work, and something will happen... when we implement <br>
> TemplateInstance, we'll find out exactly what it is :P<br>
> What I will do is show what such a nested tuple does when code works in <br>
> the DIP to instantiate TemplateInstances.<br>
> <br>
> It's basically the same thing as what you showed above with: <br>
> Items[0].MemberTup, Items[1].MemberTup, ...<br>
> In general, in D currently, nested tuples flatten. Evaluate from the <br>
> leaf upwards. Your answer will materialise.<br>
<br>
I think this is more complicated than the MemberTup thing. By inference <br>
of the name, MemberTup is a tuple, but only defined in the context of <br>
the expanded items. There aren't any tuples for the compiler to expand <br>
in there.<br>
<br>
A template that returns a tuple based on it's parameters is a tuple with <br>
or without expansion.<br>
<br>
F!(F!t)) is valid. It's going to return int, char, int, char, int, char, <br>
int, char<br>
<br>
F!(F!t))... what does this do?<br>
<br>
Saying "let's see what happens" is not a good way to create a DIP. We <br>
have enough of "design by implementation" in D.<br></blockquote><div><br></div><div>I only say that because;</div><div>1. It was 2am, and I had to think it through.<br>2. It will just apply the specification I've described in the DIP, absent of special-cases.</div><div><br></div><div>I expect it will do this: </div><div><br></div><div>F!(F!t)... =></div><div><br></div><div>expand for `t` (at leaf of tree):</div><div>F!( (F!t[0], 

F!t[1]) )  ~=  

F!( (F!int, 

F!char) )  =><br></div><div><br></div><div>Spec does not say it will NOW evaluate the template and operate on the result, it deals with the expression as stated.</div><div>If it didn't behave that way, it would be very easy to lead to recursive expansion expressions, and impossible to reason about the expansion when it disappears inside of code that's defined elsewhere.</div><div><br></div><div>Expansion applies to the expression as-written.</div><div><br></div><div>So, take the tuple from expanding `t`, and expand the next level:</div><div><br></div><div>( F!( (F!int, 

F!char)[0] ), F!( (F!int, 

F!char)[1]

) )  ~=   

( F!( F!int ), F!( F!char ) )

</div><div><br></div><div>I think that's all the tuples in the expression, now semantic will run as usual, and it will resolve those templates:</div><div><br></div><div><div>Resolve inner F:</div><div><br></div><div><div>( F!(int, int), F!(char, char) )</div><div></div></div><div></div></div><div><br></div><div>And outer F:</div><div><br></div><div><div><div><div>( int, int, int, int, char, char, char, char )</div><div></div></div><div></div></div><div></div></div><div><br></div><div>That's the expansion I would expect from that expression. So, I guess the point you want to determine is that *evaluating* templates is NOT part of tuple expansion.</div><div>Template resolution will follow normally in semantic. The expansion applies to the expression as written, and I think that's the only possible definition, otherwise the expansion starts to recurse inside of implementation code which is defined elsewhere.</div><div><br></div><div>I think that expansion is actually reasonable and 'easy' to understand. There's nothing unexpected about application of the stated rules.<br></div><div>Of course, I would suggest not writing code like this, unless it's really clear to the reader what your intent was. There's a million-and-one ways to write obscure code that does something, but doesn't really help the reader along the way; this expression is one such thing.</div></div></div>