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.3 required=5.0 tests=BAYES_00,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: mfb@mbunix.mitre.org (Michael F Brenner) Subject: Re: newbie question Date: 1999/03/19 Message-ID: <7cti23$ad2@top.mitre.org>#1/1 X-Deja-AN: 456473756 References: <36F039F8.275E7145@hknet.com> Organization: MITRE Corporation, Bedford, MA Newsgroups: comp.lang.ada Date: 1999-03-19T00:00:00+00:00 List-Id: Kenneth, if the problem is how to switch types, here is the information. In Ada some things are done at compile time and some things are done at runtime. One of the things you can do at compile time is switch what type a package works on. For example, you can write a SORT algorithm that works on a particular type of data called CUSTOMERS, and it might looks like this: type objects is record -- put all the object information here end record; type indexes is range 1..243; type object_lists is array (indexes range <>) of objects; procedure sort (object_list: in out object_lists) is begin -- put your sort algorithm here end sort; And you would call it like this: initialize (welsh_customers); sort (welsh_customers); Now, to switch to use other fixed-length types such as any fixed length string type, any exact type such as integers, any approximate type such as float, or any other type that has a fixed length, you could PASS IN the types to your sort algorithm like this: generic type indexes is range <>; type objects is private; type lists_of_objects is array (indexes range <>) of objects; procedure sort (list_of_objects: in out lists_of_objects); begin -- exactly the same sort algorithm end sort; You can then instantiate this generic at compile time by passing it the types you really want to sort, like this: procedure customer_sort is new sort (customer_ids, customers, call_lists); Then you could call this instantiation at runtime as follows: initialize(welsh_customers); customer_sort (welsh_customers); There are of course, many improvements that could be made to this code, but this technique will generalize any simple sort algorithm that works on fixed-length data to work on any other fixed-length data; in order to work on variable length data, additional structure is needed to do the variable length, such as discriminants, accesses, slices, dispatching, or (yuk) pointers. ------------------------------------------------------------------------- Kenneth said: just switched to Ada a few days. can someone show me how can i have a universal sort routine to sort arrays of integer and float? or even strings? i tried to implement such a generic unit, but failed coz i'm really new to Ada :P thx in advance. Kenneth