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: a07f3367d7,12d893e9461dcfe6 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.138.146 with SMTP id a18mr82889qau.6.1343953646895; Thu, 02 Aug 2012 17:27:26 -0700 (PDT) Received: by 10.180.107.167 with SMTP id hd7mr295296wib.0.1343910029539; Thu, 02 Aug 2012 05:20:29 -0700 (PDT) Received: by 10.224.138.146 with SMTP id a18mr14318654qau.6.1343910020175; Thu, 02 Aug 2012 05:20:20 -0700 (PDT) Path: c6ni8032qas.0!nntp.google.com!r1no233637qas.0!news-out.google.com!n2ni4545788win.0!nntp.google.com!volia.net!news2.volia.net!feed-B.news.volia.net!12no3629213wil.1!news-out.google.com!a15ni8161257qag.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin.stu.neva.ru!gegeweb.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Access to generic formal parameters in an generic package instantiation Date: Sun, 29 Jul 2012 21:36:28 +0200 Organization: cbb software GmbH Message-ID: <1g8gnsgtfkmog$.1gs7zsxkjcxrl.dlg@40tude.net> References: <87a9yi5t7j.fsf@mid.deneb.enyo.de> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: 9A8bJrx4NhDLcSmbrb6AdA.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-07-29T21:36:28+02:00 List-Id: On Sun, 29 Jul 2012 20:16:00 +0200, Florian Weimer wrote: > If G is a generic package and P is one of its formal parameters, it is > legal to refer to G.P where G is visible? Does this depend on the > kind of entity, or whether the formal part uses <>? Sometimes it works, sometimes it does not, I am not a language lawyer to tell when GNAT is right or not. Facing this problem quite frequently, I developed a custom to rename formal parameters within the declaration area, e.g. generic type Foo is ...; with package Bar is new Baz (<>); package Boo is subtype My_Foo is Foo; package My_Bar is renames Bar; ... Another method of making formal parameters visible is to have it a generic child. > that is, specify that two types in two formal packages are the same, > without break down the formal packages to their components? Yes. There several techniques to accomplish this. 1. You can to make that type a formal parameter and specify it among the formal parameters of the instances: type T is ... with package P1 (T, <>); with package P2 (T, <>); 2. You can take the type from one package and constrain another with it: with package P1 (<>); with package P2 (P1.T, <>); 3. You can factor out a generic parameter package that defines T and other common types and make it generic parent for the packages of interest. > It seems that generic formal packages are unusual because GNAT shows > some strange effects (and the occasional bug box). There were always problems with generics in GNAT. Though you likely won't believe me anyway, but using generics is a very bad idea unless absolutely nothing else works. Here is an outlook what it becomes in a relatively simple case: http://www.dmitry-kazakov.de/ada/fuzzy_packages.gif Can you figure out a chain of instantiation of this for some given floating-point type? How many instances it does? In a really complex case there are multiple pages of such diagrams. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de