Eiffel "Gotchas"

07 April 1998


Oops!

Gotcha #4 - array items

The Eiffel Library Standard Vintage 95 (ELS95) defines infix "@" as an alternative to 'item' for access to an element of an array. The description and the assertions are identical for infix "@" and for 'item'.

Suppose we have:

   a: ARRAY[INTEGER]
   ...
   !!a.make(1, 1) -- make with index from 1 to 1 (i.e. one element)
   a.put(1, 1) -- put '1' into position 1 of the array

Why can we then write this instruction...

   print(a.item(1))

..but not this one...

   print(a@1)

ANSWER


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

Eiffel "Gotchas"