From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Re: newbie question
Date: 1999/03/19
Date: 1999-03-19T00:00:00+00:00 [thread overview]
Message-ID: <7cucck$jdp$2@plug.news.pipex.net> (raw)
In-Reply-To: 7cti23$ad2@top.mitre.org
Crucially, one of the things you can pass as a generic parameter into a
generic unit is a procedure or function. Furthermore, the parameter types
of the parameters (and return types) of these can be other generic
parameters (which must appear beforehand).
Thus one might declare:
generic
type Element_Type is private;
type Index_Type is (<>);
type Array_Type is array (Index_Type) of Element_Type;
with procedure Swap (Item1, Item_2: in out Element_Type) is <>;
with function "<=" (Left, Right: in Element_Type) return Boolean is
<>;
procedure My_Sort (Object: in out Array_Type; From, To: Index_Type);
and complete this declaration with a body:
procedure My_Sort (Object: in out Array_Type; From, To: Index_Type) is
...
end My_Sort;
within which you can refer to the generic parameters (almost) as if they
were ordinary examples of the corresponding kinds of entity.
The 'is <>' at the end of the procedure and function generic parameters
allow an instantiation of the generic procedure (My_Sort) to be omitted, if
there is a suitable procedure or function already in existence which has the
same name ('Swap' or the operator "<="). A lot of types already have "<="
defined for them (the predefined types Integer, Float, and String, for
example).
The generic procedure can then be 'instantiated' to create a specific
procedure which can actually be called. For example, supposing we had:
type Day is (Monday, ..., Sunday);
type Earnings is array (Day) of Float;
procedure Swap (F1, F2: in out Float) is
F3: constant Float := F1;
begin
F1 := F2;
F2 := F3;
end Swap;
we could then declare the following instantiation:
procedure Sort_Earnings is new My_Sort(Float,Day,Earnings);
The procedure Sort_Earnings will sort an array of the type Earnings. The
generic parameters 'Swap' and "<=" did not have to explicitly passed in the
instantiation, because they already existed, and could be 'assumed'.
I hope this is not too complicated to take in in one gulp! A good textbook,
tutor, friendly local expert, or online tutorial will repay your study.
Best of luck.
-------------------------------------
Nick Roberts
-------------------------------------
next prev parent reply other threads:[~1999-03-19 0:00 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-18 0:00 newbie question Kenneth Lee
1999-03-18 0:00 ` Tom Moran
1999-03-18 0:00 ` Kenneth Lee
1999-03-18 0:00 ` Nick Roberts
1999-03-18 0:00 ` Andreas Winckler
1999-03-19 0:00 ` Kenneth Lee
1999-03-19 0:00 ` Michael F Brenner
1999-03-19 0:00 ` ELMO
1999-03-21 0:00 ` Matthew Heaney
1999-03-19 0:00 ` Michael F Brenner
1999-03-19 0:00 ` Nick Roberts [this message]
1999-03-20 0:00 ` Nick Roberts
1999-03-19 0:00 ` robert_dewar
-- strict thread matches above, loose matches on Subject: below --
2000-05-25 0:00 Newbie question olsonm76
2000-05-26 0:00 ` Robert Dewar
2001-12-24 13:52 Jasbinder S Uppal
2001-12-24 20:06 ` Michal Nowak
2001-12-24 21:13 ` martin.m.dowie
2001-12-25 12:36 ` Michal Nowak
2001-12-27 14:25 ` Alfred Hilscher
2001-12-29 21:54 ` Michal Nowak
2001-12-31 17:51 ` Jasbinder S Uppal
2002-01-01 21:26 ` Michal Nowak
2004-08-04 6:42 Newbie Question leke
2004-08-04 8:55 ` Frank
2004-08-04 9:51 ` Martin Dowie
2005-07-03 17:58 newbie question e.coli
2005-07-03 18:32 ` Dmitry A. Kazakov
2005-07-18 11:26 Newbie question Francisco J. Montoya
2005-07-18 13:14 ` Martin Dowie
2005-07-18 13:51 ` Alex R. Mosteo
2005-07-18 20:27 ` Martin Dowie
2005-07-18 15:28 ` Jeffrey Carter
2005-07-18 17:40 ` Martin Krischik
2007-11-23 13:22 Sir Chewbury Gubbins
2007-11-23 14:01 ` Sir Chewbury Gubbins
2007-11-24 16:49 ` Stephen Leake
2007-11-24 17:08 ` Peter C. Chapin
2007-11-25 19:25 ` Stephen Leake
2007-11-29 0:46 ` Robert A Duff
2009-03-12 13:29 Olivier Scalbert
2009-03-12 13:48 ` Ludovic Brenta
2009-03-12 14:16 ` Olivier Scalbert
2009-03-12 14:31 ` Ludovic Brenta
2009-03-12 14:32 ` stefan-lucks
2009-03-12 14:36 ` Ludovic Brenta
2009-03-12 17:14 ` stefan-lucks
2009-03-12 18:29 ` Adam Beneschan
2009-03-12 15:03 ` Jacob Sparre Andersen
2009-03-12 15:07 ` Robert A Duff
2009-03-12 17:16 ` Georg Bauhaus
2009-03-13 1:59 ` tmoran
2009-03-15 13:46 ` Olivier Scalbert
2009-03-21 18:08 ` Olivier Scalbert
2009-03-21 18:22 ` (see below)
2009-03-21 18:29 ` Olivier Scalbert
2009-03-21 18:36 ` Georg Bauhaus
2009-03-21 18:39 ` Olivier Scalbert
2009-03-22 12:40 ` (see below)
2009-03-22 13:19 ` Olivier Scalbert
2009-03-21 18:39 ` Jeffrey R. Carter
2009-03-23 8:24 ` Jean-Pierre Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox