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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b30ef5c12f872cb8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.59.229 with SMTP id c5mr11085837pbr.6.1322217973015; Fri, 25 Nov 2011 02:46:13 -0800 (PST) Path: lh20ni16156pbb.0!nntp.google.com!news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!news-transit.tcx.org.uk!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Why constant components are not permitted ? Date: Fri, 25 Nov 2011 11:45:51 +0100 Organization: cbb software GmbH Message-ID: References: <1856c00b-1994-406a-bbb3-73d93785099a@i6g2000vbe.googlegroups.com> <87lir5tibe.fsf@ludovic-brenta.org> <1paloim06wnwx.1stqgrcrax4md.dlg@40tude.net> <16f6610a-39e3-4988-a239-eb7c1778ade8@e2g2000vbb.googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news2.google.com comp.lang.ada:14645 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2011-11-25T11:45:51+01:00 List-Id: On Fri, 25 Nov 2011 02:23:22 -0800 (PST), Ludovic Brenta wrote: > Dmitry A. Kazakov wrote on comp.lang.ada: >> On Thu, 24 Nov 2011 20:46:13 +0100, Ludovic Brenta wrote: >>> Constants with other purposes can be declared outside the type >>> definition and thus shared among all objects of the declared type. >> >> The constant value may depend on the enclosing object, undesired or >> impossible to re-evaluate each time when needed. > > IOW, the constant is the cached result of a function taking the rest, > or part thereof, of the object as its sole parameter. and possibly the context where the object was created. > If this result > is a constant, this can only mean that the rest of the object is > constant too, right? No. The object itself can be mutable. Otherwise we would need no discriminants, which among other play the role of constant components. > If not all other components are inputs into the function returning > the constant result, then it is probably desirable to split the object > into two types, such that all the "constant" components are in a type > of their own: > > type Immutable_Part is record > Hash_Value : Natural; > Component_1 : Foo; > end record; > > type T (Immutable : not null access constant Immutable_Part) is record > Component_2 : Bar; > end record; That would complicate design. If discriminants must keep on playing the role of constant components, then Ada should allow any objects as discriminants: type T (Immutable : constant Immutable_Part) is record Component_2 : Bar; end record; However I would prefer discriminants used as constraints and only constraints in order to produce constrained subtypes. Furthermore, since Ada does not have abstract record interface (getter and setter), you might also with to have this: type T is private with record Field_1 : constant Integer; -- You cannot change this Field_2 : constant Integer; -- You cannot change this either end record; private type T is record Field_1 : constant Integer := 3; -- Nobody can change this field Field_2 : Integer; -- I can change this, you cannot Field_3 : Integer; -- You cannot see this one end record; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de