DIP 1009--Improve Contract Usability--Preliminary Review Round 1

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 22 17:17:23 PDT 2017


On 6/22/17 5:56 PM, Timon Gehr wrote:
> On 22.06.2017 23:51, MysticZach wrote:
>> On Thursday, 22 June 2017 at 21:41:55 UTC, MysticZach wrote:
>>>> The whole double parentheses is a bit ugly to me. Is there any 
>>>> problem with
>>>> out(return > 0)
>>>> instead of
>>>> out(r) (r > 0)
>>
>> I'm sorry, I didn't read closely. I think that's just asking for 
>> trouble, wanting to use `return` as an identifier. Timon found a 
>> specific reason why, but in general contextual keywords are frowned 
>> upon for precisely this type of ambiguity in the meaning of the code.
> 
> 
> (It's not a contextual keyword. A contextual keyword is an identifier 
> that is reserved in some contexts but not others.)

We can call that contextual "keyword" result. Doesn't have to be a 
keyword, just the implied return value symbol name.

It would work fine on it's own. My concern is that out(result > 4) 
matches the grammar for the declaration (a bit) for the declaration of 
the out contract today.

If we allow not supplying the body (do) keyword, then it's almost 
exactly the same. In fact, if you are just asserting the result, then:

int foo()
out(result)
{
}

what does this mean? Does it mean assert(result) on the out contract, or 
this is the old form of out?

If we didn't have contract syntax already, and many existing code bases 
that use it, I'd say this would be the way to go.

-Steve


More information about the Digitalmars-d mailing list