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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a5cdfaf37bba8923 X-Google-Attributes: gid103376,public From: kst@sd.aonix.com (Keith Thompson) Subject: Re: Design of Ada.Strings.Bounded Date: 1997/07/16 Message-ID: #1/1 X-Deja-AN: 257452542 Sender: news@thomsoft.com (USENET News Admin @flash) X-Nntp-Posting-Host: puumba References: <5q4mel$16r$1@goanna.cs.rmit.edu.au> Organization: Aonix, San Diego, CA, USA Newsgroups: comp.lang.ada Originator: kst@puumba Date: 1997-07-16T00:00:00+00:00 List-Id: In mheaney@ni.net (Matthew Heaney) writes: > In article , kst@sd.aonix.com (Keith Thompson) wrote: > >I do wonder, though, why the maximum length of a Bounded_String was > >made a generic parameter rather than a discriminant. [...] > > >Was this approach considered? If so, why was it rejected? > > The reasons for the choice are discussed in the Rationale. So they are. > Also, from AARM 95 A.4.4 (1.b): > > Reason: The bound of a bounded-length string is specified as a parameter to > a generic, versus as the value for a discriminant, because of the > inappropriateness of assignement and equality of discriminated types for > the copying and comparison of bounded strings. Predefined equality isn't a problem, since the package declares its own "=" function explicitly. Assignment is a problem, but I'm not convinced that the generic approach is the best solution. Currently, assignment between Unbounded_Strings of different Max_Lengths is illegal, since they're different types. (For that matter, two instantations of Ada.Strings.Bounded.Generic_Bounded_Length with the *same* Max_Length will create two distinct types.) With a discriminated type, such an assignment would be legal, but it would raise Constraint_Error. (Even using a controlled type wouldn't solve this.) If the source and target Max_Lengths are static, though, the Constraint_Error could be detected at compile time and the compiler could issue a warning. I suspect most instantiations of Ada.Strings.Bounded.Generic_Bounded_Length use a static value for Max_Length. In any case, programmers who are really concerned about flexibility can always use Unbounded_Strings. -- Keith Thompson (The_Other_Keith) kst@sd.aonix.com <*> TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix 5040 Shoreham Place, San Diego, CA, USA, 92122-5989 "Zathras warn Zathras, but Zathras never listen to Zathras." -- Zathras -- Keith Thompson (The_Other_Keith) kst@sd.aonix.com <*> TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix 5040 Shoreham Place, San Diego, CA, USA, 92122-5989 "Zathras warn Zathras, but Zathras never listen to Zathras." -- Zathras