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 05:52:57 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!news-hog.berkeley.edu!ucberkeley!newshub.sdsu.edu!west.cox.net!cox.net!p01!news2.central.cox.net.POSTED!53ab2750!not-for-mail Message-ID: <3D4BD17A.5000004@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> <3D4B6516.C952DF5E@easystreet.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 03 Aug 2002 12:52:57 GMT NNTP-Posting-Host: 68.12.51.201 X-Complaints-To: abuse@cox.net X-Trace: news2.central.cox.net 1028379177 68.12.51.201 (Sat, 03 Aug 2002 08:52:57 EDT) NNTP-Posting-Date: Sat, 03 Aug 2002 08:52:57 EDT Organization: Cox Communications Xref: archiver1.google.com comp.lang.ada:27648 Date: 2002-08-03T12:52:57+00:00 List-Id: achrist@easystreet.com wrote: > Ted Dennison wrote: > >>no problem at all if you program everthing functionally. >> > > > Just a few weeks ago I wrote an Ada program that does lots of string > splitting and concatenation, and I wrote it functionally, and it > runs very slowly. Things like extracting the nth item in a string > by extracting the 1st item n times and all that, all recursively. > Is that true? Does a typical Ada compiler, for example GNAT 3.14 > public edition that I used, have optimizations for tail-recursive > functions? Or will I get into trouble if I over-abuse recursion Why don't you check the docs? I just reinstalled my OS here, so I can't do it for you. But I seem to remember it doing tail-recursion optimizations at the higher optimization levels. At the default it is purposely extra slow (perhaps "deliberate" would be a better term), so as to not confuse debuggers. There are some things you can do to help out though. For example, don't declare anything locally that you don't need a separate copy of in each recursive call. The same goes for passing parameters. This goes against the usual rule of not using globals, but so be it. You can mitiagate the maintainability pain by declaring the recursive routine inside of another routine, which contains the declarations for all the recursive "globals". Also, try to code so that your algorithim is indeed tail-recursive (and use the optimization). But you will still have to expect a certian amount of slowness, compared to just declaring a big honking string and using a "Last_Index" variable. That's why the example of functional Text_IO Get_Line on Adapower used both approaches (a big honking string with a Last_Index, and a recursive call if that wasn't big enough).