From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 11 Aug 93 18:48:48 GMT From: cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland. reston.ans.net!news.ans.net!rpi!news.crd.ge.com!e7sa!groleau@ucbvax.Berkeley.ED U (Wes Groleau x1240 C73-8) Subject: Re: question about generics Message-ID: List-Id: In article eachus@spectre.mitre.org (R obert I. Eachus) writes: >In article <9308091429.aa12174@Paris.ics.uci.edu> kanderso@mabillon.ICS.UCI.ED U (Kenneth Anderson) writes: > > I.E. I need to be able to say something like > > package Generic_Package_Support is > > Viewers : array (1 .. 5) of STRING := ("How", "Would", "I", "Do", "Thi s?"); > > end Generic_Package_Support; > > You apparently need a package which implements varying strings in >a way that allows you to have arrays of differently sized strings. >This can be done in Ada by having a type which has a discriminated >record (with defaults) wrapped in a record with no discriminants. >I can send you such a package if you don't have one... Why the wrapper? Why won't the following work? package VAR_STRING is Max : constant := 1000; -- substitute your idea of reasonable value type STRING_LENGTH_TYPE is range 0 .. Max; subtype STRING_INDEX_TYPE is STRING_LENGTH_TYPE range 1 .. Max; type TEXT ( Size : STRING_LENGTH_TYPE := 0 ) is private; -- all the operations, including conversion functions to and from -- STRING, concatenation, etc. two of which are function TEXT_OF ( Str : STRING ) return TEXT; function STRING_OF ( Txt : TEXT ) return STRING; -- end VAR_STRING; ----------- ...... package INIT is new I_FORGOT_THE_NAME ( ( VAR_STRING.TEXT_OF ( "first" ), VAR_STRING.TEXT_OF ( "second" ), ... VAR_STRING.TEXT_OF ( "last" ) ) ) ....... Inside the generic you have for I in Formal'RANGE loop DO_SOMETHING_WITH ( VAR_STRING.STRING_OF ( Formal ( I ) ) ); end loop; Although I have not used the VAR_STRING package to pass OBJECTS to a generic (except indirectly), I don't see why there should be a problem. Wes G. P.S. I have seen several "free" variable string packages that have what is to me a RIDICULOUS usage of access types, requiring all sorts of contortions by client packages to avoid dangling pointers and heap exhaustion. My package and the ones I'm complaining about make the type private. In my case, no one needs to know the fact that it's a simple discriminated record, and "garbage collection" is done by leaving scope (of a TEXT object). In the other(s), the type is private in name only, because the client has to understand the implementation to protect itself )or carefully follow VERY detailed rules in the comments in the package spec. Why are such packages popular, while my approach is unpopular enough that I couldn't find anything similar in the repositories and books I checked? Is there something I don't know? I have yet to find a disadvantage to it, having used it in user interfaces and a primitive language parser. I'm admittedly a bit egotistical when it comes to my programming skills, but not so much so that I don't get nervous when it appears that no one else has thought of something so simple. Robert Eachus's post is the first hint I've seen that I'm not alone. Huh? A P.S. longer than the "main" ?