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-03 18:08:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!jfk3-feed1.news.algx.net!allegiance!news.stealth.net!news.stealth.net!central.cox.net!cox.net!p01!news2.central.cox.net.POSTED!53ab2750!not-for-mail Message-ID: <3D4C7DE5.9060408@telepath.com> From: Ted Dennison User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, 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> <3D4B4477.500088B@san.rr.com> <3D4BCEC9.9030108@telepath.com> <3D4C0ABA.F38204E3@san.rr.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 04 Aug 2002 01:08:30 GMT NNTP-Posting-Host: 68.12.51.201 X-Complaints-To: abuse@cox.net X-Trace: news2.central.cox.net 1028423310 68.12.51.201 (Sat, 03 Aug 2002 21:08:30 EDT) NNTP-Posting-Date: Sat, 03 Aug 2002 21:08:30 EDT Organization: Cox Communications Xref: archiver1.google.com comp.lang.ada:27662 Date: 2002-08-04T01:08:30+00:00 List-Id: Darren New wrote: > In the sense that it was the OP's original question. Surely you can't mean > "don't ask that question." No. The OP asked about general string processing routines in Ada, listing several examples from Perl. If the question is "where are the string routines" the answer is "Ada.String.*, and the string attributes (and built in slicing)". If the question is, "In general, how am I supposed to deal with strings in Ada", then the answer is unfortunately rather long. But either way, whether Ada has routines exactly matching all the Perl routines is definitely not the point. > I mean, wouldn't the same argument hold if someone said "Why doesn't > language Blah have a while loop?" and you gave the answer "Well, the idiom > in Blah is to use conditional gotos, which is not a royal pain." Actually, Lisp originally did not have built in looping (or so I've been told). The idea behind the language was that you were supposed to do iteration with recursion instead. Sound familiar? I would imagine the Lisp folks had dicussions very much like the one we're having now, before they broke down and added procedural looping constructs to the language. :-) > Recursion is not always possible either, if other tasks need to be handled > coherently, if (say) other tasks need to look at the value of the list while > you're waiting for more input to come in, if you want to update a GUI based That would be completely unsafe, unless you lock the data structure somehow. In order to do that you'd probably want to make the list a protected object, which I don't think anyone is seriously talking about doing right now. > on the lines of text, if you're filling in the array based on the processing > of a state machine (like a parser), etc etc. I.e., if you have something > that's difficult to program in a functional style. I think you mean a lexical analyzer, not a parser. Lexical analyzers are usually some kind of state machine (unless they are very simple). Parsers aren't always state machines; in fact most hand-written ones are probably recursive-descent. I've done functional lexical analyzers. You just give the "tokenize_once" function its input string, and have it return the slice of it that contains a token. However, its usually a lot quicker to just work out of a big buffer, and use indices to designate tokens within the buffer. That way you aren't copying strings around until you need to. The only really good example of something that's tough to program functionally in Ada that I can think of is stuff involving Text_IO.Get_Line, and that's only because you are forced to use buffers and data lengths to use that routine. A functional version of Get_Line (and one exists on AdaPower) would have solved this problem. There *are* times where functional use of String is way too slow. For those instances you can use buffers and lengths. There are also times where you could deal with the overhead of dynamic allocations, but you just can't deal with all the extra data copying that funtional use of String would cause. For those instances, its nice to have Ada.Strings.Unbounded. (and hopefully one day Ada.Lists or whatever). But Ada programmers should teach themselves to work with perfectly sized constant strings where feasable, as that's the language's native idiom.