D's design by contract is missing "old"?

Manfred Nowak svv1999 at hotmail.com
Mon Jun 18 10:55:34 PDT 2007


Russ Williams wrote

> This makes senses because copy and identity are issues 
> with multiple solutions -- a shallow copy as done by 
> 'clone' by default may not be enough for instance -- and 
> a compiler cannot be reasonably expected to guess correctly 
> which interpretation is appropriate for a given usage.

Then `old' seems to control a preimplemented simplified memento 
pattern that is served once and only on function scope entry.

So this seems an application for D's non existing scope guard
  `scope(entry)'

In fact pre- and postconditions seem to be nothing else than blocks 
that are injected into the function body by `scope(entry)' and `scope
(exit)' respectively.

If this holds, then a call of the form `old variable' can in 
principle be seen as the duality of 
  scope(entry){ save( variable);}
injected into the function body and the call `old variable' replaced 
by
  recall( variable);

-manfred 


More information about the Digitalmars-d-learn mailing list