Feature request: Optional, simplified syntax for simple contracts

Tyler Jameson Little beatgammit at gmail.com
Mon Jun 17 22:46:31 PDT 2013


Or the comma operator:

int x = (5, 3); // x is 3

Arrays:

int[] x = [3, 5];

Struct initializers:

struct t { int x, y };
auto z = t(3, 5);

Variable declarations:

int x = 5, y = 3;

I'm not sure which would be more idiomatic though... I'm leaning 
more towards commas though, to keep with the syntax of the 
initializers.

On Tuesday, 18 June 2013 at 05:28:07 UTC, Manu wrote:
> What about the argument list only 3 characters earlier?
>
>
> On 18 June 2013 15:16, Aleksandar Ruzicic 
> <aleksandar at ruzicic.info> wrote:
>
>> On Sunday, 16 June 2013 at 00:19:37 UTC, Manu wrote:
>>
>>> Super awesome idea! How about coma separated expressions to 
>>> perform
>>> multiple asserts?
>>>
>>> int func(int i, int j) in(i<5, j<10)
>>> {
>>>   return i + j;
>>> }
>>>
>>
>> I find use of comma inside of parentheses of a statement a bit 
>> unusual.
>> Correct me if I'm wrong but I don't think there is a single 
>> statement in D
>> that separates it's "parts" with a comma. It's always a 
>> semi-colon.
>>
>> So I think it should be:
>>
>> int func(int i, int j) in (i < 5; j < 10)
>> {
>>   return i + j;
>> }
>>
>>
>> But either comma or a semi-colon used as a separator, this is 
>> a really
>> nice syntactic sugar!



More information about the Digitalmars-d mailing list