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,f3437064e1091fec X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-13 15:36:01 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: wojtek@power.com.pl (Wojtek Narczynski) Newsgroups: comp.lang.ada Subject: Re: What evil would happen? Date: 13 Jul 2003 15:36:00 -0700 Organization: http://groups.google.com/ Message-ID: <5ad0dd8a.0307131408.58f18f0d@posting.google.com> 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> NNTP-Posting-Host: 212.160.20.107 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1058135761 14484 127.0.0.1 (13 Jul 2003 22:36:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 13 Jul 2003 22:36:01 GMT Xref: archiver1.google.com comp.lang.ada:40243 Date: 2003-07-13T22:36:01+00:00 List-Id: "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? > 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. > In mathematics, functions only return single elements, which may be a > composite of some sort. Well, in the mathematical definition there is no "call" so there may not be a "return". Instead there are two sets... > I suggest that if you want 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 :-) > procedure Parse_UserName (Item : String; > UserName : out String; > NameSize : out Natural) ; This works fine for shor strings, but for longer there will be unnecessary storage allocation. Regards, Wojtek