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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,99e73f65ea2533b9 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed.freenet.de!news-lei1.dfn.de!news.uni-weimar.de!not-for-mail From: stefan-lucks@see-the.signature Newsgroups: comp.lang.ada Subject: Re: and then... (a curiosity) Date: Tue, 2 Sep 2008 12:50:38 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> <57qdnfULQ9tzKCHVnZ2dnUVZ_tHinZ2d@comcast.com> <48bd0003$1@news.post.ch> Reply-To: stefan-lucks@see-the.signature NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323584-958872072-1220352638=:10279" X-Trace: tigger.scc.uni-weimar.de 1220348322 17177 141.54.178.228 (2 Sep 2008 09:38:42 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Tue, 2 Sep 2008 09:38:42 +0000 (UTC) X-X-Sender: lucks@medsec1.medien.uni-weimar.de In-Reply-To: <48bd0003$1@news.post.ch> Xref: g2news1.google.com comp.lang.ada:1861 Date: 2008-09-02T12:50:38+02:00 List-Id: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323584-958872072-1220352638=:10279 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: 8BIT > > (Well, "A and B" also > > implies "if B is false, don't care about A", but in a programming language > > you can't have it both ways.) > > That is what I learned in my boolean arithmetic classes. It's either > way. There is no preference that the left parameter if more important > then the right. A Human seeing "A∧0" won't evaluate A. And if you see > "f(x)∧g" you would probably evaluate g first as a variable is usually > easier to evaluate then a function. True. But, at the logic level, the Ada-statement if (X >= A'First) and (X <= A'Last) and (A[X]=Y) then ... else ... end if; should *not* raise a Constraint_Error if X < A'First or X > A'Last, but instead handle the "else" case. True enough, at the logic level the same should hold for if (A(x)=Y) and (X >= A'First) and (X <= A'Last) then ... end if; > It's all about those side effect which make order of evaluation so > important. Otherwise it should not matter. The bad thing is that Constraint_Error counts as a valid side effect here. Ideally, the program should check the other branches of the "and" expression, and only propagate the exception if none of them evaluates to false without raising an exception of its own. Consider a programm fragment like if X and Y then ... end if Assume Y raises a Constraint_Error if X is false. This appears to be a common bug pattern in Ada. I have seen this several times in Ada sourcecode, and *never* it was the programmer's intention to raise an exception if X is false ... except when an exception was raised explicitely in the else branch. Even then, the programmers typically expected the exception they raised there, not Constraint_Error. I admit, we will not get this "ideal" behavoiur in any usable programming language. What happens, e.g., if two different exceptions are raised when evaluating "A and B"? Which exception should be propagated? In the absence of this "ideal" behaviour, a short-circuit behaviour of "and" and "or" would eliminate a common bug pattern in Ada. I would consider it the lesser evil, compared to the current situation. > Note that once you add: > > pragma Inline (f); > > to the example above things become very interesting for the optimizer > ;-) (do remember that the optimizer will use goto without shame). Funny idea! ;-) But at the end, there are lots of gotos ("jumps", "branches") in assembler code, with or without pragma inline or optimisation. -- ------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------ Stefan dot Lucks at uni minus weimar dot de ------ I love the taste of Cryptanalysis in the morning! ------ --8323584-958872072-1220352638=:10279--