<div dir="ltr"><div dir="ltr">On Thu, Apr 23, 2020 at 2:50 PM 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 8:13 PM, Manu wrote:<br>
> On Thu, Apr 23, 2020 at 2:10 AM Steven Schveighoffer via Digitalmars-d <br>
> <<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a> <mailto:<a href="mailto:digitalmars-d@puremagic." target="_blank">digitalmars-d@puremagic.</a>.com>> wrote:<br>
> <br>
> 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<br>
> 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<br>
> with<br>
> or without expansion.<br>
> <br>
> F!(F!t)) is valid. It's going to return int, char, int, char, int,<br>
> char,<br>
> int, char<br>
> <br>
> F!(F!t))... what does this do?<br>
> <br>
> I expect it will do this:<br>
> <br>
> F!(F!t)... =><br>
> <br>
> expand for `t` (at leaf of tree):<br>
> F!( (F!t[0], F!t[1]) ) ~= F!( (F!int, F!char) ) =><br>
<br>
OK, that is what I thought too (that is the most useful), but this needs <br>
to be explicit in the DIP.<br>
<br>
Remember that templates can also be tuples too, so when it says " for <br>
any tuples present in the expression tree", it reads ambiguous.<br>
<br>
I will bring up again something like this, which someone might expect to <br>
work:<br>
<br>
alias G(T) = const(T);<br>
<br>
alias F(T) = AliasSeq!(T, T);<br>
<br>
alias f = F!(int);<br>
G!(f)...; // seems cool to me<br>
G!(F!int)...; // compiler error or works?<br>
G!(AliasSeq!(int, char))...; // error or works?<br>
<br>
> Spec does not say it will NOW evaluate the template and operate on the <br>
> result, it deals with the expression as stated.<br>
<br>
I'm not expecting multiple expansions, but one has to remember that D is <br>
full of templates that create tuples, so the DIP has to say at what <br>
point "these tuples are generated and considered before the expansion" <br>
and "these are not". It seems to me you are saying only tuples that <br>
exist BEFORE the expression are considered. Something like that should <br>
be in the DIP, with appropriate examples.<br></blockquote><div><br></div><div>Yes, these are very good points. Thanks for spelling this out clearly.</div><div><br></div><div></div><div>In the event you want the behaviour where the template resolution is expanded, I reckon people would expect this is the natural solution:</div><div> alias Tup = TupleFromTemplate!(Instantiation, Args);<br></div><div> (Tup <a class="gmail_plusreply" id="plusReplyChip-1">+</a> expr)...<br></div><div><br></div><div>In this expression, `Tup` would expand, because the instantiation that created the tuple is not involved in the expression being expanded.</div><div>I have to double-check, but I expect that's precisely how the code works naturally with no intervention. AliasSeq!() itself depends on this behaviour to work right now in our unittests.</div><div><br></div><div>So, if you find yourself in a situation where you want to expand a tuple into a template instantiation, and that instantiation resolves to a tuple which you want to further expand, you just need to break it into 2 lines. That will also have the nice side-effect of being much clearer to read.</div><div><div></div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> That's the expansion I would expect from that expression. So, I guess <br>
> the point you want to determine is that *evaluating* templates is NOT <br>
> part of tuple expansion.<br>
<br>
A good way to say it, but still needs examples in the DIP to clarify. To <br>
elaborate, you might say:<br>
<br>
"expansion is performed only on tuples represented by symbols in the <br>
expression. All template instantiations that generate tuples are <br>
performed after expansion is finished."<br></blockquote><div><br></div><div>Yes, this reads well, thanks again. I was struggling to imagine simple language to describe this behaviour.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> I think that expansion is actually reasonable and 'easy' to understand. <br>
> There's nothing unexpected about application of the stated rules.<br>
> Of course, I would suggest not writing code like this, unless it's <br>
> really clear to the reader what your intent was. There's a <br>
> million-and-one ways to write obscure code that does something, but <br>
> doesn't really help the reader along the way; this expression is one <br>
> such thing.<br>
<br>
It's easy to understand, but it's also easy to expect the compiler to <br>
understand what you were thinking when you wrote:<br>
<br>
foo!(AliasSeq!(int, char))...<br>
<br>
instead of the (required) long form:<br>
<br>
alias args = AliasSeq!(int, char);<br>
foo!(args)...<br>
<br>
proper tuples would make this much less painful...<br></blockquote><div><br></div><div>You're exactly correct, the first instantiation needs to be broken out to a separate line.</div><div><div>Exactly. I hope this feature might motivate renewed interest in first-class tuples, and that would improve this situation.</div><div></div></div></div></div>