Pipo
Pipo

Reputation: 5093

eiffel across an_iterable as vs is

I didn't find the documentation about the difference between is and as

I'd like to implement an iterator something similar to this MAP, I'd like to know what TYPE is returned with the is keyword and with the as one.

Upvotes: 1

Views: 98

Answers (1)

Alexander Kogtenkov
Alexander Kogtenkov

Reputation: 5810

The version with is is a shortcut when the only feature called on the loop cursor is item. The shortcut removes the need to call the query explicitly. So, the following two versions are semantically equivalent:

across foo as x loop ... x.item ... end
across foo is x loop ... x ... end

In other words, the second version could be seen as automatically translated into

across foo as _x loop ... _x.item ... end

where _x is inaccessible and x stands for _x.item.

The type of x in the first version is ITERATION_CURSOR [G]. In the second version, it is the type of {ITERATION_CURSOR [G]}.item, i.e. G.

In fact, the type of the cursor is derived from the type of query new_cursor called on the object on which the iteration is performed. However, any additional features available in this cursor type are accessible only when using the complete iteration form of a loop with as and are inaccessible when using the shortcut form with is.

Upvotes: 2

Related Questions