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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f3437064e1091fec X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-13 17:10:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!msunews!not-for-mail From: "Chad R. Meiners" Newsgroups: comp.lang.ada Subject: Re: What evil would happen? Date: Sun, 13 Jul 2003 20:06:30 -0400 Organization: Michigan State University Message-ID: References: <5ad0dd8a.0307111151.4a08f95a@posting.google.com> <1LEPa.9034$nP.7178@newsfep4-winn.server.ntli.net> <5ad0dd8a.0307120426.226775f1@posting.google.com> <5ad0dd8a.0307130417.41548778@posting.google.com> <5ad0dd8a.0307131407.4955979e@posting.google.com> NNTP-Posting-Host: arctic.cse.msu.edu X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Xref: archiver1.google.com comp.lang.ada:40245 Date: 2003-07-13T20:06:30-04:00 List-Id: "Wojtek Narczynski" wrote in message news:5ad0dd8a.0307131407.4955979e@posting.google.com... > "Chad R. Meiners" wrote in message news:... > > > > "Functions" with side effects can only inject their side effect into > > > where they have been hardcoded to. > > This is wrong. Function have the capability to randomly introduce side > > effects just like any other section of code. > > Have you read the whole thread? I read all the root nodes, but I was responding to the single sentence which is incorrect. > > > In my experience, functions are more useful > > when they are pure. Sure there are times when a function cannot be pure, > > but sub-routine with a side-effect should be made a procedure in most cases. > > I agree that functions should be pure. But procedures cannot return an > unconstrained value. Again, this is what this thread is about. However, procedure's can return parse trees. > > I suggest that if you want to return composites from > > functions you should return a record type. > > > > type Composite(StringSize : Natural) is record > > User_Name : String(1..StringSize); > > Result : Boolean; > > end record; > > > > function Parse_User_Name(Item : String) return Composite; > > > > However, the following might also be a suitable procedure for the task > > Yes, this works, but causes code explosion, and memory copying (when > gathering all the parsed pieces together). This is what you can neatly > do in SML with tagged union types, by the way :-) You are prematurely trying to optimize. Furthermore, returning records does not automatically cause code explosion or extra memory copying. I have used similar techniques when writing recursive decent parsers. The code is both readable and concise (it is also fast enough for any test I cared to give it). If you are going to write any sort of language parser, I recommended browsing the source for GNAT's parser. It is probably overkill for what you want but you can get a lot of good ideas from it. The way it represents tokens is inspired. ;-) -CRM