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!b2g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: and then... (a curiosity) Date: Fri, 29 Aug 2008 15:28:16 -0700 (PDT) Organization: http://groups.google.com Message-ID: <09fad49e-95d9-4ffc-a0bd-d68d14a0f901@b2g2000prf.googlegroups.com> References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> 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 1220048896 11851 127.0.0.1 (29 Aug 2008 22:28:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 29 Aug 2008 22:28:16 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b2g2000prf.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:1825 Date: 2008-08-29T15:28:16-07:00 List-Id: On Aug 29, 2:06 pm, mockturtle wrote: > Dear.all, > today while I was writing in my favorite language > (PERL with C extensions, of course :-)))) I wondered why in Ada the > "shortcut and" is "and then", while the simple "and" has not > a shortcut behaviour. My curiosity stems from the fact that > I am not able to envision any situation where the "non shortcut" > version would preferable, but I immagine that there was some > reason for this choice. Do anyone have any hint? Aside from Samuel's comment (sometimes you want both sides evaluated), there are some very important differences. "and" is a predefined function and can be used wherever a function can (you can rename it, pass it as parameter for a generic formal function, etc.). Besides the "and" on Booleans, there are predefined "and" functions on arrays of Booleans and on modular types [both of those do bitwise AND's]. You can define your own "and" on other types if you like. Like every other function, the use of "and" requires that all (both) of its arguments be evaluated. The language also defines "or", "xor", and "not" with similar properties. "and then" is not a function, however, and has none of these properties. To make "and" [and "or"] on two Booleans behave like the short-circuit form would introduce a major inconsistency into the language. -- Adam