From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: U : Unbounded_String := "bla bla bla"; (was: Is the Writing...)
Date: Tue, 07 Oct 2003 10:51:31 +0200
Date: 2003-10-07T10:51:31+02:00 [thread overview]
Message-ID: <86u4ov4ojmuugvp2p4qsg725ah45p01c2h@4ax.com> (raw)
In-Reply-To: mailman.36.1065484926.25614.comp.lang.ada@ada-france.org
On Tue, 7 Oct 3 03:57:32 +0400, "Alexandre E. Kopilovitch"
<aek@vib.usr.pu.ru> wrote:
>Generalizing the Strings/Unbounded_Strings issue, I would propose a new notion
>of "enveloped" private type. That is, a private type Y may be declared as an
>envelope (new keyword) of some base type X:
>
> type Y is private envelope of X;
>
[...]
Looks similar to my proposal for defining subtypes.
Why to call "envelope" something which is a subtype? (:-))
It should be something like:
type Y is private subtype X;
Note that for the sake of genericity one need more than two
conversions. There should be four:
X_From_Y, X_To_Y - this pair is used when an Y gets substituted for X,
i.e. when Y *inherits* a subprogram from X. One of these conversions
might be absent. Then Y becomes an in-subtype or an out-subtype of X:
type Y is private in subtype X;
-- Only in-subroutines are inherited. So only X_From_Y has to be
-- defined
Y_From_X, Y_To_X - this pair is used when X gets substituted for Y,
i.e. when Y exports something to X. This is a way to create
supertypes.
type Y is private in out supertype X:
If all four conversions are present both types become fully
interchangeable, which is actually required in case String vs.
Unbounded_String.
So a definition of Unbounded_String should be:
type Unbounded_String is
private in out subtype String, in out supertype String;
procedure Append (Source : in out Unbounded_String;
New_Item : in Unbounded_String);
-- No need to define a variant with New_Item of String,
-- because it will be automatically exported to String.
private
type Unbounded_String is
new Ada.Finalization.Controlled with record ...
Note also that there is no need to require X_From_Y (X_To_Y (X))=X. It
is an implementation detail. The standard subtype does not insure
that. It raises Constraint_Error when a conversion is not possible.
For example, Append exported to String:
X : String (80);
Append (X, "something"); -- Constraint_Error
Here X was converted to Unbounded_String, then Append was called, then
it failed to convert it back to String.
---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de
next prev parent reply other threads:[~2003-10-07 8:51 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-02 18:02 U : Unbounded_String := "bla bla bla"; (was: Is the Writing...) amado.alves
2003-10-03 0:05 ` U : Unbounded String : " Alexander Kopilovitch
2003-10-03 20:46 ` Dmitry A. Kazakov
2003-10-03 9:00 ` U : Unbounded_String := " Preben Randhol
2003-10-03 11:17 ` Jeff C,
2003-10-04 2:49 ` Robert I. Eachus
2003-10-06 23:57 ` Alexandre E. Kopilovitch
2003-10-07 8:51 ` Dmitry A. Kazakov [this message]
2003-10-08 19:12 ` Alexandre E. Kopilovitch
2003-10-09 8:42 ` Dmitry A. Kazakov
2003-10-10 20:58 ` Alexander Kopilovitch
2003-10-13 8:35 ` Dmitry A. Kazakov
2003-10-13 21:43 ` Alexandre E. Kopilovitch
2003-10-14 8:09 ` Dmitry A. Kazakov
2003-10-16 9:39 ` Alexandre E. Kopilovitch
2003-10-18 10:57 ` Dmitry A. Kazakov
2003-10-08 23:18 ` Robert I. Eachus
2003-10-09 21:35 ` Alexandre E. Kopilovitch
2003-10-10 18:10 ` Robert I. Eachus
2003-10-11 19:43 ` Alexandre E. Kopilovitch
2003-10-12 5:03 ` Robert I. Eachus
2003-10-13 9:07 ` Dmitry A. Kazakov
2003-10-13 14:36 ` Alexandre E. Kopilovitch
2003-10-13 19:46 ` Robert I. Eachus
2003-10-14 1:35 ` Jeffrey Carter
2003-10-14 17:11 ` Alexandre E. Kopilovitch
2003-10-14 20:26 ` Mark A. Biggar
2003-10-14 20:58 ` Robert I. Eachus
2003-10-15 16:59 ` Alexandre E. Kopilovitch
2003-10-15 20:38 ` (see below)
2003-10-16 0:31 ` Alexandre E. Kopilovitch
2003-10-16 2:30 ` (see below)
2003-10-16 13:54 ` Alexandre E. Kopilovitch
2003-10-16 14:11 ` (see below)
2003-10-16 8:01 ` Dmitry A. Kazakov
2003-10-17 20:26 ` Randy Brukardt
2003-10-17 21:39 ` Alexandre E. Kopilovitch
2003-10-17 23:03 ` Robert I. Eachus
2003-10-23 21:11 ` Alexandre E. Kopilovitch
-- strict thread matches above, loose matches on Subject: below --
2003-10-03 12:00 amado.alves
2003-10-03 15:54 ` Mark A. Biggar
2003-10-03 20:41 ` Dmitry A. Kazakov
2003-10-03 16:12 amado.alves
2003-10-04 12:16 ` Preben Randhol
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox