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.2 required=5.0 tests=BAYES_00,FROM_WORDY, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d46d23ef29cdbd30 X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: newbie question Date: 1999/03/19 Message-ID: <7cucck$jdp$2@plug.news.pipex.net>#1/1 X-Deja-AN: 456643427 References: <36F039F8.275E7145@hknet.com> <7cti23$ad2@top.mitre.org> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom) Newsgroups: comp.lang.ada Date: 1999-03-19T00:00:00+00:00 List-Id: 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 -------------------------------------