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=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!goblin1!goblin.stu.neva.ru!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: hreba Newsgroups: comp.lang.ada Subject: How to use read-only variables? Date: Sat, 03 Jan 2015 22:58:15 -0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net AwMzRZJejG7a2iY1vChRDw1qzfcT/HxcIHORlAHxg/YTFp+bLo Cancel-Lock: sha1:Kd+tUbhPkZEnH5HpWHoULqah/F0= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 Xref: number.nntp.giganews.com comp.lang.ada:191638 Date: 2015-01-03T22:58:15-02:00 List-Id: My Ada book says that 'access const' types serve for readonly variables but I am not sure whether I grasped the idea. I want a readonly variable 'n' as component of a record 'R'. The variable which is accessed by 'n', let's call it 'nv' must be hidden, otherwise the client could change it. Consequently 'R' must be extensible, that is tagged. It makes no sense to use the base class alone (without something for 'n' to point to), so it must be abstract. As the pointer-target relation wouldn't be conserved in a simple assignment, the record must be limited. This leads to 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; The value of 'n' would be defined in an initialization procedure: procedure Init (rec: in out Rv) is begin rec.n:= rec.nv'Access; end Init; This however gives me an error message: non-local pointer cannot point to local object Now I am really confused: - Are readonly variables really handled this way, typically? - How can rec.nv be local and rec.n not? - How would you write the correct initialization procedure? All this seems pretty complicated to somebody used to Oberon, where all this would be simply written as TYPE R* = RECORD n-: INTEGER; END; -- Frank Hrebabetzky +55 / 48 / 3235 1106 Florianopolis, Brazil