Short-circuit evaluation, also called minimal evaluation or McCarthy evaluation after John McCarthy, is the rule by which some Boolean operators in some programming languages evaluate their second argument only when the first argument does not already settle the result. When the first argument of an AND is false the whole expression must be false, and when the first argument of an OR is true the whole expression must be true, so the second operand is never run. Languages with lazy evaluation such as Lisp, Perl and Haskell short-circuit by default, while Ada, Java and Delphi offer both short-circuit and ordinary Boolean operators. Exclusive or cannot be short-circuited because both operands are always needed. Because the operators behave as control structures and introduce a sequence point in C and C++, side effects in the first operand always happen before the second is considered. The technique has also been criticized for complicating formal reasoning about programs.
Connections
Credited To
Source Short-circuit evaluation (Wikipedia)
In Field
Source Short-circuit evaluation (Wikipedia)
Sources
Short-circuit evaluation (Wikipedia)
In Group: Compiler and Language Implementation Techniques, Lead section
the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression
In Field: Programming Language Theory, Lead section
the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression
Credited To: John McCarthy, Lead section
McCarthy evaluation (after John McCarthy)
View the SourceReader Challenges (0)
No disputes yet. Spotted an error or a better source? Open the first one.
Sign in to dispute this or suggest a correction.