HPCC-ECL 逻辑运算符 - 为什么 OR 不短路?
HPCC-ECL Logical Operators - Why is OR not short-circuiting?
The documentation表示OR逻辑运算符应该短路:
If the probability of occurrence is known,
you should order them from the most likely to occur to the least likely to occur, because once any part of a compound
OR condition evaluates to TRUE, the remainder of the expression is bypassed
除非我弄错了,否则这不是预期的行为。
当它必须评估 returns TRUE 的表达式时,它似乎会继续评估 OR 之后的下一个表达式。
似乎对于 TRUE 的硬编码值,它按预期工作。
我是不是做错了什么或者误解了code/documentation?
考虑以下代码:
IMPORT STD;
superFileName := 'temp::superFile';
fileName := 'temp::regularFile';
returnsTrue := ~STD.File.FileExists(fileName, TRUE); // File does not exist, so will return true as expression is negated
getSubCount := NOTHOR(STD.File.GetSuperFileSubCount(superFileName)) > 0; // "Could not locate superfile: thor::nonExistent"
deleteFile := STD.File.DeleteLogicalFile(fileName);
deleteSuperFile := STD.File.DeleteSuperFile(superFileName);
SEQUENTIAL(
deleteFile,
deleteSuperFile,
OUTPUT(returnsTrue), // true
OUTPUT(IF ((TRUE OR getSubCount), 'true', 'false')), // 'true'
OUTPUT(IF ((returnsTrue OR getSubCount), 'true', 'false')), // "Could not locate superfile: thor::temp::superFile"
);
The documentation表示OR逻辑运算符应该短路:
If the probability of occurrence is known, you should order them from the most likely to occur to the least likely to occur, because once any part of a compound OR condition evaluates to TRUE, the remainder of the expression is bypassed
除非我弄错了,否则这不是预期的行为。 当它必须评估 returns TRUE 的表达式时,它似乎会继续评估 OR 之后的下一个表达式。 似乎对于 TRUE 的硬编码值,它按预期工作。
我是不是做错了什么或者误解了code/documentation?
考虑以下代码:
IMPORT STD;
superFileName := 'temp::superFile';
fileName := 'temp::regularFile';
returnsTrue := ~STD.File.FileExists(fileName, TRUE); // File does not exist, so will return true as expression is negated
getSubCount := NOTHOR(STD.File.GetSuperFileSubCount(superFileName)) > 0; // "Could not locate superfile: thor::nonExistent"
deleteFile := STD.File.DeleteLogicalFile(fileName);
deleteSuperFile := STD.File.DeleteSuperFile(superFileName);
SEQUENTIAL(
deleteFile,
deleteSuperFile,
OUTPUT(returnsTrue), // true
OUTPUT(IF ((TRUE OR getSubCount), 'true', 'false')), // 'true'
OUTPUT(IF ((returnsTrue OR getSubCount), 'true', 'false')), // "Could not locate superfile: thor::temp::superFile"
);