DIP19: Remove comma operator from D and provision better syntactic support for tuples

foobar foo at bar.com
Sun Sep 23 14:10:29 PDT 2012


On Sunday, 23 September 2012 at 21:00:39 UTC, foobar wrote:
> On Sunday, 23 September 2012 at 20:57:48 UTC, foobar wrote:
>> On Sunday, 23 September 2012 at 20:39:38 UTC, Andrei 
>> Alexandrescu wrote:
>>> I discussed this with Walter, and we concluded that we could 
>>> deprecate the comma operator if it helps tuples. So I started 
>>> with this:
>>>
>>> http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP19
>>>
>>> Unfortunately, I started much cockier than I ended. The 
>>> analysis in there fails to construct a case even half strong 
>>> that deprecating the comma operator could significantly help 
>>> tuples. Well it essentially concludes that tuples are mostly 
>>> fine as they are, and attempts to embellish them 
>>> syntactically are marred with unexpected problems. 
>>> Nevertheless, I sure have missed aspects all over, so 
>>> contributions are appreciated.
>>>
>>>
>>> Thanks,
>>>
>>> Andrei
>>
>>
>
> Yay! vote += infinity
>
> Regarding specifics,
> I'd argue that (int) should be a perfectly valid construct. I
> don't see what's confusing about that. I also am opposed to the
> idea to limit tuples to 2 or more elements. On the contrary, I
> root for the clean semantics of having a proper unit type
> represented as () instead of the horrible C semantics of the
> 'void' type. Just make void an alias to () for backwards
> compatibility.
> Also, why the need to special case the for loop? the increment
> part can be a regular tuple since the for loop doesn't assign
> the value of the expression.
> for (int i, j; cond; i++, j++) {}
>
> I'd suggest looking at functional implementations such as ML or 
> Haskel for more inspiration.

urg.. .Sorry for the double posting..

Also, I want to add that type declarations should be changed from 
statements to expressions so that we could do:
auto tup = (3, "hello");
(int num, string s) = tup; // num == 3, s == "hello"


More information about the Digitalmars-d mailing list