why no "old" operator in function postconditions, as in Eiffel?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sat Jun 23 04:32:32 PDT 2007


Frits van Bommel wrote:
> Bruno Medeiros wrote:
>> For D to properly support 'old', D would need to clone any input used 
>> as old, and that sounds as it might have some issues (not sure about 
>> that though). Still, perhaps better would be the alternative presented 
>> in the .learn thread where the 'out' scope would be able to access the 
>> 'in' scope.
> 
> I don't think cloning is necessary. It would just need to evaluate the 
> old-expression before the body is entered (i.e. at the end of the "in" 
> clause) and save the result in an "invisible variable" that's accessed 
> where the old-expression appears.
> Of course, it's then the programmer's responsibility to make sure that 
> the result is still valid after the body has executed; if it for 
> instance slices an array that's modified in the function, manual dups 
> will be required.

Well, yeah, if you only want old to work automatically for primitive 
types, then D itself wouldn't need to know how to clone. But if there 
will still be cases which need manual dups, then maybe its not worth it, 
versus the joined in-out scope alternative (where you have to manually 
dup any old you wish to check).

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list