1

I saw a really confusing statement when I read OMOHUNDRO's article about balltree construction algorithms:

--...
if pq.empty or else 
btm.bvol <= pq.top.bvol then done:=true
--...

I don't know how could an 'else' follows 'or' and there is empty after the 'or'. could someone reorganize it and explain the branches of this statement?

SZYoo
  • 147
  • 7

1 Answers1

1

The and and or operators in Eiffel are eager: they will evaluate both operands.

Meanwhile, and then and or else are the corresponding short-circuiting operators. They will cease evaluation as soon as the result of the boolean expression is known.

In the example given, if pq.empty is true, btm.vol <= pq.top.bvol will not be evaluated, since the result of the expression is already known to be true, regardless of the value of the second comparison.

Chris
  • 26,361
  • 5
  • 21
  • 42
  • In Eiffel the order of evaluation and eagerness of `or` and `and` is undefined: It may do the second, and skip the first. e.g. `if function_call() or true` will probably be optimised to not call the function. – ctrl-alt-delor Jul 16 '23 at 09:50