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,2e8cf506f89b5d0a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-20 19:36:52 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "DuckE" Newsgroups: comp.lang.ada References: Subject: Re: Looping over a tagged record? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: <75dY6.214285$p33.4322717@news1.sttls1.wa.home.com> Date: Thu, 21 Jun 2001 02:36:51 GMT NNTP-Posting-Host: 24.248.45.203 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 993091011 24.248.45.203 (Wed, 20 Jun 2001 19:36:51 PDT) NNTP-Posting-Date: Wed, 20 Jun 2001 19:36:51 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:8956 Date: 2001-06-21T02:36:51+00:00 List-Id: "M. A. Alves" wrote in message news:mailman.993045741.6638.comp.lang.ada@ada.eu.org... [snip] > > Often I also want to merge record and array i.e. have named _and_ > iteratable "components". Theoretically this comes down to "types as > objects", which Ada doesn't have. Practically, a "standard" Ada idiom for > this is an heterogenous array indexed on an enumeration e.g. (not tested): Could you please elaborate on exactly what you mean by "types as objects"? > > ... > type Field_Ptr is access Field'Class; > type Field_Names is (Field_1, Field_2, Field_3); > type Record_Type is array(Field_Names) of Field_Ptr; > A_Record: Record_Type := ( > Field_1 => Field_Constructor_A(...), > Field_2 => Field_Constructor_A(...), > Field_3 => Field_Constructor_B(...)); > > Now we have a record-like object A_Record with "components" Field_1, > Field_2 of "type" A and Field_3 of "type" B. This example assumes > class-wide programming (including dispatching), with (tagged) type Field > being the root of some derivation class. Iterating over A_Record's > "components": > > for I in A_Record'Range loop > Do_Something(A_Record(I).all); -- dispatching call > end loop; > > Accessing "components" by name: > > Do_Something(A_Record(Field_1).all); > > This particular approach has a notorious shortcoming: field types are not > checked (Field_Ptr values can reference _any_ derived type in the class). > The remedy for this is left as an exercise ;-) I believe this will be caught a runtime. But it really depends on how Do_Something is defined. SteveD > > -- > , > M A R I O data miner, LIACC, room 221 tel 351+226078830, ext 121 > A M A D O Rua Campo Alegre, 823 fax 351+226003654 > A L V E S P-4150 PORTO, Portugal mob 351+939354002 >