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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-04 01:28:19 PST Path: archiver1.google.com!news2.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!dialin-145-254-043-040.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? Date: Sat, 04 Oct 2003 10:33:04 +0200 Organization: At home Message-ID: References: <3F739C1D.4030907@attbi.com> <3F78E850.8010401@comcast.net> <3F797748.3000203@noplace.com> <834clb.uan1.ln@skymaster> <3F79EF18.7060600@comcast.net> <3F7B1076.8060106@comcast.net> <5mknnv4u96qqudrt4bd8n4t1cljp2fjlp8@4ax.com> <3F7C810E.7070100@comcast.net> <3G2dnS15r8mycOCiXTWJkA@gbronline.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-043-040.arcor-ip.net (145.254.43.40) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 1065256095 14311757 145.254.43.40 (16 [77047]) User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:198 Date: 2003-10-04T10:33:04+02:00 List-Id: Wes Groleau wrote: > Dmitry A. Kazakov wrote: >> This is what I want. And this is what arrays cannot: >> >> type Element (Constraint : Natural) is ...; >> type Array_Of_Elements is array (...) of Element; >> >> This is not allowed, because I cannot constrain Element, and there is no >> way to do it other than create a constrained subtype of Element. > > I realize this is not exactly what you meant, > but is it not possible to do this: > > type Element (Constraint : Natural) is ...; > > type Array_Of_Elements is array (...) of Element; No. Consider a very simple thing: type String_Array is array (...) of String; You cannot do that because the element is not constrained. The compiler does not know that in our case all elements are of same length. How to tell him? You have to do something like: type String_In_Record (Length : Positive) is The_Body : String (1..Length); end record; and even this artificial construct does not work: type String_Array is array (...) of String_In_Record; -- Error So you have to go further: type String_In_Record (Length : Positive := 80) is The_Body : String (1..Length); end record; This would result in Storage_Error. Defaulted discriminants are not what people usualy think about them! And even if you replace Positive with something of lesser range, you will not solve the problem: type Index is range 1..1024; type Yet_Another_String is array (Index range <>) of Character; type String_In_Record (Length : Index := 80) is The_Body : Yet_Another_String (1..Length); end record; type String_Array is array (...) of String_In_Record; Observe that this disgusting construction does not serve the purpose, because it allocates the memory for the worst case. And also this does not work for all the cases where the defaults are not allowed for the discriminants. For example (a very important one), the tagged types cannot have defaulted discriminants. Presently this is unsolvable without generics. -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de