Difference between revisions of "Minor-ECMA-problems"

(Agent types)
(Agent types)
Line 224: Line 224:
  
 
we could write
 
we could write
 
+
<code>[N, eiffel]
 
f (STRING): INTEGER
 
f (STRING): INTEGER
 +
</code>
  
 
Calling this f would be easy:
 
Calling this f would be easy:

Revision as of 12:23, 25 September 2006

Definition: Coupled name

Motivation

There are several situations in which the ECMA standard uses unfoled forms as a vehicle to describe semantics. When this unfoled forms need names, like in Precursor, inline agents and not isolated features. These names have an influence on the semantics of the system. An example:

class
   B
feature
   f 
      do 
         (agent do g := g + 1; print (g) end).call ([]) 
      end
   g: INTEGER
end
class
   D
inherit
   B
      rename f as f1, g as g1, select f1, g1 end
   B
      rename f as f2, g as g2 end
end

It feels natural to unfold class B first and then inherit D from its unfolded form before D is unfolded:

class
   B
feature
   f 
      do 
         (agent fict_name).call ([]) 
      end
   g: INTEGER
 
   fict_name 
      do 
         g := g + 1; print (g) 
      end
end
class
   D
inherit
   B
      rename f as f1, g as g1, select f1, g1 end
   B
      rename f as f2, g as g2 end
end

The call-equivalent of the inline-agent (here named fict_name) has a call to g which has several potential versions in D. Hence this is not a valid system. The same problem can occur with calls to Precursor. The programmer cannot do anything about it since he has no knowledge of the fictous name of the call-equivalent. There should have been some coupling between the name f and the name of the call-equivalent of the inline-agent. The unfolded form of a renaming would then also rename all the coupled name (a precice definition follows). Our final example woul become:

class
   B
feature
   f 
      do 
         (agent fict_name).call ([]) 
      end
   g: INTEGER
 
   fict_name 
      do 
         g := g + 1; print (g) 
      end
end
class
   D
inherit
   B
      rename f as f1, fict_name1, g as g1 
      redefine f1, fict_name1
      select f1, g1, fict_name1 end
   B
      rename f as f2, fict_name as fict_name2, g as g2 
      redefine f2, fict_name2 end
feature
   f1 do (agent fict_name1).call ([]) end
   fict_name1 do g1 := g1 + 1; print (g1) end
 
   f2 do (agent fict_name2).call ([]) end
   fict_name2 do g2 := g2 + 1; print (g2) end      
end

The redefinitions of f1, fict_name1, f2 and fict_name2 come with the unfolded form of not isolated features. Please note that the unfolded form of D needed to select fict_name1 or fict_name2 for the system to be valid. But this select has no semantic influence.

Definition

A feature name can be coupled to the name of an other feature.

A complex example with precursor

class
   A
feature
   a: INTEGER   
   f do a := a + 1 end
   g do f end
class
   B
inherit
   A redefine g end
feature
   g do Precursor end
end
class
   D
inherit
   B 
      rename a as a1, f as f1, g as g1 
      select a1, f1, g1 end
   B
      rename a as a2, f as f2, g as g2 end
feature
end

Unolded forms of A and B:

class
   A
feature
   a: INTEGER   
   f do a := a + 1 end
   g, gp do f end
class
   B
inherit
   A redefine g end
feature
   g do gp end
end

Unfolded form of D:

class
   D
inherit
   B 
      rename a as a1, f as f1, g as g1, gp as gp1
      redefine f1, g1, gp1 end
      select a1, f1, g1, gp1 end
   B
      rename a as a2, f as f2, g as g2, gp as gp2
      redefine f2, g2, gp2 end
feature
   f1 do a1 := a1 + 1 end
   g1 do gp1 end
   gp1 do f1 end
 
   f2 do a2 := a2 + 1 end
   g2 do gp2 end
   gp2 do f2 end
end

New Behaviour of renaming and select

The unfolded form of a renaming is the renaming itself plus the unfolded forms of the renamings of all the coupled names.

Precursor

The current definition of the Precursor semantics in the ECMA standard (8.10.11)

Agent types

The classes ROUTINE, PROCEDURE, FUNCTION and the new class PREDICATE do not nicely fit in to the Eiffel language. Reasons:

  • They do not reflect the fact, that an agent can refer an attribute. An attribute is not a routine.
  • They do kind of contradict the uniform access principle.
  • They are difficult to define. It is difficult to understand, why it is so difficult to define an agent type when it is so easy in functional languages!
  • Specially the first generic Paramter of ROUTINE is difficult to understand and, if I am not wrong, never used.
  • The standard conformance rules simply do not work nice for agent types. They introduce a type hole that can only be detected at runtime, and even then, only if precondition assertions are enabled.

I will give an example of an other mechanism:

Instead of writing

f: FUNCTION [ANY, TUPLE [STRING], INTEGER]

we could write

f (STRING): INTEGER

Calling this f would be easy:

i: INTEGER ... i := f ("hello")

We could also write:

i: INTEGER ... i := agent f ("hello")




Instead of writing:

f: FUNCTION [ANY, TUPLE [STRING], ANY]

we would write:

f (STRING): ANY