I am trying to implement does_key_exist, I thought the code below would do it. But I get a compilation error key not found line: Result := not (x.key = key)
does_key_exist(key: attached STRING):BOOLEAN
do
Result := not data.item(hash(key)).for_all (agent (x:like pair_at):BOOLEAN
do
Result := not equal(x.key, key)
end)
end
definitions:
pair_at(key:attached STRING):TUPLE[key:STRING;value: like value_at]
require
does_key_exist(key)
deferred
ensure
end
list_at(key:STRING) : LINKED_LIST[like pair_at]
require
does_key_exist(key)
end
data : ARRAY[like list_at]
Inline agents in Eiffel have access to attributes of the current object, but not to locals or arguments, as they are just syntactic sugar for "normal" agents, that are constructed upon normal features of the class. The latter do not have any access to the locals or arguments of the other features. So the code can be corrected by passing the argument explicitly:
does_key_exist (key: STRING): BOOLEAN
do
Result := not data.item (hash (key)).for_all
(agent (x: like pair_at; y: STRING): BOOLEAN
do
Result := not equal(x.key, y)
end
(?, key))
end