www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Comma expression as tuple operator [was Tuples, C#, Java, language

reply justme <justme somewhere.net> writes:
grauzone Wrote:

 BCS wrote:
 Hello justme,
 
 bearophile Wrote:


 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
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?
Why not make the programmer write tuple[$-1] instead? i = (j += i, i*2 + j)[$-1]; There's no reason to keep the current comma operator.
It's his language, after all. I'm sure there is a good reason why the old C style comma expression is still there. Maybe it's good for generating parsers with some software tools?
Dec 29 2009
parent reply Don <nospam nospam.com> writes:
justme wrote:
 grauzone Wrote:
 
 BCS wrote:
 Hello justme,

 bearophile Wrote:


 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
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?
Why not make the programmer write tuple[$-1] instead? i = (j += i, i*2 + j)[$-1]; There's no reason to keep the current comma operator.
It's his language, after all. I'm sure there is a good reason why the old C style comma expression is still there. Maybe it's good for generating parsers with some software tools?
I doubt it. The thing is, in Walter's world (which I've been living in for the fast six months), comma is really important. It's used everywhere inside the compiler. Interestingly, however, the compiler's comma operator is not the same as the one in D! In the compiler internal comma, you can have declarations: int x = (int y=foo(); y*y); And also, the compiler can generate unique variable names, which makes it much more useful: it's basically a way to generate a simple function which is guaranteed to be inlined. So I think, that Walter's opinion is based on strong personal experience; but I don't think that experience is actually relevant.
Dec 29 2009
parent reply "Denis Koroskin" <2korden gmail.com> writes:
On Wed, 30 Dec 2009 09:29:22 +0300, Don <nospam nospam.com> wrote:

 justme wrote:
 grauzone Wrote:

 BCS wrote:
 Hello justme,

 bearophile Wrote:


 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
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?
Why not make the programmer write tuple[$-1] instead? i = (j += i, i*2 + j)[$-1]; There's no reason to keep the current comma operator.
It's his language, after all. I'm sure there is a good reason why the old C style comma expression is still there. Maybe it's good for generating parsers with some software tools?
I doubt it. The thing is, in Walter's world (which I've been living in for the fast six months), comma is really important. It's used everywhere inside the compiler. Interestingly, however, the compiler's comma operator is not the same as the one in D! In the compiler internal comma, you can have declarations: int x = (int y=foo(); y*y); And also, the compiler can generate unique variable names, which makes it much more useful: it's basically a way to generate a simple function which is guaranteed to be inlined. So I think, that Walter's opinion is based on strong personal experience; but I don't think that experience is actually relevant.
I believe he could replace comma operator with AOC (Any Other Character) operator: just replace comma with "something" which is not yet used. Choose some fancy-looking Unicode character that no one will really use but the compiler itself to generate intermediate code.
Dec 30 2009
next sibling parent justme <justme somewhere.net> writes:
Denis Koroskin Wrote:

 I believe he could replace comma operator with AOC (Any Other Character)  
 operator: just replace comma with "something" which is not yet used.  
 Choose some fancy-looking Unicode character that no one will really use  
 but the compiler itself to generate intermediate code.
Maybe that happens in D3. I'm already eagerly waiting for it.
Dec 30 2009
prev sibling parent BCS <none anon.com> writes:
 I believe he could replace comma operator with AOC (Any Other
 Character)  operator: just replace comma with "something" which is not
 yet used.  Choose some fancy-looking Unicode character that no one
 will really use  but the compiler itself to generate intermediate
 code.
If you don't expect it to be written in code, then there is no reason at all to even defined what char is used because the compiler doesn't internally handle code as text. You can just define it as an AST node and be done with it.
Dec 30 2009