<div class="gmail_quote">On Wed, May 23, 2012 at 3:00 PM, Dmitry Olshansky <span dir="ltr"><<a href="mailto:dmitry.olsh@gmail.com" target="_blank">dmitry.olsh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
My proposal the is following using a.{ ... } syntax to unpack:<br>
</blockquote>
<br>
In short:<br>
I think the original proposal of<br>
 <a href="https://github.com/D-Programming-Language/dmd/pull/341" target="_blank">https://github.com/D-<u></u>Programming-Language/dmd/pull/<u></u>341</a><br>
could be enhanced with introduction  <expr>.{ <spec> } selectors allowing to cherry pick fields and array elements easily.<br>
<br>
If we go with Kenji's proposal, this can be treated as cool way to construct tuple by applying selector to an expression.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Record r = ...;<br>
auto a, b, c = r.{ first, third, some_other_field };//a=r.first,<br>
b=r.third, c = r.some_other_field<br>
<br>
With tuples:<br>
auto a, b, c = r.{};//a = r[0], b = r[1], c = r[2]<br>
auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4]<br>
<br>
With arrays, exactly the same as tuples:<br>
auto a, b, c = r.{0, 2, 4}; // a = r[0], b = r[2], c = r[4]<br>
<br>
Tuples with named fields can work in both named and indexed "modes".<br>
Indexes must be a valid CT-constant.<br>
<br>
More over we then have nested unpacking syntax:<br>
<br>
auto x, i = r.{ something, nested_thing.{ precious_secret} };<br>
//x = r.something, i = r.nested_thing.precious_secret<br>
<br>
The same with just about any expression:<br>
<br>
auto point = (a+b()).{ x, y };<br>
//even better - point is now Tuple!(<type of x>, "x", <type of y>, "y")<br>
<br>
<br>
Summarizing it all.<br>
<br>
For single left-side variable the rewrite of expression is:<br>
auto __tmp = <expr>, tuple(__tmp.<spec_1>, __tmp.<spec_2>);<br>
<br>
For multiple left-side the rewrite of the whole statement is:<br>
auto __tmp = <expr>, __1st = __tmp.<spec_1>, __2nd = __tmp.<spec_2> ...;<br>
<br>
<br>
Where spec_x is constructed from:<br>
<br>
root_0.{ ... root_1.{ .. root_n.{ var_x ... } ... } ... }<br>
<br>
as<br>
root_0.<...>.root_n.var_x<br>
<br>
If some var_k/root_k happens to be CT index the rewrite is<br>
...[root_k]... or ...[var_k]..<br>
<br>
<br>
So far I think it's the closest thing to multiple value return with<br>
natural syntax. It also brings concise syntax for a common general<br>
propose task.<br>
<br><span class="HOEnZb"><font color="#888888">
</font></span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
<br>
<br>
<br>
-- <br>
Dmitry Olshansky<br>
</font></span></blockquote></div><br>This is awesome! I really like it!<br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>