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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Access parameters and accessibility Date: Wed, 17 Dec 2014 09:28:41 +0100 Organization: cbb software GmbH Message-ID: References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: YGNMlxhiQ90vAyH0QA4qPw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:24065 Date: 2014-12-17T09:28:41+01:00 List-Id: On Wed, 17 Dec 2014 07:02:56 +0000 (UTC), Natasha Kerensikova wrote: > Now you got me really worried, because I thouhgt access discriminants > were safe. It was under that assumption that I actually started to > really like them. > > More specifically, the pattern I caught myself using a lot looks like > the following: > > type Preprocessed_Data (Input_Data : access Input_Data_Type) is record not null access? > Computed_Value_1 : Type_1; > Computed_Value_2 : Type_2; > end record; > > procedure Private_Helper (Data : in Preprocessed_Data) is > begin > -- Do stuff qui Computed_Value_* and maybe also with Input_Data > end Private_Helper; > > procedure Process (Input_Data : in out Input_Data_Type) is > Data : Preprocessed_Data (Input_Data'Access); > begin > -- Initialize Data.Computed_Value_* > Private_Helper (Data); > end Process; > > For course, it means that Input_Data is actually aliased, so it must be > of a tagged type (or maybe a limited type works too?). > > That way a strong connection is maintained between the original data and > whatever is derived from it, and it gets to be handled in a single value > rather than letting the number of arguments explode when there are > several preprocessed types or steps. Though I started building such > types to use generics that expected a single type/value. > > Am I doing something danegerous here? > Should I try to find another pattern to achieve the same effects? The language should. Access disciminant is a hack. The pattern should have been: procedure Process (Input_Data : in out Input_Data_Type) is Data : Preprocessed_Data (Input_Data); with a proper constructor "virtualizing" Input_Data_Type "discriminant" of Preprocessed_Data. type Preprocessed_Data (Input_Data : Input_Data_Type) is ...; private type Preprocessed_Data is ... -- No discriminant actually overriding procedure Initialize (Input_Data : Input_Data_Type); > From what I understood, here accessibility is statically known to be > fine, isn't it? Or is there a trap hidden in there? AFAIK, it is safe. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de