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 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,2308afbbe4ecec0b X-Google-Attributes: gid103376,public From: Brian Rogoff Subject: Re: Subverting 'Access for Sub-programs Date: 1999/08/04 Message-ID: #1/1 X-Deja-AN: 509040923 Content-Transfer-Encoding: QUOTED-PRINTABLE References: <37A71EF1.2201@dera.gov.uk> <37A7FDE8.4F5@dera.gov.uk> <7o9vrv$qgt$1@wanadoo.fr> Content-Type: TEXT/PLAIN; charset=X-UNKNOWN X-Trace: nntp1.ba.best.com 933824901 228 bpr@206.184.139.136 MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-08-04T00:00:00+00:00 List-Id: On Wed, 4 Aug 1999, Jean-Pierre Rosen wrote: > Anton Gibbs a =E9crit dans le message : > 37A7FDE8.4F5@dera.gov.uk... > > Dear Ada Community, > > > > Thank you, everyone, for all the very helpful responses to my question > > on 'Access. > > > > Unfortunately, in my eagerness to provide a simplified statement of my > > problem, I had omitted an important detail: in fact, the procedure whic= h > > I called Main is really not the main program and, more importantly, it > > has a parameter which I need to access. > > > [snip] > I understood from a previous message that you didn't like the solution wi= th > a generic taking a formal procedure. > It seems however that it would allow you to do precisely what you want. > You may not "like" generics, but they are inherently safer than access > values. Actually, in the discussion about downward closures, it was noted > that all the cases presented could be equally well be dealt with with > generics, and therefore that it was not worth introducing a risky feature= =2E Not true for any reasonable value of "equally well". For instance, in one of those ancient postings of a few years ago on this very topic Richard O'Keefe presented the example of making a two dimensional integrator from= =20 a one dimensional one. The Ada version with generics depended on the name of the one dimensional integratoir, and so it was parameterized by that particular integrator. The downward closure one was free to range over all= =20 one dimensional integrators. I'll append the code, if you can come up with a perspicuous generic version that doesn't depend on the one dimensional code I'll be more convinced.=20 I think its also true that in the typical implementation of generics there= =20 will be a code size problem too.=20 -- Brian type Func1_Type is access function(X : Float) return Float; type Func2_Type is access function(X,Y : Float) return Float; type Integrate_1D_Type is access function(X,Y : Float;=20 =09=09=09=09=09 F : Func1_Type)=20 return Float; function Integrate_1D(L1, U1 : Float; =09=09=09 F : Func1_Type) return Float is=20 =09-- some locals=20 begin =09-- some 1-D integrator=20 end; function Integrate_2D(L1, U1, L2, U2: Float; =09=09=09 Integrator : Integrate_1D_Type; =09=09=09 Func : Func2_Type ) return Float is=20 =09function Inner(Y: Float) return Float is=20 =09 function Curried_F(X: Float) return Float is=20 =09 begin=20 =09=09return Func(X, Y)=20 =09 end; =09begin=20 =09 return Integrator(L1, U1, Curried_F'Unrestricted_Access)=20 =09end; begin=20 =09return Integrator(L2, U2, Inner'Unrestricted_Access)=20 end;