From: "M. A. Alves" <maa@liacc.up.pt>
To: comp.lang.ada@ada.eu.org
Subject: Re: Looping over a tagged record?
Date: Thu, 21 Jun 2001 11:14:20 +0100 (WEST)
Date: 2001-06-21T11:14:20+01:00 [thread overview]
Message-ID: <mailman.993114925.4754.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <75dY6.214285$p33.4322717@news1.sttls1.wa.home.com>
> > 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"?
Essentialy that you can manipulate types as you do objects. A language
with less basic semantic devices. Types would be an elaboration of the
programmer. A reflexive tower of 2 or 3 levels. Hardly a software
engineering language. Roughly approximative model in Ada:
type Object is ...
procedure Add_Property(O: Object; Name: String);
procedure Add_Property(O: Object; Name, Value: String);
procedure Add_Property(O: Object; Name: String; Value: Object);
...
Record_Type: Object;
Add_Property(Record_Type, "type", Type_Definition);
Add_Property(Record_Type, "is a", "list");
Add_Property(Record_Type, "named components");
Add_Property(Record_Type, "iteratable");
A_Record: Object;
Add_Property(A_Record, "type", Record_Type);
Field_1, Field_2, Field_3: Object;
Add_Property(Field_1, "name", "Field_1");
Add_Property(Field_1, "type", "A");
Add_Property(Field_1, "name", "Field_2");
Add_Property(Field_2, "type", "A");
Add_Property(Field_1, "name", "Field_2");
Add_Property(Field_3, "type", "B");
Add_Property(A_Record, "component", Field_1);
Add_Property(A_Record, "component", Field_2);
Add_Property(A_Record, "component", Field_3);
Iterating:
for I in 1 .. Length(A_Record) loop
Do_Someting(Component(A_Record, I));
end loop;
Selecting by name:
Do_Somenthing(Component(A_Record, "Field_1"));
> >
> > ...
> > 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);
--
,
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
next prev parent reply other threads:[~2001-06-21 10:14 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-19 20:39 Looping over a tagged record? M R Goodwin
2001-06-19 21:31 ` Pascal Obry
2001-06-19 21:32 ` Pascal Obry
2001-06-19 22:20 ` Samuel T. Harris
2001-06-19 23:45 ` mgoodwinSPAMMY
2001-06-20 1:33 ` Pat Rogers
2001-06-20 3:13 ` Pat Rogers
2001-06-20 2:58 ` DuckE
2001-06-20 13:15 ` Ted Dennison
2001-06-20 15:01 ` M. A. Alves
2001-06-21 2:36 ` DuckE
2001-06-21 10:14 ` M. A. Alves [this message]
2001-06-21 13:24 ` Pat Rogers
2001-06-21 17:08 ` Charles Hixson
2001-06-21 18:58 ` tmoran
2001-06-21 23:02 ` Charles Hixson
2001-06-22 19:04 ` B.Gaffney
2001-06-22 20:36 ` Pascal Obry
2001-06-22 2:18 ` DuckE
2001-06-22 17:33 ` Charles Hixson
2001-06-22 18:24 ` tmoran
2001-09-13 0:29 ` Gnat Windows load error tmoran
2001-09-13 18:15 ` Jerry van Dijk
2001-09-13 23:17 ` tmoran
2001-09-13 3:58 ` Ada web crawler tmoran
2001-11-17 21:50 ` ada.strings.bounded slice errors tmoran
2001-11-18 17:16 ` Florian Weimer
2001-11-18 19:31 ` tmoran
2001-11-19 7:12 ` Florian Weimer
2002-02-08 20:55 ` How to get a traceback in Gnat 3.14p tmoran
2002-02-08 21:24 ` Pascal Obry
2002-02-08 22:28 ` tmoran
2002-02-11 0:10 ` How to use gnatelim in Gnat 3.14p? tmoran
2002-02-15 17:23 ` does gnatelim work? tmoran
2002-02-15 18:18 ` Stephen Leake
2002-02-15 21:58 ` tmoran
2002-02-18 1:31 ` Stephen Leake
2002-04-15 3:05 ` Announce: .rc files with Gnat tmoran
2002-04-15 14:48 ` Ted Dennison
2002-05-25 7:06 ` slice'access? tmoran
2002-05-25 16:47 ` slice'access? Robert Dewar
2002-05-25 18:28 ` slice'access? tmoran
2002-05-25 20:20 ` slice'access? Jeffrey Carter
2002-05-25 23:39 ` slice'access? tmoran
2002-05-26 14:22 ` slice'access? Robert Dewar
2002-09-30 1:54 ` 'write of bounded string? tmoran
2002-09-30 16:06 ` Stephen Leake
2002-10-27 23:01 ` phone# etc bdean
2002-10-28 3:04 ` tmoran
2002-11-06 3:14 ` A little Ada app tmoran
2002-11-06 11:37 ` Larry Kilgallen
2002-11-06 15:08 ` Ted Dennison
2002-11-06 18:02 ` tmoran
2001-06-21 3:09 ` Looping over a tagged record? gresset1
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox