* Design of Ada.Strings.Bounded @ 1997-07-11 0:00 Dale Stanbrough 1997-07-11 0:00 ` Matthew Heaney 1997-07-13 0:00 ` Keith Thompson 0 siblings, 2 replies; 5+ messages in thread From: Dale Stanbrough @ 1997-07-11 0:00 UTC (permalink / raw) After contemplating how i would use Ada.Strings.Bounded, i wondered about the decisions that were made when it was designed. If I use it in a package, and want to add any additional features, or use it as a parameter type e.g. function Check_Spelling (Item : Bounded_80) return Boolean; then this is rather unfortunate when i want to check the spelling of an item in a Bounded_81 string. This is exactly the same problem that we had in Pascal, that unconstrained types in Ada solved. One possible design that would have solved this problem is to have Ada.Strings.Bounded declare and abstract tagged type, with all of the subprograms declared abstract, and a small generic package with the type inside. e.g. package Ada.String.Bounded is type Bounded_String is abstract tagged private; function Length (Item : Bounded_String) return Natural is abstract; function Max_Length (Item : Bounded_String).... is abstract; ... generic Max : Positive; package Generic_Bounded_Length is ... type Bounded is new Bounded_String with private; ... end Generic_Bounded_Length; end Ada.Strings.Bounded; This would at least allow class wide programming for functions such as Check_Spelling above. Dale ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Design of Ada.Strings.Bounded 1997-07-11 0:00 Design of Ada.Strings.Bounded Dale Stanbrough @ 1997-07-11 0:00 ` Matthew Heaney 1997-07-13 0:00 ` Keith Thompson 1 sibling, 0 replies; 5+ messages in thread From: Matthew Heaney @ 1997-07-11 0:00 UTC (permalink / raw) In article <5q4mel$16r$1@goanna.cs.rmit.edu.au>, Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> wrote: >After contemplating how i would use Ada.Strings.Bounded, i wondered about >the decisions that were made when it was designed. > >If I use it in a package, and want to add any additional features, or >use it as a parameter type > >e.g. > function Check_Spelling (Item : Bounded_80) return Boolean; > >then this is rather unfortunate when i want to check the spelling >of an item in a Bounded_81 string. This is exactly the same problem >that we had in Pascal, that unconstrained types in Ada solved. Declare your subprogram as a generic, and import the instantiation of Generic_Bounded_Length: generic with package Bounded_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length (<>); use Bounded_Strings; function Generic_Check_Spelling (Item : Bounded_String) return Boolean; QED. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant <mailto:matthew_heaney@acm.org> (818) 985-1271 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Design of Ada.Strings.Bounded 1997-07-11 0:00 Design of Ada.Strings.Bounded Dale Stanbrough 1997-07-11 0:00 ` Matthew Heaney @ 1997-07-13 0:00 ` Keith Thompson 1997-07-14 0:00 ` Matthew Heaney 1 sibling, 1 reply; 5+ messages in thread From: Keith Thompson @ 1997-07-13 0:00 UTC (permalink / raw) In <5q4mel$16r$1@goanna.cs.rmit.edu.au> Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes: > After contemplating how i would use Ada.Strings.Bounded, i wondered about > the decisions that were made when it was designed. > > If I use it in a package, and want to add any additional features, or > use it as a parameter type > > e.g. > function Check_Spelling (Item : Bounded_80) return Boolean; > > then this is rather unfortunate when i want to check the spelling > of an item in a Bounded_81 string. Probably the easiest way to handle this is to declare Check_Spelling to take a parameter of type String. To pass it a parameter of type Bounded_80, just call To_String. I do wonder, though, why the maximum length of a Bounded_String was made a generic parameter rather than a discriminant. Thus, rather than ... package Ada.Strings.Bounded is ... generic Max : Positive; package Generic_Bounded_Length is type Bounded_String is private; ... end Generic_Bounded_Length; end Ada.Strings.Bounded; we could have ... package Ada.Strings.Bounded is ... type Bounded_String(Max_Length : Positive) is private; ... end Ada.Strings.Bounded; This would slightly complicate the function To_Bounded_String (it would need an extra parameter to specify the Max_Length of the result), but it would otherwise simplify the use of Bounded_Strings from the user's point of view. It would also allow operations between Bounded_Strings of different Max_Lengths. On the other hand, it might make operations on Bounded_Strings slightly less efficient, since they'd have to allow for the discriminant values. Was this approach considered? If so, why was it rejected? -- Keith Thompson (The_Other_Keith) kst@sd.aonix.com <http://www.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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Design of Ada.Strings.Bounded 1997-07-13 0:00 ` Keith Thompson @ 1997-07-14 0:00 ` Matthew Heaney 1997-07-16 0:00 ` Keith Thompson 0 siblings, 1 reply; 5+ messages in thread From: Matthew Heaney @ 1997-07-14 0:00 UTC (permalink / raw) In article <EDA684.Dnr@thomsoft.com>, 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. Thus, rather than >Was this approach considered? If so, why was it rejected? The reasons for the choice are discussed in the Rationale. 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. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant <mailto:matthew_heaney@acm.org> (818) 985-1271 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Design of Ada.Strings.Bounded 1997-07-14 0:00 ` Matthew Heaney @ 1997-07-16 0:00 ` Keith Thompson 0 siblings, 0 replies; 5+ messages in thread From: Keith Thompson @ 1997-07-16 0:00 UTC (permalink / raw) In <mheaney-ya023680001407970241320001@news.ni.net> mheaney@ni.net (Matthew Heaney) writes: > In article <EDA684.Dnr@thomsoft.com>, 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 <http://www.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 <http://www.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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1997-07-16 0:00 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1997-07-11 0:00 Design of Ada.Strings.Bounded Dale Stanbrough 1997-07-11 0:00 ` Matthew Heaney 1997-07-13 0:00 ` Keith Thompson 1997-07-14 0:00 ` Matthew Heaney 1997-07-16 0:00 ` Keith Thompson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox