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-Thread: 103376,1e369abf7da96fac X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.211.195 with SMTP id ne3mr629096pbc.2.1326454081010; Fri, 13 Jan 2012 03:28:01 -0800 (PST) Path: lh20ni177213pbb.0!nntp.google.com!news2.google.com!postnews.google.com!h13g2000vbn.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Pure function aspect?... Date: Fri, 13 Jan 2012 03:01:35 -0800 (PST) Organization: http://groups.google.com Message-ID: <26153f03-40a0-4101-a9aa-b15f90cb0b69@h13g2000vbn.googlegroups.com> References: <1d74a186-2599-4de5-af49-ffca2529ea96@do4g2000vbb.googlegroups.com> <18gmy0hbklhv5.swfwyybigqv2$.dlg@40tude.net> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 X-Trace: posting.google.com 1326454080 26397 127.0.0.1 (13 Jan 2012 11:28:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 13 Jan 2012 11:28:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h13g2000vbn.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALERCFNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:10.0) Gecko/20100101 Firefox/10.0,gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-01-13T03:01:35-08:00 List-Id: On Jan 13, 8:45=A0am, "Dmitry A. Kazakov" wrote: > On Thu, 12 Jan 2012 18:00:05 -0600, Randy Brukardt wrote: > > "Martin" wrote in message > >news:1d74a186-2599-4de5-af49-ffca2529ea96@do4g2000vbb.googlegroups.com..= . > >> Now Ada has bitten the bullet and allowed "in out" mode parameters in > >> functions, is it time to allow users to contract the other extreme and > >> allow a function to be declared Pure (no state changes, not even > >> hidden ones)? e.g. > > >> package P is > >> =A0 type T is tagged private; > >> =A0 function Pure_F =A0 (Self : T) return Integer > >> =A0 =A0 =A0with Pure; > >> =A0 function Impure_F (Self : T) return Integer; > >> private > >> =A0 type T is tagged record > >> =A0 =A0 =A0I : Integer :=3D 0; > >> =A0 end record; > >> end P; > > >> Functions with a Pure contract would be allowed to call other > >> functions with pure contracts, read values/parameters but promise to > >> change nothing (not even via 'tricks' a la random number generator!!). > > > We've argued this for a long time within the ARG, and we haven't been a= ble > > to get a real consensus. This discussion goes back to Ada 79 (which is = even > > before I got involved in Ada) -- early drafts of Ada had both functions > > (which were what we now call pure) and value-returning procedures (whic= h > > were not). The concern was that there was not a clear line between them= , and > > moreover there are many sorts of functions that are "logically" pure bu= t > > still do change things (the "memo function" being the banner carrier fo= r > > that idea). > > I think that the problem may be resolved by considering the contexts wher= e > the function is pure. There is no absolutely pure functions, any one is > impure because it returns something, pumps stack etc. The result is taken > out of consideration, so are local variables etc. There should be some > syntax for specifying what is not touched at the given level of "purity" > and what is. [snip] Care to mock up an example of the levels you had in mind? Is it something like (and stealing Randy's "Global"): function F1 (P1 : T1; P2 : T2) return Boolean with Pure =3D> (Global, P1); -- promise to not change globals or parameter P1, might tamper with P2 function F1 (P1 : T1; P2 : T2) return Boolean with Pure =3D> (all); -- promise to not change anything (other than subprogram local objects) function F1 (P1 : in out T1) return Boolean with Pure =3D> (Global); -- promise to not change anything other than subprogram local objects or parameters A function with no pure aspect might be equivilent of: function F1 (P1 : T1; P2 : T2) return Boolean with Pure =3D> (null); -- no promise to not change anything local, global or parameter -- Martin