From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,165d3eeae8b654b6 X-Google-Attributes: gid103376,public From: Alexander V. Konstantinou Subject: Re: constant record components in Ada Date: 1997/06/29 Message-ID: <5p4qfr$rac@sutton.cs.columbia.edu>#1/1 X-Deja-AN: 253351851 Sender: akonstan@news.cs.columbia.edu References: <5p100i$pvn@sutton.cs.columbia.edu> Organization: Columbia University Department of Computer Science Newsgroups: comp.lang.ada Date: 1997-06-29T00:00:00+00:00 List-Id: Robert Dewar wrote: : A K asks : <> : The cleanest solution is to use a private extension so that Key_Type : is a hidden field. If you want users to have read access to it, you : can provide an appropriate access function. : You can of course make the entire type private, and provide exactly the : access you want in functional form as another alternative. How does that help me get the functionality of the C++ statement map_pair a(1, true); // ok a.first = 10; // assignment of a read only member // compile time error a.second = false; // ok The Ada package using a combination of private/limited types would either not provide any assignmet to a.first (what is the use then), or catch a second assignment through an exception. Now, I don't see how that is equivalent. : If the specification of your type is precisely that any arbitrary change : to Value_Type is OK, but no change at all is valid to Key_Type, then : it is true that the C++ notation is more convenient, but this is a very : special case of the general issue of maintaining consistent data. : Abstracting the data type is a much more general and usually preferable : solution. This is not an issue of syntactic sugar. It is perfectly reasonable to have a data structure in which you would like to provide write-once only access to certain records (like the key used to create the map). In addition, I wish to catch such errors at compile-time rather than run- time. I would have to go to great lengths, that is, create a new type and support a limited view of its operations to achieve what C++ does naturally (this is not a shot in the language war -- I can give many examples in which Ada does things much more cleanly than C++). To be fair, I do not see an easy way to incorporate such fuctionality to Ada since Ada takes a different view of constants than C++. Alexander -- Alexander V. Konstantinou http://www.cs.columbia.edu/~akonstan/ akonstan@cs.columbia.edu akonstan@acm.org