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=0.6 required=5.0 tests=BAYES_20,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,47def5aa7b3182bd X-Google-Attributes: gid103376,public From: tmoran@bix.com (Tom Moran) Subject: Re: How to write TYPECASE in Ada 95? Date: 1999/02/17 Message-ID: <36cb2712.1390453@news.pacbell.net>#1/1 X-Deja-AN: 445459745 References: <79fct8$9k3$1@murdoch.acc.Virginia.EDU> <1103_918264881@DZOG-CHEN> X-Complaints-To: abuse@pacbell.net X-Trace: typhoon-sf.pbi.net 919283471 206.170.2.115 (Wed, 17 Feb 1999 12:31:11 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Wed, 17 Feb 1999 12:31:11 PDT Newsgroups: comp.lang.ada Date: 1999-02-17T00:00:00+00:00 List-Id: Dispatching is certainly better than a case statement - if you use it. Consider an existing package of the form: package Grocer is type Fruit is abstract tagged ... type Apple is new Fruit ... ... type Watermelon is new Fruit ... ... function Best(Budget : in Money) return Fruit'class; end Grocer; And now you are writing a new package which, among other things, does with Grocer; use Grocer; package Meal is procedure Serve(Dish : in Apple); ... procedure Serve(Dish : in Watermelon); end Meal; Suppose a user wants, not unreasonably, to write ... Meal.Serve(Dish => Grocer.Best(Budget=>1.00)); Unless you can go back and modify Grocer, it appears you must include in Meal procedure Serve_Fruit(Dish : in Fruit'class); with a body like procedure Serve_Fruit(Dish : in Fruit'class) is begin if Dish in Apple'class then Serve(Apple(Dish)); ... elsif Dish in Watermelon'class then Serve(Watermelon(Dish)); else raise Heck; end if; end Serve_Fruit; Is there a better way?