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,437103ff8a92c0df X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!blackbush.cw.net!cw.net!feed.news.tiscali.de!news.belwue.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: generics and records Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1109532840.857126.234720@z14g2000cwz.googlegroups.com> <1109539865.754582.147740@o13g2000cwo.googlegroups.com> Date: Mon, 28 Feb 2005 09:47:44 +0100 Message-ID: NNTP-Posting-Date: 28 Feb 2005 09:44:50 MET NNTP-Posting-Host: c5b7488c.newsread2.arcor-online.net X-Trace: DXC=c1NCn@B8[eVMYeRE0Pb_HUQ5U85hF6f;TjW\KbG]kaMXea\9g\;7NmUZkQQ9LHD5V][6LHn;2LCV^7enW;^6ZC`T<=9bOTW=MN^ X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8523 Date: 2005-02-28T09:44:50+01:00 List-Id: On 27 Feb 2005 13:31:05 -0800, spambox@volja.net wrote: > Dmitry A. Kazakov wrote: > >> 2. Inheritance from a record type with known components: >> >> type Common_Base is tagged record >> A : Float; -- This will be visible in Foo >> end record; >> >> generic >> type Record_Type is new Common_Base with private; >> package Foo is >> ... >> >> Instantiation: >> >> type My_Record is new Common_Base with record >> ... -- These new components will be inaccessible in Foo! >> end record; >> package My_Foo is new Foo (My_Record); > > Thanks for the prompt response. One more question: how do I make the > components (the whole record?) known? Where must it be declared? You can't do that. Ada has a contract model of generics. That means that Foo in the example above will never directly see the whole record, only its Common_Base part. The primitive operations defined on Common_Base will. So if Foo has to access all record, the only way to do it is to express what Foo should do in terms of primitive operations defined on Common_Base. They can dispatch to the specific operations defined on the actual type. Usually, it is sufficient for all purposes and also is a good OO-ish programming style. But there is no way to write a generic unit working with whatever components of an actual parameter. Ada does not provide abstract record interfaces with enumeration of components and their types at run time. Though you can implement something close to that using map container types instead of record types. Probably this is what you actually need. But again, to work through primitive operations is better. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de