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!postnews.google.com!s9g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: and then... (a curiosity) Date: Tue, 2 Sep 2008 08:06:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5c718c25-5921-4888-81c8-15a5381b3d40@s9g2000prg.googlegroups.com> References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> <09fad49e-95d9-4ffc-a0bd-d68d14a0f901@b2g2000prf.googlegroups.com> <1tlnjekp3wf5g$.19r86nar256t2.dlg@40tude.net> <48b968b4$0$31926$4d3efbfe@news.sover.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1220368009 3019 127.0.0.1 (2 Sep 2008 15:06:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 2 Sep 2008 15:06:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s9g2000prg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1869 Date: 2008-09-02T08:06:49-07:00 List-Id: On Aug 30, 8:35 am, "Peter C. Chapin" wrote: > Dmitry A. Kazakov wrote: > > I am unsure if the arguments of "and" are eager. You are a language lawyer, > > I am not. But I used to think that the eagerness of evaluation is rather > > unspecified, so that the compiler is free "not to care," when it optimizes > > the code, as Jeff Carter has pointed out. > > I thought all function arguments must be evaluated, but that it is > unspecified in which order this evaluation is done. Correct. If an argument to a subprogram contains another function call that has side-effects, that argument must be evaluated, and the compiler is generating incorrect code if it doesn't (which is *not* the case with "or else"). I think that if the compiler can determine that the only possible side effect would be to raise a predefined exception, the compiler doesn't have to actually do any evaluation--- the code isn't required to perform computations just for the sake of doing the computations. I'm not sure how far the predefined-exception thing goes, though. If you say if X = null or X.ID < 0 then ... -- "or", not "or else"! even though the right side is supposed to be evaluated, I suppose that a compiler could in theory generate code that doesn't bother to evaluate it if X is null, because there would be no point to reading that field (assuming no memory-mapped I/O is involved here!!). I think that behavior is allowed by the Implementation Permissions in 11.6, but of course it would be quite foolish to write code like this and rely on the optimization. -- Adam