[GAP] old attribute

Jean-Pierre Rosen rosen at adalog.fr
Sat Oct 29 22:13:15 CEST 2011


Le 28/10/2011 17:41, Robert Dewar a écrit :
> On 10/28/2011 11:35 AM, Dick Gayler wrote:
>> I am using ada in an upper division course covering design by contract.
>> Specifically, I am using the precondition and postcondition pragmas.  As
>> is typical in academia, I am "going overboard" to emphasize the
>> concepts.  The problem that I have run across is that is seems that the
>> implementation of the old attribute makes a shallow copy of the object
>> leading to the obvious problems with linked structures.  Has anyone
>> looked at what has to be done so that the old attribute when make a deep
>> copy?  I am trying to avoid explicitly putting the "deep copy" code in
>> the subprograms.
> 
> Interesting, obviously this cannot be done automatically since what
> a "deep copy" means is very data structure dependent, I guess what
> you would need is a user defined attribute function something like
> 
>    for typ'Old use subprogram
> 
> where subprogram has the profile
> 
>    function typ'Old (Arg : typ) return typ;
> 
> Definitely an interesting suggestion.

But if you need a deep copy, you should define your type as controlled,
and the definition of Adjust will do the trick (Too lazy to check in the
RM, but I hope and believe that 'Old uses a regular assignment)


-- 
---------------------------------------------------------
           J-P. Rosen (rosen at adalog.fr)
Adalog a déménagé / Adalog has moved:
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00


More information about the GAP mailing list