http://d.puremagic.com/issues/show_bug.cgi?id=4579



--- Comment #1 from bearophile_h...@eml.cc 2010-09-16 19:24:57 PDT ---
'auto' too may be supported:

void main() {
    (auto fc, auto fa, auto fm) = getTimes("filename");
}

Or even:

void main() {
    auto (fc, fa, fm) = getTimes("filename");
}


An unpacking syntax for Tuples is useful to replace the very similar zip() and
lockstep():


import std.algorithm, std.stdio, std.range;
void main() {
    foreach (p; zip([1, 2, 3], "abcd"))
        writeln(p._0, " ", p.length, " ", p._1);
    writeln();
    foreach (i, a, b; lockstep([1, 2, 3], "abcd"))
        writeln(i, " ", a, " ", b);
}


with a single zip() that may be used for both situations:

import std.algorithm, std.stdio, std.range;
void main() {
    foreach (p; zip([1, 2, 3], "abcd"))
        writeln(p[0], " ", p[1]);
    writeln();
    foreach ((a, b); zip([1, 2, 3], "abcd"))
        writeln(a, " ", b);
}


As in Python:

for p in zip([1, 2, 3], "abcd"):
    print p[0], p[1]
print
for (a, b) in zip([1, 2, 3], "abcd"):
    print a, b


(The zip() is a very commonly useful higher order function.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to