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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Community Input for the Maintenance and Revision of the Ada Programming Language Date: Tue, 12 Sep 2017 19:41:39 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <915874b5-52c0-4aa8-9023-82fddedb816f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 12 Sep 2017 17:41:40 -0000 (UTC) Injection-Info: reader.eternal-september.org; posting-host="22f2b84e7b7b28cb881445d9d9076c92"; logging-data="25526"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pIubRW3W4tG/ZdADLGAT5AOAJiQt+UoM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:8ARQCbmuNLn5kU4KlKhTkLghg44= Xref: news.eternal-september.org comp.lang.ada:48076 Date: 2017-09-12T19:41:39+02:00 List-Id: On 09/12/2017 08:18 AM, Tarjei Jensen wrote: > > A counted string can be viewed as > > type counted_string is record > max : natural; > len : natural; > str : array range ( 1 .. max) of character; > end record; This is, of course, illegal. > The best known environment which uses counted strings is Turbo Pascal. Note that I wrote "uses". It is still being used in education. In Ada 12, you can have something similar to Turbo Pascal's strings: with Ada.Strings; package B_Strings is type B_String (Max_Length : Positive := 1_000) is tagged limited private; -- This works in Ada 12 and only allocates Max_Length. -- Default initial value is Null_B_String Null_B_String : constant B_String; -- A string of zero characters function To_String (Source : B_String) return String; function "+" (Source : B_String) return String renames To_String; -- Lower bound of result is 1; upper bound is Length (Source) function To_B_String (Source : String) return B_String; function "+" (Source : String) return B_String renames To_B_String; -- Result's Max_Length will be Max (Source'Length, 1) function Length (Source : B_String) return Natural; Too_Long : exception; procedure Assign (To : in out B_String; From : in B_String; Drop : in Ada.Strings.Truncation := Ada.Strings.Error); -- Gives To the same value as From -- If Drop = Error and Length (From) > To.Max_Length, raises Too_Long -- To is unchanged if Too_Long is raised procedure Assign (To : in out B_String; From : in String; Drop : in Ada.Strings.Truncation := Ada.Strings.Error); -- Same as Assign (To => To, From => +From, Drop => Drop); function "=" (Left : B_String; Right : B_String) return Boolean; function "<" (Left : B_String; Right : B_String) return Boolean; function "<=" (Left : B_String; Right : B_String) return Boolean; function ">" (Left : B_String; Right : B_String) return Boolean; function ">=" (Left : B_String; Right : B_String) return Boolean; private -- B_Strings type B_String (Max_Length : Positive := 1_000) is tagged limited record Len : Natural := 0; Value : String (1 .. Max_Length) := (1 .. Max_Length => ' '); end record; Null_B_String : constant B_String := (Max_Length => 1, others => <>); end B_Strings; For earlier versions of Ada, you can eliminate the default for Max_Length, which may be even closer to what TP provides. -- Jeff Carter "Why don't you bore a hole in yourself and let the sap run out?" Horse Feathers 49