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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,75ffc1f081ec10e3 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.glorb.com!feed.xsnews.nl!feeder.xsnews.nl!feeder.news-service.com!feeder.news-service.com!195.14.215.231.MISMATCH!newsfeed-fusi2.netcologne.de!newsreader2.netcologne.de!news.netcologne.de!nhp.netcologne.de!newsfeed.arcor.de!news.arcor.de!not-for-mail Date: Sun, 02 Jul 2006 11:18:24 +0200 From: Georg Bauhaus Organization: elsewhere User-Agent: Thunderbird 1.5.0.4 (Macintosh/20060530) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Constant record components References: <12ad8guf3sg1o0d@corp.supernews.com> <1loq7utmaxvll$.yqsxj5edzqgv.dlg@40tude.net> <12adcn2kslq7d80@corp.supernews.com> <1151778788.25270.4.camel@localhost.localdomain> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <44a78f17$0$29122$9b4e6d93@newsread4.arcor-online.net> NNTP-Posting-Date: 02 Jul 2006 11:17:11 MEST NNTP-Posting-Host: b796953c.newsread4.arcor-online.net X-Trace: DXC=9]XNWJii[>gGnN95NbAh:a:ejgIfPPlddjW\KbG]kaMhLL]:kiR8f=oPM1R`F_P9oehP3YJKgE\jl2Y5TcK=F8Co`J7J Jeffrey R. Carter wrote: > Ada.Text_IO.Put_Line ("Component is not constant"); > You get 3 guesses which string is output, and the 1st 2 don't count. > Clearly, this does not meet the OP's interest in components that cannot > be changed after initialization. Not sure whether it is clear that the OP wanted records initialized twice, as in A : Rec.R := Rec.Make (1); begin A := Rec.Make (2); To enforce the contract of the constructor function `make` ("call once for each object") and still not making the records or a component limited how about this workaround then: package Rec is type R is tagged private; procedure make(m: INTEGER; result: in out R); -- `m` is the initial value for the immutable component -- pre: result has not been initialized function immutable(thing: R) return INTEGER; private type R is tagged record mutable: INTEGER; data: INTEGER; identity: POSITIVE'base := 0; end record; end Rec; Imagine a protected Sequence in the body that generates unique positive values for the .identity part of R. Make raises Program_Error whenever called with a Result that has .identity /= 0. A limited component Immutable looks like another option to me. (Yes, there are no immutable non-limited components other than discriminants, but possibly there is a solution, sort of, that works reasonably well even though it takes some space?)