contract programming without a function

Ary Manzana ary at esperanto.org.ar
Sun May 20 06:51:11 PDT 2007


It's gone from the documentation, but luckily I've got an old one (this 
is from DMD 0.176). In the "Contracts" section it was said:

| The in-out statement can also be used inside a function, for example, 
| it can be used to check the results of a loop:
|
| in
| {
|     assert(j == 0);
| }
| out
| {
|     assert(j == 10);
| }
| body
| {
|     for (i = 0; i < 10; i++)
| 	j++;
| }
|
| This is not implemented at this time.

I guess this is exactly what you want in the example you gave. I don't 
know why it's gone from the documentation, though. Maybe these feature 
was dropped from future plans?

Regards,
Ary

Jan Hanselaer escribió:
> Hi
> 
> In the manual http://www.digitalmars.com/d/dbc.html I read  :
> " The pre contracts specify the preconditions before a statement is 
> executed. The most typical use of this would be in validating the parameters 
> to a function. The post contracts validate the result of the statement. The 
> most typical use of this would be in validating the return value of a 
> function and of any side effects it has. "
> Makes sense to me. What I ask myself is if it's useful elsewhere and 
> especially is it possible in D? I tried it with a little example.
> 
> void main()
> {
>    bool assign = true;
>    int x;
>    in{
>       assert(assign);
>    }
>    body{
>       x = 1;
>    }
> }
> 
> 
> It wont compile ("found in instead of statement"). I know it's not exactly a 
> useful example but I just wanted to check if it was possible. I thought it 
> would be because nowhere es said it's not possible. Did I just made a 
> programming error or is it really not possible?
> 
> Greetings
> Jan
> 
> 
> 


More information about the Digitalmars-d-learn mailing list