digitalmars.D - Re: The empty statement ";" - when is it useful?
- Arthur Lloyd <via google.com> Jul 29 2009
- "Adam D. Ruppe" <destructionator gmail.com> Jul 29 2009
- Arthur Lloyd <via google.com> Jul 29 2009
- "Adam D. Ruppe" <destructionator gmail.com> Jul 29 2009
Andrei Alexandrescu Wrote:I think he just means that the comma operator is not a strategic advantage for automated code generation.
If the comma operator does not offer a strategic advantage, will it be deprecated in favor of something that python and ruby do. I've many times fallen into a trap when initializing multidim arrays, like: # int[][] a; # a.length = 3,4; Also # struct coordinates { int x; int y; } # coordinates getThem() { coordinates c; c.x = 4; c.y = 5; return c; } # auto a = getThem(); seems very verbose when in a scripting language I can do: # def getThem() { (4, 5) } # a = getThem Does this work, if the comma builds a tuple instead of a sequence?
Jul 29 2009
On Wed, Jul 29, 2009 at 10:29:51AM -0400, Arthur Lloyd wrote:Also # struct coordinates { int x; int y; } # coordinates getThem() { coordinates c; c.x = 4; c.y = 5; return c; } # auto a = getThem(); seems very verbose when in a scripting language I can do:
It also seems very verbose in D where you can do: auto getThem() { return tuple(4,5); } auto a = getThem; -- Adam D. Ruppe http://arsdnet.net
Jul 29 2009
Adam D. Ruppe Wrote:On Wed, Jul 29, 2009 at 10:29:51AM -0400, Arthur Lloyd wrote:Also # struct coordinates { int x; int y; } # coordinates getThem() { coordinates c; c.x = 4; c.y = 5; return c; } # auto a = getThem(); seems very verbose when in a scripting language I can do:
It also seems very verbose in D where you can do: auto getThem() { return tuple(4,5); } auto a = getThem;
No, that looks quite good. Is the tuple() a D2 feature? D1/Tango doesn't seem to have it? Why not even go so far as to make the tuple keyword completely optional?
Jul 29 2009
On Wed, Jul 29, 2009 at 11:00:13AM -0400, Arthur Lloyd wrote:No, that looks quite good. Is the tuple() a D2 feature? D1/Tango doesn't seem to have it? Why not even go so far as to make the tuple keyword completely optional?
It is part of phobos 2, in std.typecons. (so you'd actually need to stick import std.typecons; at the top of the file to get that to compile.) Since it is a library solution, there is no actual keyword here, nor can it do the length thing you wanted. But, it does cover the other case quite well, without needing to change the language at all. -- Adam D. Ruppe http://arsdnet.net
Jul 29 2009