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,99e73f65ea2533b9 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!nlpi057.nbdc.sbc.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: and then... (a curiosity) Date: Wed, 03 Sep 2008 11:56:15 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> <874p53bij6.fsf@willow.rfc1149.net> <94cc1ce3-59d1-41fa-9167-f3b60ddd2835@a1g2000hsb.googlegroups.com> <48bba264$1@news.post.ch> <48bce306$1@news.post.ch> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1220457375 17192 192.74.137.71 (3 Sep 2008 15:56:15 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 3 Sep 2008 15:56:15 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:Dt235yxjoLJkbv2oRXMYq+zJk5U= Xref: g2news1.google.com comp.lang.ada:1897 Date: 2008-09-03T11:56:15-04:00 List-Id: Brian Drummond writes: > On Tue, 02 Sep 2008 16:50:34 -0400, Robert A Duff > wrote: >>It seems to me that two cases come up in practise, for "A and [then] B". >>Either I don't care which gets evaluated first, and don't care whether >>or not both get evaluated, because there are no important side effects >>(that's "A and B"), or I care about order (that's "A and then B"). >> >>I never see cases where it is important that A and B both be evaluated. >> >>Counterexamples, please? ;-) Realistic ones, I mean. > > Given the speed penalty for branches, there are circumstances where it > is faster to evaluate both cases than branch around one. In that sense, > it would be important (for performance, rather than semantics) to > evaluate both cases. But that is properly the compiler's decision to > make. > > I don't think that's what you meant; I believe you meant "important for > semantics" Yes, that's what I meant. And I would like the compiler to worry about efficiency for me, although I admit that's not always feasible. > But it does illustrate that (I) "and then" (short circuit form, order > guaranteed) and (II) "and" (short circuit permitted, but not guaranteed, > order not guaranteed) are properly separate operations. > > For cases such as the logging example (semantics require both to be > evaluated) my personal choice would be to explicitly evaluate both, and > combine their evaluation results, as elsewhere in this thread. > > Is my understanding of Ada correct in expecting this is the only way to > guarantee evaluation of both? ( i.e. Ada handles "and" as (II) above) No. Ada guarantees that both arguments of "and" are evaluated. Of course if the compiler knows that evaluation has no effect, it doesn't need to generate any code -- that would be the case for "X > 0", for example. Ada allows the two operands to be evaluated in either order (but not in parallel, if that matters). So in the example you mention, "F(...) and G(...)" where the bodies of F and G write some output to a log file, both outputs will be written -- in some order, but not intermixed. - Bob