eiffel

why here 'or' follows with an 'else', what kind of branches do they make?


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?


Solution

  • 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.