Shortcut evaluation for hierarchy of in contracts

Jens Mueller jens.k.mueller at gmx.de
Tue Jul 5 13:31:04 PDT 2011


Daniel Murphy wrote:
> "Timon Gehr" <timon.gehr at gmx.ch> wrote in message 
> news:iukvrl$1c1c$1 at digitalmars.com...
> >
> > Sure, if you remember the Foo/Qux example (Foo is parent, Qux is child, 
> > method
> > bar(a,b), parent requires a>0 child requires else b>0)
> >
> > void main(){
> >  auto a=new Foo, b=new Qux;
> >  a.bar(1,-1);//ok
> >  b.bar(1,-1);//ok, child works everywhere parent works
> >  //a.bar(-1,1);// not ok
> >  //b.bar(-1,-1)// not ok
> >  b.bar(-1,1);//ok, child works too if b>0
> > }
> 
> And it finally clicks!  Thanks for taking the time to explain it to me.
> (If only I'd got it sooner, I wouldn't have spent the last two hours 
> implementing my behaviour in the compiler) 

Just found the time to go over this thread.
Thanks Daniel for asking until it was obvious for you. I now understand
it as well and I hope my initial post wasn't the cause for your
confusion. Thanks Timon for patiently answering and pushing us to
correct understanding.
The crucial thing to understand is that the in contract or precondition
is the disjunction of the super's in contract/precondition and the
statements written in "in { ... }" (note this definition is recursive).
This was pointed out several times. But I never understood why. Timon's
example makes it clear.

Jens


More information about the Digitalmars-d mailing list