From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a37:e211:: with SMTP id g17mr10770016qki.298.1608403254274; Sat, 19 Dec 2020 10:40:54 -0800 (PST) X-Received: by 2002:ac8:690f:: with SMTP id e15mr9916291qtr.100.1608403254111; Sat, 19 Dec 2020 10:40:54 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 19 Dec 2020 10:40:53 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=47.185.235.180; posting-account=zwxLlwoAAAChLBU7oraRzNDnqQYkYbpo NNTP-Posting-Host: 47.185.235.180 References: <5fdbde31$0$6455$426a74cc@news.free.fr> <86im8ylnj4.fsf@stephe-leake.org> <5fdde913$0$3238$426a74cc@news.free.fr> <7a72951a-5a0c-42d6-ad30-357a43883b6fn@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Ada syntax questions From: Andreas ZEURCHER Injection-Date: Sat, 19 Dec 2020 18:40:54 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:60894 List-Id: On Saturday, December 19, 2020 at 11:49:12 AM UTC-6, Dmitry A. Kazakov wrot= e: > On 2020-12-19 18:13, Andreas ZEURCHER wrote:=20 > > On Saturday, December 19, 2020 at 6:40:28 AM UTC-6, Dmitry A. Kazakov w= rote:=20 > >> On 2020-12-19 12:50, DrPi wrote:=20 > >>=20 > >>>> Why would you care?=20 > >>>=20 > >>> Calling a function can have side effects. Accessing an array or a=20 > >>> variable can't have side effects.=20 > >>=20 > >> Untrue. Both array and variable access have side effects on the=20 > >> registers, on the cache, on the process memory paging, in the form of= =20 > >> exception propagation etc. Even direct effects on the outside world ar= e=20 > >> possible when using machine memory load instructions. E.g. on some=20 > >> hardware reading memory at the specific address location means physica= l=20 > >> serial input.=20 > >=20 > > Dmitry, DrPi here is referring to side-effects as viewed from the funct= ional-programming paradigm's perspective. Some programming languages have a= "pure" designator (usually the keyword: pure) that assures that this subro= utine and all invoked subroutines therein are pure (i.e., have no FP side e= ffects).=20 > >=20 > > The side effects of which you speak are at the machine-code level: e.g.= , setting/clearing comparison flag(s), setting/clearing carry flag, setting= /clearing overflow/underflow flag(s), evictions from L1/L2/L3 cache, (on RI= SC processors) latching an address in preparation of a load/store, and so f= orth. None of these are externally observable side effects from FP's perspe= ctive above the machine-code level. DrPi's FP goals are valid. > Memory paging is pretty much observable.=20 >=20 > What you are saying is a question of contracts. The contract must=20 > include all effects the user may rely on. The contract of a function may= =20 > include observable effects or have none (to some extent).=20 >=20 > If contracts were indeed relevant to the syntax then functions without=20 > contracted side effects must have been called using [] instead of ().=20 >=20 > No? Then it is not about the contracts. As witnessed by your final sentence quoted below and multiple other replies= along this thread, the key tactical advantage of Ada's usage parentheses f= or array indexing is to accomplish a switcheroo days, weeks, months, years,= or decades later: to substitute a function invocation later for what was = formerly an array index. Cute trick. Advantageous in some situations. Bu= t for people like DrPi who seek contractual assurance of FP-purity of (all?= ) invoked functions (and overt declaration of impurity of other functions),= Ada's 1) implicit switcheroo there in unfortunate combination with Ada's 2= ) lack of flamboyantly advertising impurity in the replacement function doe= s in fact violate the purity portion of the contract that the mere offset-i= nto-array implementation had=E2=80=94and indeed =E2=80=A2overtly=E2=80=A2 d= eclared in its specification as a mere offset-into-array operation-of-unque= stionable-purity. It is okay for a 1970s Ada to not foresee this, because = FP was not a mainstream programming practice back then. (But, btw, it is n= ot as okay for there to be a lack of HOLWGn each decade since the 1980s to = revisit whether HOLWG1 forgot anything, where n>1, n=E2=88=88=E2=84=A4.) T= his 1970s faux pas in letting a silent slip-streamed switcheroo into the co= re contract-definition declaration mechanism of Ada (not comments! btw, tis= k tisk) is merely some tarnish that an AdaNG (next-generation Ada) would fi= x: e.g., by mandating that all functions (and procedures?) shall be overtly= declared & enforced to be pure or impure, which would then mean that only = pure functions could substitute for array indexing is the ()-based switcher= oo on which so many replies in this thread hang their hat. And DrPi would = enjoy seeing the compile-time errors emerge when some cavalier programmer o= ver yonder changed an array index to an =E2=80=A2impure=E2=80=A2 function i= nvocation as contract violation. The cute implicit switcheroo isn't evil, = but the lack of compile-time detection of impurity in the switcherooed func= tion is what is evil. (While drinking tea as none of my business as the meme goes,) I actually cl= aim that Ada's usage of parentheses for array indexing was merely happensta= nce copying the Fortran-PL/I-PL/1-Simula-PL/P-PL/M/CHILL heritage popular i= n the 1970s*, which itself mimicked mathematics' usage of parentheses aroun= d each matrix. Because there was no way to represent mathematics' subscrip= ts as the notation for indexing, the next best punctuation for matrix/vecto= r indexing was borrowed: parentheses. * as opposed to the ALGOL58's, ALGOL60's, ALGOL68's, BCPL's, C's square bra= ckets, so the big split was somewhere around 1957 for FORTRAN (and whicheve= r predecessor languages influenced it) and 1958 for ALGOL58 (and whichever = predecessor languages influenced it), as opposed to APL's =E2=8D=B3 iota wh= ich uses neither parentheses nor square brackets to pull out an element sin= ce 1966 > >> All these effects are either desired parts of the implementation or el= se=20 > >> bugs to be fixed. If desired, why do you care?=20 > >>>> You seem to be implying this is bad; why?=20 > >>>=20 > >>> Reading the code can't tell you the writer's intentions.=20 > >> What intentions?=20 > >=20 > > The intentions of the Ada programmer to design an overtly FP-pure or ei= ther an overtly FP-impure subroutine or an FP-impure subroutine by happenst= ance. > Intentions are constraints expressed by contracts. Everything else is=20 > implementation details.=20 >=20 > Ada programmers are not motivated by pureness of a subroutine. These are= =20 > totally irrelevant. What is relevant is the strength of the contract.=20 > Functions without side effects are preferable just because they have=20 > weakest preconditions and strongest postconditions. Side effects weaken= =20 > postconditions.=20 >=20 > For the clients these are of no interest, even less to deserve a=20 > different syntax. The user must simply obey the contract whatever it be,= =20 > ignoring the implementation as much as possible.=20 >=20 > Ada's unified syntax is a great help here. I quite often replace arrays= =20 > and variables with functions. It would be great if literals were fully=20 > equivalent to parameterless functions. > --=20 > Regards,=20 > Dmitry A. Kazakov=20 > http://www.dmitry-kazakov.de