On 23.06.2017 18:21, H. S. Teoh via Digitalmars-d wrote:
On Fri, Jun 23, 2017 at 09:06:59AM +0000, Solomon E via Digitalmars-d wrote:
[...]
T foo(T)(T x, T y)
in (x > 0, y > 0)
out (r; r > 0)
{
return x % y + 1;
}
Hmm, I like this syntax for out-contracts! It borrows from existing
foreach syntax, so it has some precedence, whereas the previous proposal
of `out(...)(...)` looks uglier and also looks deceptively like a
template function declaration.
`out (r; r > 0)` gets my vote.
OTOH, I don't like the comma in the in-contract. Let's just keep it as
either separate clauses:
in (x > 0)
in (y > 0)
or just use a boolean operator:
in (x > 0 && y > 0)
T
Agreed. Implementation:
https://github.com/dlang/dmd/compare/master...tgehr:contract-syntax
(At most one contract of each type is supported. It is not very hard to
implement multiple contracts, but this requires touching semantic analysis.)