digitalmars.D - Feature Request for 2.0: A way to implement MRV
- Downs (28/28) Aug 31 2007 -----BEGIN PGP SIGNED MESSAGE-----
- Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= (25/45) Aug 31 2007 votes++;
- Downs (23/45) Aug 31 2007 -----BEGIN PGP SIGNED MESSAGE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I don't think this much-longed-for feature (returning tuples) has been mentioned at DCon, and although I believe it would be highly useful, I realize it might be too hard to implement (though I can't exactly see how, if a half-working surrogate can be whipped up with half a page of 1.0 code). However, there is an easier way to achieve something sufficiently close as to be indistuingishable from "real" MRV. This way entails two closely related features: First, the redefinition of the comma operator to combine variables into a new type of tuple: a variable tuple, that being a set of variables combined under a common name, that a tuple can be assigned to. Second, and probably more important, the ability to implicit cast a struct to a tuple. This would allow us to extend the current solution of returning a TupleStruct to implicitly assigning that tuple struct to a group of variables without needing to store their pointers separately, as is currently done. Thanks for your consideration. - --downs -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG2FEwpEPJRr05fBERAvxWAJ9zcxnc/Gjn7MgKzAn3r0OQ1iNYzgCfUE8T h1qoVLIVijYAAdnCHDvpZjg= =oQjK -----END PGP SIGNATURE-----
Aug 31 2007
Downs wrote:I don't think this much-longed-for feature (returning tuples) has been mentioned at DCon, and although I believe it would be highly useful, I realize it might be too hard to implement (though I can't exactly see how, if a half-working surrogate can be whipped up with half a page of 1.0 code). However, there is an easier way to achieve something sufficiently close as to be indistuingishable from "real" MRV. This way entails two closely related features: First, the redefinition of the comma operator to combine variables into a new type of tuple: a variable tuple, that being a set of variables combined under a common name, that a tuple can be assigned to. Second, and probably more important, the ability to implicit cast a struct to a tuple. This would allow us to extend the current solution of returning a TupleStruct to implicitly assigning that tuple struct to a group of variables without needing to store their pointers separately, as is currently done.votes++; http://d.puremagic.com/issues/show_bug.cgi?id=1293 What makes me a bit worried is that the 'future of D' slides didn't say much about tuples. It's a natural extension to the current type system and improves the readability of code (and hopefully also deprecates those ad-hoc implementations with templates that actually are an order of magnitude slower than e.g. out parameters). It's also one area where D could "win" C++0x: tuple<int, int> get_coordinates_of_collision() { ... return make_tuple(x, y); } vs for example (int, int) get_coordinates_of_collision() { ... return x, y; } or tmp = x; x = y; y = tmp; vs x, y = y, x; Of course there are useful use cases for metaprogramming too.
Aug 31 2007
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jari-Matti Mäkelä wrote:Downs wrote:Thanks for your reply. I actually intended to ask for the ability to return tuples, but seeing how Walter feels about hard-to-implement features (and it has to be hard to implement, considering how useful it would be), I thought it better to ask for something easier to implement :) Naturally, enhanced tuple functionality at the cost of the not-much-needed comma operator would be infinitely preferable to merely improving the look-and-feel of what still is an ugly, struct-based pointer hack (MRV). Also, it has occured to me that the current function of the comma operator could be largely emulated by allowing the implicit conversion of a tuple to its last element, though if that is a good idea I cannot see. Ah well. Glad to hear your opinion, --downs -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG2LdkpEPJRr05fBERAgL/AKCc3tCe526Du5jm8TYa4OyuR38VPwCfaoWY RPlVD2s1t20VLo4K7lIi50Y= =uWK8 -----END PGP SIGNATURE-----First, the redefinition of the comma operator to combine variables into a new type of tuple: a variable tuple, that being a set of variables combined under a common name, that a tuple can be assigned to. Second, and probably more important, the ability to implicit cast a struct to a tuple. This would allow us to extend the current solution of returning a TupleStruct to implicitly assigning that tuple struct to a group of variables without needing to store their pointers separately, as is currently done.votes++; http://d.puremagic.com/issues/show_bug.cgi?id=1293 What makes me a bit worried is that the 'future of D' slides didn't say much about tuples. It's a natural extension to the current type system and improves the readability of code (and hopefully also deprecates those ad-hoc implementations with templates that actually are an order of magnitude slower than e.g. out parameters).
Aug 31 2007