<div dir="ltr"><div>2013/8/20 bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>></span><br></div><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"><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">So, std.typecons.Tuple _is not special_. You can define another Tuple struct in the same way.<br>

We should not define new syntax for the library utility std.typecons.Tuple.<br>
</blockquote>
<br></div>
With your idea is there a way to unpack a short array into variables? This is an handy operation I do often in Python:<br>
<br>
<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"><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">
<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">
s = "red blue"<br>
(a, b) = s.split()<br>
a<br>
</blockquote></blockquote></blockquote>
'red'<br>
<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"><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">
<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">
b<br>
</blockquote></blockquote></blockquote>
'blue'<br></blockquote><div><br></div>My position to such a feature is constant. We should not conflate tuple unpacking and array unpacking.<br><div><br></div><div>But, extending unpacking syntax mentioned in DIP32 might help it.</div>
<div><br></div><div>// Just an idea: extending DIP32 unpacking syntax<br></div><div>import std.typecons : tuple;<br></div><div>auto tup = tuple(1, tuple(2,3), [4,5]);</div><div>{ auto a, {b, c}, [d, e] } = tup;<br></div><div>
//{ auto a, [b, c], {d, e} } = tup;   // cause compile-time error</div><div>assert(a == 1);</div><div>assert(b == 2 && c == 3);<br></div><div>assert(d == 4 && e == 5);<br></div><div><br></div><div>However, array unpacking would require *hidden* runtime boundary check.</div>
<div>In above example code,</div><div><br></div><div>  assert(tup[2].length == 2);</div><div>  // or</div><div>  if (tup[2].length != 2) throw Error("Runtime mismatch of unpacking pattern");</div><div>  // or similar</div>
<div><br></div><div>should be implicitly inserted by compiler, even in @system code.</div><div>I'm not sure that is acceptable cost or not.</div><div><br></div><div>Kenji Hara</div></div></div></div>