Eiffel "Gotchas"

22 May 1997


Gotcha #7 - Answer and Explanation

Here's the question again:

How can you break a valid, working program by adding a single pair of parentheses that do not affect the order of computation?


Here's how:

   -- this works:
   a.some_procedure
   b.some_function.some_procedure

   -- this does not compile
   a.some_procedure
   (b.some_function).some_procedure

   -- this works again
   a.some_procedure;
   (b.some_function).some_procedure

The second example fails because the parser ignores line endings, and treats "some_procedure(b.some_function)" as a function call with one argument.

The fix is to separate the instructions with a semicolon, which makes it clear to the parser when we have reached the end of the first instruction.


Eiffel and NICE are registered trademarks of the Nonprofit International Consortium for Eiffel.

Eiffel "Gotchas"