On Thu, Sep 19, 2013 at 04:44:12PM +0200, bearophile wrote: > H. S. Teoh: > > >At the very least, it would be nice to have access to x.old, as > >Eiffel allegedly allows, if we insist on letting x refer to the copy > >of the input value modified by the function body. > > OK. But if x is a reference to a data structure, the old (prestate) > needs to be just a shallow copy. [...]
Hmm. So it seems there are two use cases here: 1) An argument is passed by value: in this case, the implementation details shouldn't be exposed, so only x.old should be referred to in the out contract. 2) An argument is mutable and passed by reference: in this case, the point of the function is presumably some side-effect on the argument, so the out contract generally should refer to the final state of the argument (so it serves as documentation on what the function does to the mutable argument). It may still be useful to refer to x.old in this case, but it would incur performance overhead (and possibly implementational difficulties since D currently doesn't have automatic deep-copying). So a shallow copy would be an acceptable compromise. T -- I've been around long enough to have seen an endless parade of magic new techniques du jour, most of which purport to remove the necessity of thought about your programming problem. In the end they wind up contributing one or two pieces to the collective wisdom, and fade away in the rearview mirror. -- Walter Bright