A different tuple syntax

Timothee Cour thelastmammoth at gmail.com
Thu May 30 20:53:14 PDT 2013


>
> Regarding the syntax to unpack tuples into single variables, Kenji Hara
> wrote a DIP (http://wiki.dlang.org/DIP32 ) denoting tuples with the
> univesal syntax {...}, but people have found some problems in it.


Do you have a reference to the post(s) mentioning the problems with Kenji's
proposed syntax?
Thanks


On Thu, May 30, 2013 at 5:29 AM, bearophile <bearophileHUGS at lycos.com>wrote:

> Regarding the syntax to unpack tuples into single variables, Kenji Hara
> wrote a DIP (http://wiki.dlang.org/DIP32 ) denoting tuples with the
> univesal syntax {...}, but people have found some problems in it.
>
> (I think Kenji didn't update that DIP with all the small improvements we
> suggested in that thread, so they risk getting lost.)
>
> Maybe one solution is to use a "tup(...)" syntax, it's a bit heavy, but
> it's clear and maybe it has no corner cases:
>
> tup(int, string) tup = tup(1, "hi");
> foreach (Float; tup(float, double, real)) { ... }
> auto tup(x, y) = tup(1, "hi");
> tup(auto x, y) = tup(1, "hi");
> tup(int x, string y) = tup(1, "hi");
> foreach (i, const tup(x, y); [tup(1,2), tup(3,4), tup(5,6), ...]) {
> void foo(tup(int, string name), string msg);
> (tup(A a, B b)) => a + b;
> switch (tup) { case tup(1, 2): ... }
>
>
> This is not very elegant, "tup" becomes a new keyword and generally I
> don't like such strong abbreviations, like the ones used in Rust language,
> but "tuple()" clashes with the library-defined ones, and it's even more
> wordy if you want to define an array of them:
>
> [tuple(1,2), tuple(3,4), tuple(5,6), ...]
>
> Bye,
> bearophile
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130530/3450eae9/attachment.html>


More information about the Digitalmars-d mailing list