Difference between revisions of "Agent problems"

m
 
m (Corrected typo from B to C)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[Category:ECMA]]
 +
{{UnderConstruction}}
 +
 
The following feature expects as its formal argument an agent:
 
The following feature expects as its formal argument an agent:
  
 
<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
 +
      l_f := f
 +
      Result := l_f.item ([])
 +
  end
 
</code>
 
</code>
  
Line 8: Line 17:
 
* refer to a feature of a descendant of class A.
 
* 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.
 
* 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 C.
 +
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.

Latest revision as of 04:30, 11 April 2007

Construction.png Not Ready for Review: This Page is Under Development!

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
      l_f := f
      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 C.

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.