From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: attributes in generic procedure
Date: 1999/11/21
Date: 1999-11-21T00:00:00+00:00 [thread overview]
Message-ID: <38380fdb_4@news1.prserv.net> (raw)
In-Reply-To: 818esd$t6l$1@nnrp1.deja.com
In article <818esd$t6l$1@nnrp1.deja.com> , daelen@my-deja.com wrote:
> I would like to create a generic procedure as shown below which will only be
> used for scalar types. Does anybody have a hint how to accomplish this?
The issue is that there are different classes of scalar type, and
generic formal types differentiate the classes:
generic
type Integer_Type is range <>;
type Enum_Or_Int_Type is (<>);
type Float_Type is digits <>;
type Fixed_Type is delta <>;
type Mod_Type is mod <>;
> generic
> type A_Type is private;
> procedure Update (Par : in out A_Type; Value : String);
It looks like you need First, Last, Pred, Succ. Import the type as
private (like you already have), but also import constants and
operations on that type:
generic
type T is private;
First : in T;
Last : in T;
with function Pred (O : T) return T is <>;
with function Succ (O : T) return T is <>;
with function Value (S : String) return T is <>;
procedure Generic_Update (O : in out T; Image : in String);
Now, when a client instantiates the generic, he supplies the attribute
functions defined for the type as generic actuals:
function Update is new Generic_Update
(T => Integer,
First => Integer'First,
Last => Integer'Last,
Pred => Integer'Pred, ...);
This will work for any scalar type.
> procedure Update (Par : in out A_Type; Value : String) is
> begin
> if Value = "+" then
> if Par = A_Type'Last then
> Par := A_Type'First;
> else
> Par := A_Type'Succ (Par);
> end if;
For example:
if Value = "+" then
if Par = Last then
Par := First;
else
Par := Succ (Par);
end if;
--
Yeah, well, no one was present when the dinosaurs lived, so I guess
their presence in the fossil record is "only a theory." No one was
present when the Grand Canyon was formed either, or the creation of the
solar system, or, or, or. Of course evolution is "only a theory." What
else would it be as a scientific concept?
Skeptic magazine publisher Micheal Shermer, commenting on the recent
decision by the Oklahoma board of education to include a disclaimer on
school science textbooks warning that evolution is "only a theory."
Skeptic web page: http://www.skeptic.com/
next prev parent reply other threads:[~1999-11-21 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-11-21 0:00 attributes in generic procedure daelen
1999-11-21 0:00 ` Matthew Heaney [this message]
1999-11-25 0:00 ` Nick Roberts
1999-11-29 0:00 ` Niklas Holsti
1999-11-29 0:00 ` Robert Dewar
1999-12-03 0:00 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox