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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,330ec86e1824a689 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-28 11:54:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!snoopy.risq.qc.ca!newsfeed.news2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3D6D1C3C.884FAD77@acm.org> From: Jeffrey Carter X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Run-Time Type Assignment References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 28 Aug 2002 18:53:29 GMT NNTP-Posting-Host: 63.184.105.138 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1030560809 63.184.105.138 (Wed, 28 Aug 2002 11:53:29 PDT) NNTP-Posting-Date: Wed, 28 Aug 2002 11:53:29 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:28521 Date: 2002-08-28T18:53:29+00:00 List-Id: "Robert C. Leif" wrote: > > From: Bob Leif > To: SK et al. > How does your solution work, if the variants are: > case Num_Parameters is > when 1 => > Parameter_1: Parameter_1_Type; > when 2 => > Parameter_1: Parameter_1_Type; > Parameter_2: Parameter_2_Type; > when 3 => > Parameter_1: Parameter_1_Type; > Parameter_2: Parameter_2_Type; > Parameter_3: Parameter_3_Type; > end case; > This is the equivalent of a tagged type. One way is to make it a tagged type with a chain of types extended from it. If you need/want to avoid tagged types, the composition equivalent to type extension is to build up a bunch of record types, then combine them in a variant record: type Param_1_Data is record Parameter_1 : Parameter_1_Type; end record; -- Further types may be in separate packages if desired type Param_2_Data is record Parent : Param_1_Data; Parameter_2 : Parameter_2_Type; end record; type Param_3_Data is record Parent : Param_2_Data; Parameter_3 : Parameter_3_type; end record; type Any_Param_Data (Num_Params : Whatever) is record case Num_Params is when 1 => Parameter_1 : Param_1_Data; when 2 => Parameter_2 : Param_2_Data; when 3 => Parameter_3 : Param_3_Data; end case; end record; Run-time dispatching is also easily implemented using this approach, and is left as an exercise for the reader. -- Jeff Carter "I wave my private parts at your aunties." Monty Python & the Holy Grail