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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a00006d3c4735d70 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-25 13:12:42 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!priapus.visi.com!orange.octanews.net!news.octanews.net!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "Alexandre E. Kopilovitch" Newsgroups: comp.lang.ada Subject: Re: In-Out Parameters for functions Date: Mon, 26 Jan 2004 00:02:45 +0300 (MSK) Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1075065015 44891 80.67.180.195 (25 Jan 2004 21:10:15 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Sun, 25 Jan 2004 21:10:15 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: ; from Robert A Duff at 24 Jan 2004 16:57:08 -0500 X-Mailer: Mail/@ [v2.44 MSDOS] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.3 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:4796 Date: 2004-01-26T00:02:45+03:00 Robert A Duff wrote: > > Look at this formulae: > > > > F(A) + G(A); > > > > If F is permitted to change value of A then the result of the formulae may > > depend on order of computation. And this is obviously dangerous, because the > > formulae looks as typical mathematical expression, where this effect usually > > is not anticipated. > > That might be a good argument against side effects in functions, but > Wojtek Narczynski is asking why, given that side effects in functions > are allowed in Ada, is it damaging to allow side effects on 'in out' > parameters. The F and G functions above might both write upon global > variable X. How could writing upon parameter A be any worse? The F and G functions may both update global variable X, but neither of them uses that X for computing the result, and this is what makes difference. Commonly, if several functions may be used in the same expression then they either update some global variable or use it for computing result, but not both. That is, if one of them updates a global variable then others should not use this variable for computation of their results. So, writing upon global variables in functions may be safe enough - while we honor the above rule. But parameters of a function are expected to participate in the computation of the result, and this is common case. So, even a particular parameter in a function is not used for computation of the result of *this* function, it easily may be passed to another function within the same expression and influence its result. Therefore, IN OUT parameters in functions will not be worse than the ability of functions to change global variables if we forbid use of such functions in expressions, that is: If at least one parameter of a function is in IN OUT mode then the function cannot be used in a compound expression. This function's call must always constitute the whole RHS of an assignment. or less restrictive rule: If at least one parameter of a function is in IN OUT mode then in any expression in which this function is called all other calls may be for parameterless functions only. Alexander Kopilovitch aek@vib.usr.pu.ru Saint-Petersburg Russia