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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c6517ef820c06ae0 X-Google-Attributes: gid103376,public From: mark_lundquist@my-deja.com Subject: Re: generic formal object parameters of mode 'in out' Date: 2000/11/06 Message-ID: <8u7evh$5ue$1@nnrp1.deja.com>#1/1 X-Deja-AN: 690478310 References: <3a06dc1c.259466533@news.rrds.co.uk> X-Http-Proxy: 1.1 x62.deja.com:80 (Squid/1.1.22) for client 130.213.201.52 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Mon Nov 06 23:30:56 2000 GMT X-MyDeja-Info: XMYDJUIDmark_lundquist Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt) Date: 2000-11-06T00:00:00+00:00 List-Id: In article <3a06dc1c.259466533@news.rrds.co.uk>, steve.folly@rdel.co.uk (Steve Folly) wrote: > In my program I have the following generic package... > > subtype Template_String is string(1..4); > > generic > type T is private; > Default : T; > Template : Template_String; > package P > The_Template : constant String := Template; > . > . > end P; > > We have had to declare The_Template because we've found that the > parameters are not visible from an instantiation, ie. > > declare > package X is new P ( T => Integer, Default => 0, Template => "NNNN" > ); > begin > Ada.Text_Io.Put_Line("The template is " & X.Template ); -- uh oh! > Ada.Text_Io.Put_Line("The template is " & X.The_Template ); -- OK > end; > > Am I right in thinking that by making Template an 'in out', I don't > need The_Template. Nope, sorry. Making Template 'in out' won't change its visibility. If you make Template 'in out', then you will get a compile error on your instantiation above, because an 'in out' generic formal requires a variable (view of an) object as the actual (because the generic is allowed to change the value of the actual). So instantiating it on a constant expression like "NNNN" isn't legal. But... I'd still get rid of The_Template, anyway! Having P re-export one of its own generic parameters strikes me as gimmiky and something that doesn't really make the program clearer. Since, by construction, the actuals are visible wherever the instantiation itself is visible, why not just refer to the actual? You don't need a workaround for not being able to refer to the formal. That is: declare Template : constant String := "NNNN"; package X is new P (T => Integer, Default => 0, Template => Template); begin Ada.Text_Io.Put_Line ("The template is " & Template); end; To me that seems less roundabout... but to each his/her own... > And, if it is now an 'in out', can I change Template at any time > outside of the instantiation (or inside it) ? Right. have fun, mark Mark Lundquist Rational Software Sent via Deja.com http://www.deja.com/ Before you buy.