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-Thread: 103376,640b65cbfbab7216 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!n1g2000prb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Ada.Bounded_Strings Date: Fri, 4 Apr 2008 14:09:27 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <47F26C46.3010607@obry.net> <44d88b93-6a90-4c18-8785-2164934ba700@a9g2000prl.googlegroups.com> <47F652F7.9050502@obry.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1207343368 18375 127.0.0.1 (4 Apr 2008 21:09:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 4 Apr 2008 21:09:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n1g2000prb.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20823 Date: 2008-04-04T14:09:27-07:00 List-Id: On Apr 4, 9:10 am, Pascal Obry wrote: > > Sorting out string handling out would be nice, too. > > Probably something to do in this area I agree. OK, this is *really* beating a dead horse, but... When I read this and was thinking randomly about Ada's string handling, I got to wondering why Bounded_Strings was defined as a generic, rather than declaring a discriminated type with the maximum length as the discriminant. I don't know why I hadn't thought of this before, in the last 13 years, but I figured someone else had probably asked that, so sure enough after a bit of searching I ended up finding the answer in the Ada 95 Rationale. The problem is, the answer doesn't make a whit of sense to me. The idea was to declare a non-generic package and a Bounded_String type that looked like: type Bounded_String (Max_Length : Positive) is record Length : Natural; Data : String(1..Max_Length); end record; The disadvantage of this approach was given as this: "[P]redefined assignment and equality for discriminated Bounded_String do not have the desired behavior. Assignment makes sense when the maximum lengths of source and target are different, as long as the source's current length is no greater than the target's maximum length, yet predefined ":=" would raise Constraint_Error on the discriminant mismatch". The reason this doesn't make sense to me is, how does the generic definition solve the problem? If you have two different maximum lengths, then you have to instantiate Bounded_Strings twice to get types with different maximum lengths; and then the Bounded_String types are separate types and you can't do an assignment anyway. So I don't see why this was considered a disadvantage of the discriminant approach. (Plus, with a discriminant definition you could at least write an assignment *procedure* with one OUT parameter, but you can't do that with generics, except by defining a second generic package that takes two instances of Bounded_Strings as formal parameters, which would then have to be instantiated for every combination of two lengths for which you'd want to do assignment.) I realize I'm at least a decade too late in asking this, but in case someone has a good memory, I was wondering if someone could explain this to me? And would it be useful to add a package like this now? (I'm thinking of this because Graham alluded to Ada's not being adopted in business settings, and I'm wondering whether this kind of type would seem more comfortable and familiar to COBOL-type programmers than an Unbounded_String type. But I'm just guessing---I really wouldn't know.) -- thanks, Adam