Comma expression as tuple operator [was Tuples, C#, Java, language design]

Johan Granberg lijat.meREM at OVEgmail.com
Wed Dec 30 05:21:58 PST 2009


BCS wrote:

> Hello justme,
> 
>> bearophile Wrote:
>> 
>>> C# will probably not follow the route of stagnation of Java for some
>>> more time, thanks to Mono too. I don't like that string interpolation
>>> syntax because it looks unsafe, and that design of tuples can be
>>> improved, but they are listening to programmes (even if they risk
>>> creating a mudball language):
>>> 
>>> http://www.infoq.com/news/2009/12/Mono-CSharp-Ex
>>> 
>>> More on those tuples:
>>> http://tirania.org/blog/archive/2009/Dec-23.html
>>> Eventually it will be quite useful to have some very well designed
>>> multi-return support in D (like those tuples, but better).
>>> 
>> Doesn't D2 already have tuples in Phobos. D has the comma operator
>> which C# doesn't so such syntax is not possible in D, me thinks.
>> 
> 
> A though on the comma operator: if the comma operator were defined to give
> a tuple type and be implicitly castable to any suffix of it's self, then
> you could get both the comma expression usage that Walter wants as well as
> all the fun things that tuple expressions give.
> 
> int i = 1, j = 2;
> 
> (i, j) = (j, i); // swap
> 
> i = (j+= i, i*2 + j); // first expression gets evaluated and dropped.
> 
> Thoughts?

I have had the same idea and thinking about it I have not found any problems
with it. So I would get hapy if it was implementet. When tupples where
first introduced in D the ovious problems with them was the auto flattening
and lack of literal syntax, fixing that would probably make using tuoples
much nicer. (Allowing things like multiple return value as used in matlab)



More information about the Digitalmars-d mailing list