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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx22.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:36.0) Gecko/20100101 Thunderbird/36.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to use read-only variables? References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <9Z1qw.1023124$Lj7.835753@fx22.iad> X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Sun, 04 Jan 2015 02:56:05 UTC Organization: TeraNews.com Date: Sat, 03 Jan 2015 19:55:57 -0700 X-Received-Bytes: 2298 X-Received-Body-CRC: 2426316854 Xref: news.eternal-september.org comp.lang.ada:24337 Date: 2015-01-03T19:55:57-07:00 List-Id: On 03-Jan-15 17:58, hreba wrote: > > type R is abstract tagged limited record > n: access constant Integer; > end record; > > type Rv is new R with private; > > private > > type Rv is new R with record > nv: aliased Integer; > end record; Try it like this: With Ada.Text_IO.Text_Streams; procedure Test is package tmp is type R is abstract tagged limited record n: access constant Integer; end record; type Rv is new R with private; function Make( I : Integer ) return Rv; function Val( Item : Rv ) return Integer; private type Rv is new R with record -- The following referenced "this" as a particular -- instance for the default value by using the type-name -- (and 'access) as a self-reference. we have to convert -- the de-reference to the parent class, and then access -- the appropriate value. nv: aliased Integer:= R(Rv'access.all).n.all; end record; -- Note that we let the default values take care of ensuring -- that the values are properly in-sync. function Make( I : Integer ) return Rv is ( n => new Integer'(I), others => <> ); function Val( Item : Rv ) return Integer is ( Item.nv ); end tmp; use Ada.Text_IO; begin declare K : tmp.Rv:= tmp.make( 129 ); begin Put_Line( "K.n:" & K.Val'Img ); end; Put_Line( "Done." ); end Test;