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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4f316de357ae35e9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-02 19:47:57 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone.socal.rr.com!cyclone3.kc.rr.com!news3.kc.rr.com!twister.socal.rr.com.POSTED!not-for-mail Message-ID: <3D4B4477.500088B@san.rr.com> From: Darren New X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: FAQ and string functions References: <20020730093206.A8550@videoproject.kiev.ua> <4519e058.0207300548.15eeb65c@posting.google.com> <20020731104643.C1083@videoproject.kiev.ua> <4519e058.0208010629.5e6182ca@posting.google.com> <20020801194720.Q1080@videoproject.kiev.ua> <4519e058.0208020605.5ab7e092@posting.google.com> <3D4AAF63.72782659@san.rr.com> <3D4B2382.7030209@telepath.com> <3D4B2ACD.FDA29B9A@san.rr.com> <3D4B401E.3060802@telepath.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sat, 03 Aug 2002 02:47:57 GMT NNTP-Posting-Host: 66.74.216.166 X-Complaints-To: abuse@rr.com X-Trace: twister.socal.rr.com 1028342877 66.74.216.166 (Fri, 02 Aug 2002 19:47:57 PDT) NNTP-Posting-Date: Fri, 02 Aug 2002 19:47:57 PDT Organization: RoadRunner - West Xref: archiver1.google.com comp.lang.ada:27639 Date: 2002-08-03T02:47:57+00:00 List-Id: Ted Dennison wrote: > > Darren New wrote: > > Yes. But when you chop up a string, what do you do with the result? You > > can't just declare an array in Ada and say "I'm not sure how much this will > > hold" or "add one more element to the end of this array" like you can with > > Ada.Strings.Unbounded. > > Yes you can. Tell me how you declare a variable for an array whose bounds you don't know until after you're past the declaration? Tell me how you add more elements to the end of an array? You can't do something like X := X & Y as far as *I* understand. > You just can't assign a new value into the array that is a > different size than the old value. Well, that's the problem. It means you can't pass me an in out array and let me make it bigger. > That's no huge hardship with declare > blocks, and no problem at all if you program everthing functionally. Yes, actually, it can be a huge hardship, if that's how you think about things. If you've got a variable of global lifetime (or whatever Ada calls something declared at the package level so its value is valid for the duration of the program) and you want to change how big it is, you can't. You have to have a pointer to an array, like Ada.Strings.Unbounded does. Sure, you can work around it. But that's true in any language. It's no huge hardship to only have 1-D arrays - you can always keep track of the bounds and multiply your first index by the second bound and add in the second index. But it's the kind of thing that people go "I can't believe I can't find this in the manual..." > My problem with a lot of this discussion is that it seems to be "Ada > doesn't support X idiom that Y programmers like to use", rather than > "Ada can't perform X task nearly as easily as language Y can." There are > probably examples of the latter that need to be addressed, so this > discussion is important. But the former is just someone's ignorance of > the language. Well, X idiom is kind of what we're talking about here. Of course Ada *could* do all this, if you write the code for it. But people coming from scripting languages just kind of expect something that's supposedly as powerful as Ada to be able to handle variable length arrays at least as easily as it handles variable-length strings. And it doesn't. > You are quite correct there. All that stuff is basicly equivalent to > Unbounded Lists and Maps, which is a known deficiency that will > (hopefully) be addressed in the next version of the language. That's good news! My concern is that while you *can* implement it, if it doesn't come with the language, you're likely to wind up having incompatible implementations between packages. Kind of like trying to mix modules out of some unrelated but complex C packages, each of which wants to do memory allocation and GC its own way so as to avoid the inevitable memory leaks you get with big C programs. :-) You can do it, but you wind up learning a whole new memory manager for each application. It shouldn't be that way. Dale Stanbrough wrote: > Ada -can- (sort of :-) have unbounded arrays, and it's not that hard to > implement. e.g. > > type Unbounded_Array is array (Positive range <>) of Unbounded_String; > > and then... > > declare > fields : Unbounded_Array := Split ("one two three"); > begin > ... But this works poorly in many places where, for example, you want to accumulate a bunch of results into an array. Like, I want to read lines from the terminal into an array of strings until I get a blank line. > Alternatively you return a pointer to the object, allowing it to be more > long lived. But the main problem is everyone's going to have a different type for doing this. The XML parser is going to return a different kind of array than the MIME parser. Of course, you can do stuff based on the GNAT unbounded strings code, which I did, but you really shouldn't have to. -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** They looked up at me like I was a T-bone steak walking into an all-you-can-eat seafood buffet.