Difference between revisions of "Agent problems"

m
 
m
Line 2: Line 2:
  
 
<code>[eiffel,N]
 
<code>[eiffel,N]
foo (f: FUNCTION [A, TUPLE [B], C])
+
foo (f: FUNCTION [A, TUPLE [B], C]): C
 +
  local
 +
      l_f: FUNCTION [A, TUPLE, C]
 +
  do
 +
      Result := l_f.item ([])
 +
  end
 
</code>
 
</code>
  
Line 9: Line 14:
 
* have at least one open argument. The type of it needs to be a descendant of class B.
 
* have at least one open argument. The type of it needs to be a descendant of class B.
 
* refer to a feature with a return type that is a descendant of class B.
 
* refer to a feature with a return type that is a descendant of class B.
 +
At the same time feature foo gives almost no guarantees about how it will use agent f. It calls the agent without passing any arguments. This is not detected by the type system but will certainly end in runtime failures. This is a very unfortunate situation. The Eiffel agent mechanism is quite verbose, the user has to type in a lot of typing information. At the same time the type system gives the programmer no safety.

Revision as of 12:41, 20 November 2006

The following feature expects as its formal argument an agent:

foo (f: FUNCTION [A, TUPLE [B], C]): C
   local
      l_f: FUNCTION [A, TUPLE, C]
   do
      Result := l_f.item ([])
   end

By giving its formal argument a type, a feature specifies what it expects of the actual arguments. Feature foo expects the passed agent to:

  • refer to a feature of a descendant of class A.
  • have at least one open argument. The type of it needs to be a descendant of class B.
  • refer to a feature with a return type that is a descendant of class B.

At the same time feature foo gives almost no guarantees about how it will use agent f. It calls the agent without passing any arguments. This is not detected by the type system but will certainly end in runtime failures. This is a very unfortunate situation. The Eiffel agent mechanism is quite verbose, the user has to type in a lot of typing information. At the same time the type system gives the programmer no safety.