<div dir="ltr">2013/3/29 Timon Gehr <span dir="ltr"><<a href="mailto:timon.gehr@gmx.ch" target="_blank">timon.gehr@gmx.ch</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><span style="color:rgb(34,34,34)">Looks quite nice. I especially like the {a, b} => ... thing.</span><br></div>
<br>
I think, however, that there are a handful serious flaws that need to be addressed:<div class="im"><br>0 "Inside tuple literal, ; never appears."<br></div>
{{;}} // a tuple not matching your specification<br>
</blockquote><div><br></div><div style>It will be parsed as:</div><div style>{ // tuple braces</div><div style> {;} // function literal braces</div><div>}</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
{{if(foo()){}}} // a non-tuple matching your specification<br></blockquote><div><br></div><div style>{ // tuple braces</div><div style> { // function literal braces</div><div style> if (foo()){} // "if" always appears in statement scope</div>
<div style> }</div><div>}</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
1 "Note: Cannot swap values by tuple assignment."<br>
IMO a no-go. The syntax is too accessible to introduce this kind of<br>
pitfall.<br></blockquote><div><br></div><div style>Allowing value swap in tuple assignment will make language complex. I can't agree with it.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2 "// Error: cannnot use $ inside a function literal"<br>
That's a DMD-ism presumably stemming from laziness during "fixing" of<br>
an ICE/wrong code bug or something. I'd hate to carry this over to<br>
the spec. Don't rely on it. The disambiguation is arbitrary, but may<br>
be necessary. (It's not like it is a case actually occurring in real<br>
code.)<br>
<br>
3 Unpacking / pattern matching is underspecified.<br>
- Do patterns nest?<br></blockquote><div><br></div><div style>I think it should be allowed.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
- Which right-hand sides are allowed with which semantics?<br></blockquote><div><br></div><div style>Whether it is a pattern or a tuple-literal, is distinguished by their appeared locations.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
- Which left-hand sides are allowed with which semantics?<br>
eg, what about:<br>
ref int foo() { ... }<br>
{ foo(), foo() } = {1, 2};<br></blockquote><div><br></div><div style>It will be lowered to:</div><div style>// { foo(), foo() } = {1, 2};<br></div><div style>foo() = 1;</div><div style>foo() = 2;</div><div> <br></div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
4 There is no way to capture the part matched by "..."<br></blockquote><div><br></div><div style>I think this should be allowed.</div><div><br></div><div>auto {x, r...} = tup;</div><div>// Lowered to:</div><div>
// auto x = tup[0];</div><div>// auto r = tup[1..$]</div><div><br></div><div>`...` is very consistent token for this purpose.</div><div><br></div><div>template X(T...) {}</div><div>alias x = X!(int, long); // T captures {int, long}</div>
<div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
5 .expand (or similar) property is missing.<br></blockquote><div><br></div><div style>Use tup[]. It is already exists.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
6 Relation to {a: 2, b: 3}-style struct literals not explained.<br></blockquote><div><br></div><div><div>I am skeptical of the necessity of tuple literal with named fields.</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
7 Tuple unpacking for template parameters not mentioned.<br>
<br>
<br>
Is there a migration path for Phobos tuples planned?<br>
<br>
Eg. template Tuple(T...){ alias Tuple = {T}; }<br>
(field spec parsing left out for illustration)<br>
</blockquote></div><br></div><div class="gmail_extra" style>Kenji Hara</div></div>