Short-circuit evaluation

In programming languages with lazy evaluation (Lisp, Perl, Haskell), the usual Boolean operators short-circuit.

The use of short-circuit operators has been criticized as problematic: The conditional connectives — "cand" and "cor" for short — are ... less innocent than they might seem at first sight.

The generalized definition above accommodates loosely typed languages that have more than the two truth-values True and False, where short-circuit operators may return the last evaluated subexpression.

[2]: §2.9.3 The following simple left-to-right evaluator enforces a precedence of AND over OR by a continue: Short-circuit logic, with or without side-effects, have been formalized based on Hoare's conditional.

[11] Short-circuiting can lead to errors in branch prediction on modern central processing units (CPUs), and dramatically reduce performance.

[clarification needed] Some compilers can detect such cases and emit faster code, but programming language semantics may constrain such optimizations.

[citation needed] An example of a compiler unable to optimize for such a case is Java's Hotspot virtual machine (VM) as of 2012.