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,ASCII-7-bit 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 09:48:57 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> <57qdnfULQ9tzKCHVnZ2dnUVZ_tHinZ2d@comcast.com> Reply-To: stefan-lucks@see-the.signature NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: tigger.scc.uni-weimar.de 1220337422 127 141.54.178.228 (2 Sep 2008 06:37:02 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Tue, 2 Sep 2008 06:37:02 +0000 (UTC) X-X-Sender: lucks@medsec1.medien.uni-weimar.de In-Reply-To: <57qdnfULQ9tzKCHVnZ2dnUVZ_tHinZ2d@comcast.com> Xref: g2news1.google.com comp.lang.ada:1858 Date: 2008-09-02T09:48:57+02:00 List-Id: On Mon, 1 Sep 2008, Steve wrote: > If short circuit evalution is permitted then more complex logic is required > to assure that both arguments are evaluated: > > resultA := A(x); > resultB := B(z); > if resultA and resultB then > ... do something > end if; If I actually require to run both functions A and B, I always write something like the above (typically inside a declare ... begin ... end), because I think that makes my intention clearer than by just writing "and" (or "or"). > With Ada you can choose whether or not you want short circuit evaluation. > If you require short circuit evaluation you must convey that information to > the compiler. If you do not require short circuit evaluation you can convey > that information as well. The more the compiler knows about your > requirements, the greater the potential for optimization. True. But the case that you want both expressions to be evaluated is a rare exception. On a *logic* level, "A and B" implies "if A is false, the result is false, regardless of B". So short-circuit evaluation is a natural and good thing for a programming language, and it is regrettable that Ada needs a more complex syntax for this. (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.) But, as others pointed it: IF the default "and" supported short-circuit-evaluation, THEN this "and" could not be an ordinary Ada operator. At the language semantic level, it is much more reasonable to treat "and" like any other operator or function, such as "+" and "-". So the inventors of Ada decided on a special syntax for short-circuit evaluation. But I wish Ada would support some sort of lazy evaluation for subprogram arguments. So long Stefan -- ------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------ Stefan dot Lucks at uni minus weimar dot de ------ I love the taste of Cryptanalysis in the morning! ------