As you noticed, the words you are looking for are not “short”. Short circuit evaluation means that in the expression
e1 || e2
if the expression e1 is evaluated as something that represents the truth, then there is no need to evaluate e2 . Both C and Perl use a short circuit rating.
I know the difference you make in two different versions of a short circuit OR, but in twenty years of working in programming languages I have never seen these things be called. The Perl version is quite popular in dynamic languages, for example, Icon, Lua, Scheme.
The Perl version is almost expressed in C:
e1 ? e1 : e2
Unfortunately, this version can evaluate e1 twice, depending on the optimizer - and if e1 has side effects or if the compiler cannot determine if there can be side effects, then the compiler must evaluate it twice. This defect can be fixed by associating the value of e1 with a new local variable, but this requires a GNU extension.
C behavior can be emulated in Perl with
!!(e1 || e2)
Norman ramsey
source share