DIP 1009--Improve Contract Usability--Preliminary Review Round 1
via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jun 25 08:46:12 PDT 2017
On Sunday, 25 June 2017 at 12:10:02 UTC, Timon Gehr wrote:
> On 25.06.2017 13:37, Andrei Alexandrescu wrote:
>> On 6/23/17 6:52 PM, jmh530 wrote:
>>> On Friday, 23 June 2017 at 17:31:15 UTC, MysticZach wrote:
>>>>
>>>> OutExpression:
>>>> out ( ; AssertParameters )
>>>> out ( Identifier ; AssertParameters )
>>>
>>> Why not?
>>>
>>> OutExpression:
>>> out ( AssertParameters )
>>> out ( Identifier ; AssertParameters )
>>
>> The path of least resistance is to use existing language
>> constructs, i.e.
>>
>> out result => assert(result > 0)
>>
>>
>> Andrei
> This would face quite some resistance, on the following grounds:
>
> out(result){ assert(result > 0); } // exists
>
> out result => assert(result > 0) // more of the same
>
> out(result; result > 0) // better
out result => result > 0 // not much worse
out __result > 0 // even better (__result works at least since
[0])
I suggested adding a shorter / better looking contextual keyword -
`result` - a while ago [1]:
---
out result > 0 // perhaps the best
---
And before that I proposed this:
---
// `Unqual` is not needed for `isNumeric` strictly speaking,
// it's used here only for illustration purposes.
T sqrt(T)(T n)
if Unqual!T U: isNumeric!U || is(U == BigInt)
in n >= 0
out (result) result * result == n
{
//Implementation
}
---
(I think as a reply to you in the DIP1003 thread)
I'm wondering if `out result > 0` (or if not `out __result > 0`)
would be too much of a stretch for the language grammar.
[0]:
https://github.com/dlang/dmd/commit/620acd53b63bfede6179a1b6a5c7d1b01a14ed0e#diff-1faebda3a5778a9d5b2dc0037a8f589bR8
[1]: https://github.com/dlang/DIPs/pull/66#discussion_r117613661
More information about the Digitalmars-d
mailing list