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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1ce805592e46d231 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-04 10:56:56 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!opentransit.net!jussieu.fr!enst!enst.fr!not-for-mail From: "Beard, Frank" Newsgroups: comp.lang.ada Subject: RE: (elementary question) Test on type ? Date: Tue, 4 Sep 2001 13:55:27 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: avanie.enst.fr 999626215 96276 137.194.161.2 (4 Sep 2001 17:56:55 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Tue, 4 Sep 2001 17:56:55 +0000 (UTC) To: "'comp.lang.ada@ada.eu.org'" Return-Path: X-Mailer: Internet Mail Service (5.5.2448.0) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.4 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:12711 Date: 2001-09-04T13:55:27-04:00 I agree with what John's saying about "Generics are the place to do identical stuff ...", but I don't think you need to pass overloaded subprograms and some enumeration types to do specifics. The generic formal subprograms are for the specific stuff. So, I think all you would need is the following (from his original post): -- specification : generic type T is (<>); with procedure Do_Something (Item : in out T); with function Specific_Stuff (Item : T) return Float; function F(X : T) return Float; --body : function F(X : T) return Float is begin -- --if Type(X) = Integer then ?????? -- something... -- --I := integer(X) ???? -- Do_Something(X); -- if you really need to convert to integer here. I := integer(Specific_Stuff(X)); return Specific_Stuff(X); end; --application prog: procedure Do_Something (to_The_Integer : in out integer); function To_Float(from_Integer : integer) return Float; function F1 is new F(T => Integer, Do_Something => Do_Something, Specific_Stuff => To_Float); The decisions are already made in the subprograms being used to instantiate the generic, so it is unnecessary to do it again internally in the generic. Whatever specific things you want to do based on the types should be abstracted out to the actual subprograms that are supplied for the generic formal parameters. Frank -----Original Message----- From: john.mccabe@emrad.com.nospam [mailto:john.mccabe@emrad.com.nospam] Generics are the place to do identical stuff independent of the types. If you want to do different stuff depending on the type, then you should use overloaded function. I'm not sure whether this is possible (and I can't check at the moment as I don't use Ada any more), but you may be able to pass overloaded functions as generic actual parameters and then just make a call where the compiler will handle the types. e.g. generic type MyType is (<>); with procedure Test (InParm : in Integer); with procedure Test (InParm : in SomeOtherDiscreteType); package X : Then call Test when you want. I guess what you could do was define a type somewhere e.g: type PossibleTypes is (Int, Flt, Enum); then use declare the Test operations as functions that returned that type. Hope this helps. Best Regards John McCabe _______________________________________________ comp.lang.ada mailing list comp.lang.ada@ada.eu.org http://ada.eu.org/mailman/listinfo/comp.lang.ada