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,da85d9aaf769b16a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Generic package parameters not externally visible : what's the rational ? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.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: <10eygvuzeit9g.xwy2wanxoxgf$.dlg@40tude.net> Date: Thu, 29 Oct 2009 09:36:39 +0100 Message-ID: <1kf8mo4r9lqxg.1tdhqe6femt9m.dlg@40tude.net> NNTP-Posting-Date: 29 Oct 2009 09:36:39 CET NNTP-Posting-Host: 34945d66.newsspool4.arcor-online.net X-Trace: DXC=N2KcgokKlMgiENRCe X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8835 Date: 2009-10-29T09:36:39+01:00 List-Id: On Wed, 28 Oct 2009 14:19:58 -0500, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:10eygvuzeit9g.xwy2wanxoxgf$.dlg@40tude.net... >> On Tue, 27 Oct 2009 16:08:09 -0500, Randy Brukardt wrote: > ... >>> I'm not sure that it "makes perfect sense" for them to be visible: it would >>> surely increase the chance of name collisions outside of the package. >> >> Sorry, but that is a "generic" property of anything declared in a generic >> package. Two instances of the same generic packages always collide when >> "use"-ed. > > No, I was thinking of name collisions when the formal and actual have the > same name (that is very common for subprogram parameters and is not uncommon > in generic as well). If the formal is also visible, you end up with two > things with the same name. Something like: > > generic > type Int is range <>; > package Gen is > ... > end Gen; > > with Gen; > package Test is > type Int is range ...; > package My_Gen is new Gen (Int); > end Test; > > with Test; > procedure Check is > use Test, Test.Gen; > Obj : Int; -- (1) > ... > > (1) is legal by the current rules, but if the formal was visible, it would > become illegal because there would be two Int's visible. That would become > worse if any of the proposals for integrated instantiations are adopted, > because both Ints would be visible in the same scope, and thus use Test > would become ineffective: exactly the reverse of what is wanted from an > integrated instantiation. It is clear that some code will become illegal. Here is another example of a collision upon instantiation in the current version of Ada: generic type I is (<>); package P is type T is tagged null record; procedure Foo (Obj : T; X : I); procedure Foo (Obj : T; X : Integer); end P; package Bar is new P (Integer); -- Boom! I don't think we should much care about backward compatibility with regard to generics. My take is that any generic code is potentially broken. Anyone who uses generics beyond very trivial cases should know that, and mentally prepare himself to fix his code over and over again. >>> That's clear from the >>> syntax (they're outside the package). You're going to say that discriminants >>> are outside of the type, too, but they're also visible. I can't argue with >>> that beyond saying that that placement of discriminants is just awful; I >>> place them in the wrong place and continually forget to include them in >>> aggregates because they're well away from the other components. >> >> That depends on the mental model of the discriminant. If the discriminant >> is a type constraint, then you are right. But in Ada this concept, if ever >> existed, has been eroded. Presently discriminant is merely an immutable >> component. I am also in favor the "constraint" model, and yes, in this >> model it would be reasonable to make discriminants invisible, e.g. when >> they are used for construction and then dropped. But that is not the Ada >> model now. > > ...other than for Unchecked_Unions, and even there the model is incomplete. > (You can reference the discriminant in a context where it can be determined, > such as for a constrained object, even though it is not stored anywhere. But > you can't reference it if the object is unconstrained.) Yes, I also thought about Unchecked_Unions. It would be great to have checked Unchecked_Unions without "case" (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de