Re: and then... (a curiosity)
- From: Adam Beneschan <adam@xxxxxxxxxx>
- Date: Fri, 29 Aug 2008 15:28:16 -0700 (PDT)
On Aug 29, 2:06 pm, mockturtle <framefri...@xxxxxxxxx> 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
.
- Follow-Ups:
- Re: and then... (a curiosity)
- From: Dmitry A. Kazakov
- Re: and then... (a curiosity)
- From: Jeffrey R. Carter
- Re: and then... (a curiosity)
- References:
- and then... (a curiosity)
- From: mockturtle
- and then... (a curiosity)
- Prev by Date: Re: and then... (a curiosity)
- Next by Date: Re: OpenToken
- Previous by thread: Re: and then... (a curiosity)
- Next by thread: Re: and then... (a curiosity)
- Index(es):