From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Is it possible to make a possibly self-referential type using containers?
Date: Sun, 31 Jul 2016 09:00:26 +0200
Date: 2016-07-31T09:00:26+02:00 [thread overview]
Message-ID: <nnk7mq$1g72$1@gioia.aioe.org> (raw)
In-Reply-To: 18dfc647-ef22-4052-b6ad-ce3516124085@googlegroups.com
On 2016-07-31 02:31, Shark8 wrote:
> Type Executable_Code(<>) is private; -- The type in which we store executable code.
> Type Word(<>);
>
> Package Word_List is new Ada.Containers.Indefinite_Vectors
> (Element_Type => Word, Index_Type => Positive);
>
> Type Word( Is_List ) is record
> case Is_List is
> when True => List : Word_List.Vector;
> when False => Item : Executable_Code;
> end record;
>
> The above would be nicely elegant insofar as maintenance goes as
> it's simple and straightforward.
Nothing elegant in this, but anyway...
> * Word: a chunk of code to execute or a list of words [to execute].
> ** Something like SEQUENCE OF INTEGER is fundamental in IDL and ASN.1.
type Word is interface;
type Executable_Code (<>) is new Word with private;
package Lists is
new Ada.Containers.Indefinite_Vectors
( Index_Type => Positive,
Element_Type => Word'Class
);
type List is new Lists.Vector and Word with null record;
P.S. Type recursion is inconsistent if not resolved, as in the example
which splits self-referential Word into Word interface and Word'Class.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
prev parent reply other threads:[~2016-07-31 7:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-31 0:31 Is it possible to make a possibly self-referential type using containers? Shark8
2016-07-31 2:41 ` Randy Brukardt
2016-07-31 5:36 ` Jeffrey R. Carter
2016-07-31 7:00 ` Dmitry A. Kazakov [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox