On Wed, 4 Aug 1999, Jean-Pierre Rosen wrote: > Anton Gibbs a écrit 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 which > > 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 with > 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. 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 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 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. I think its also true that in the typical implementation of generics there will be a code size problem too. -- 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; F : Func1_Type) return Float; function Integrate_1D(L1, U1 : Float; F : Func1_Type) return Float is -- some locals begin -- some 1-D integrator end; function Integrate_2D(L1, U1, L2, U2: Float; Integrator : Integrate_1D_Type; Func : Func2_Type ) return Float is function Inner(Y: Float) return Float is function Curried_F(X: Float) return Float is begin return Func(X, Y) end; begin return Integrator(L1, U1, Curried_F'Unrestricted_Access) end; begin return Integrator(L2, U2, Inner'Unrestricted_Access) end;