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,e1bb9627c57b7d5b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-07 01:42:13 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: U : Unbounded_String := "bla bla bla"; (was: Is the Writing...) Date: Tue, 07 Oct 2003 10:51:31 +0200 Message-ID: <86u4ov4ojmuugvp2p4qsg725ah45p01c2h@4ax.com> References: <3F7E352F.1@comcast.net> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1065516131 16879819 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:362 Date: 2003-10-07T10:51:31+02:00 List-Id: On Tue, 7 Oct 3 03:57:32 +0400, "Alexandre E. Kopilovitch" 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