From: Brian Rogoff <bpr@shell5.ba.best.com>
Subject: Re: Ada OO Mechanism
Date: 1999/05/28
Date: 1999-05-28T00:00:00+00:00 [thread overview]
Message-ID: <Pine.BSF.4.10.9905282100570.18251-100000@shell5.ba.best.com> (raw)
In-Reply-To: 374F1DD3.64070C3E@mitre.org
On Fri, 28 May 1999, Robert I. Eachus wrote:
> Hyman Rosen wrote:
> > Once again, I will ask for an example demonstrating this, where
> > something is more complicated to use in C++ generics than in Ada.
> > This will make you the fourth person I have asked for this type
> > of example, the others being Richard D. Riehle, Samuel Mize, and
> > Robert Dewar. None of the others have chosen to post such an
> > example.
>
> I've done one example (probably with a few typos and thinkos since
> it is Friday afternoon), I'm not going to do this one too. The reason
> no one is anxious to demonstrate this is that reasonable examples take
> several pages of code in Ada, and of course lots more in C++.
I think that there are a few examples of reasonably short length, going
in each direction (Ada > C++ and C++ > Ada). I thought one of the original
preconditions was OO, but if its just generics, then the example Richard
O'Keefe presented a few years ago during one of the downward closure
discussions where he used Ada generics to simulate downward closures is
probably a good "pro-Ada" one, though I think the intent of the original
example was to show how bad Ada came off against Pascal and Scheme. Note
that using generics this way doesn't even really do a good job compared
to what you could do with downward closures; your Integrate_2D wouldn't
have to be tied to a particular Integrate_1D, you could just pass it in as
an argument. Any nice way around that problem, besides using GNAT specific
features? Anyways, I don't think this translates easily to C++, but if
Hyman or someone else can surprise me I'd be delighted.
-- First we write a simple 1-D integrator using the trapezoid rule
generic
type Float_Type is digits;
with function F(X : Float_Type) return Float_Type;
function Integrate_1D(Lower, Upper: Float_Type; Steps : Positive)
return Float_Type;
-- Tail recursive trapezoid rule, a tip o' the hat to Schemers!
function Integrate_1D(L1, U1: Float_Type; Steps : Positive)
return Float_Type is
Dx : constant Float_Type := (Upper - Lower) / Float_Type(Steps);
function Iterate( Step : Positive; Value : Float_Type )
return Float_Type is
begin
if Step = Steps then
return DX * Current_Value;
else
return Iterate( Step + 1,
Value + F(Lower + Float_Type(Step) * Dx));
end if;
end Iterate;
begin
Iterate(1, .5 * F(Lower) + F(Upper));
end;
-- The 2-D integration spec
generic
with function F(X, Y : Float_Type) return Float_Type;
function Integrate_2D(L1, U1, L2, U2: Float_Type; S1, S2 : Positive)
return Float_Type;
-- How I wish Ada 95 had real downward closures!!!
function Integrate_2D(L1, U1, L2, U2: Float_Type) return Float_Type is
function Outer_Integrand(Y: Float_Type) return Float_Type is
function Inner_Integrand(X: Float_Type) return Float_Type is
begin
return F(X, Y);
end Inner_Integrand;
function Inner_Integrator is
new Integrate_1D(F => Inner_Integrand, Steps => S1);
begin
return Inner_Integrator(L1, U1);
end Outer_Integrand;
function Outer_Integrator is
new Integrate_1D(F => Outer_Integrand, Steps => S2);
begin
return Outer_Integrator(L2, U2);
end Integrate_2D;
-- Brian
next prev parent reply other threads:[~1999-05-28 0:00 UTC|newest]
Thread overview: 116+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-20 0:00 Ada OO Mechanism Shawn M. Root
1999-05-20 0:00 ` Samuel Mize
1999-05-20 0:00 ` David Botton
1999-05-20 0:00 ` Samuel Mize
1999-05-20 0:00 ` David Botton
1999-05-24 0:00 ` Hyman Rosen
1999-05-24 0:00 ` Robert Dewar
1999-05-24 0:00 ` Hyman Rosen
1999-05-24 0:00 ` Mike
1999-05-25 0:00 ` Robert Dewar
1999-05-24 0:00 ` David Starner
1999-05-24 0:00 ` bob
1999-05-24 0:00 ` David Starner
1999-05-25 0:00 ` Ole-Hjalmar Kristensen
1999-05-25 0:00 ` Florian Weimer
1999-05-25 0:00 ` Mark A Biggar
1999-05-25 0:00 ` Hyman Rosen
1999-05-25 0:00 ` Samuel Mize
1999-05-25 0:00 ` Hyman Rosen
1999-05-25 0:00 ` Richard D Riehle
1999-05-25 0:00 ` Hyman Rosen
1999-05-26 0:00 ` Ray Blaak
1999-05-26 0:00 ` Richard D Riehle
1999-05-26 0:00 ` Hyman Rosen
1999-05-27 0:00 ` Richard D Riehle
1999-06-05 0:00 ` Matthew Heaney
1999-06-07 0:00 ` Hyman Rosen
1999-05-28 0:00 ` Laurent Guerby
1999-06-05 0:00 ` Matthew Heaney
1999-06-07 0:00 ` Hyman Rosen
1999-06-08 0:00 ` Matthew Heaney
1999-06-08 0:00 ` Hyman Rosen
1999-06-08 0:00 ` Samuel Mize
1999-06-08 0:00 ` Hyman Rosen
1999-06-08 0:00 ` Robert Dewar
1999-06-08 0:00 ` Stanley R. Allen
1999-06-08 0:00 ` Markus Kuhn
1999-06-08 0:00 ` Stanley R. Allen
1999-05-26 0:00 ` Hyman Rosen
[not found] ` <t7zp2sr6yf.fsf@calumny.jyacc.c <t7r9nmz8ou.fsf@calumny.jyacc.com>
1999-06-08 0:00 ` Larry Kilgallen
1999-06-08 0:00 ` Hyman Rosen
1999-06-14 0:00 ` Robert A Duff
[not found] ` <t7zp2sr6yf.fsf@calumny.jyacc.c <t7emjmmx8w.fsf@calumny.jyacc.com>
1999-06-08 0:00 ` Larry Kilgallen
1999-06-08 0:00 ` Hyman Rosen
1999-06-08 0:00 ` Tucker Taft
1999-06-08 0:00 ` Brian Rogoff
1999-06-09 0:00 ` Tucker Taft
1999-06-09 0:00 ` Robert Dewar
[not found] ` < <375E92CB.27850620@averstar.com>
1999-06-09 0:00 ` Brian Rogoff
1999-06-14 0:00 ` Robert A Duff
1999-06-09 0:00 ` Matthew Heaney
1999-06-09 0:00 ` Samuel Mize
[not found] ` <t7zp2sr6yf.fsf@calumny.jyacc.c <375d9a3d.e1cccc63@averstar.com>
1999-06-09 0:00 ` Larry Kilgallen
1999-06-09 0:00 ` Tucker Taft
1999-05-25 0:00 ` Brian Rogoff
1999-05-25 0:00 ` Jim
1999-05-26 0:00 ` Robert Dewar
1999-05-26 0:00 ` Brian Rogoff
1999-05-25 0:00 ` Samuel Mize
1999-05-25 0:00 ` Chris
1999-05-25 0:00 ` David Botton
1999-05-27 0:00 ` Aidan Skinner
1999-05-27 0:00 ` Gautier
1999-05-27 0:00 ` Samuel Mize
1999-05-27 0:00 ` Samuel Mize
1999-05-27 0:00 ` Jon S Anthony
1999-05-27 0:00 ` Samuel Mize
1999-05-27 0:00 ` Hyman Rosen
1999-05-28 0:00 ` Samuel Mize
1999-05-28 0:00 ` Laurent Guerby
1999-05-28 0:00 ` Richard D Riehle
1999-05-28 0:00 ` Tom Moran
1999-05-25 0:00 ` Richard D Riehle
1999-05-25 0:00 ` David Botton
1999-05-26 0:00 ` Tom Moran
1999-05-27 0:00 ` Aidan Skinner
1999-05-28 0:00 ` Robert I. Eachus
1999-05-28 0:00 ` Brian Rogoff [this message]
1999-05-29 0:00 ` Ehud Lamm
1999-05-30 0:00 ` chris
1999-05-30 0:00 ` Harry George
1999-05-30 0:00 ` Vladimir Olensky
1999-05-31 0:00 ` Robert Dewar
1999-05-30 0:00 ` Robert Dewar
1999-05-31 0:00 ` Vladimir Olensky
1999-06-03 0:00 ` Dale Stanbrough
1999-06-02 0:00 ` mike
1999-06-03 0:00 ` Robert Dewar
1999-06-06 0:00 ` David Botton
1999-06-07 0:00 ` Robert Dewar
1999-06-01 0:00 ` Richard D Riehle
1999-06-03 0:00 ` Matthew Heaney
1999-06-03 0:00 ` Matthew Heaney
1999-05-25 0:00 ` Samuel Mize
1999-05-25 0:00 ` Hyman Rosen
1999-05-25 0:00 ` David Starner
1999-05-26 0:00 ` Ole-Hjalmar Kristensen
1999-05-26 0:00 ` Laurent Guerby
1999-05-26 0:00 ` Hyman Rosen
1999-05-28 0:00 ` Laurent Guerby
1999-06-01 0:00 ` Hyman Rosen
1999-06-03 0:00 ` Fraser Wilson
1999-06-03 0:00 ` Matthew Heaney
1999-06-03 0:00 ` Hyman Rosen
1999-05-21 0:00 ` Dale Stanbrough
1999-05-20 0:00 ` bob
1999-05-21 0:00 ` Dale Stanbrough
1999-05-21 0:00 ` Richard D Riehle
1999-05-21 0:00 ` Shawn M. Root
1999-05-21 0:00 ` Richard D Riehle
1999-05-25 0:00 ` Shawn M. Root
1999-05-21 0:00 ` Marin David Condic
1999-05-21 0:00 ` Steve
1999-05-21 0:00 ` Dan Nagle
1999-05-24 0:00 ` Marin David Condic
1999-05-25 0:00 ` Don Overheu
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox