DynBindModel: Difference between revisions
| Line 253: | Line 253: | ||
====Definition of the naming function==== | ====Definition of the naming function==== | ||
The trivial function <math>S_0\,</math> is just an empty set. It remains to define <math>S_m\,</math> for <math>m>0\,</math> given that we know <math>S_{m-1}\,</math>. This is done by showing what <math>\beta_{ S_m } \left( C_q \mapsto C_p \right)</math> evaluates to for <math>q\leq m\,</math> and <math>p\leq m\,</math>. There are two trivial cases. When <math>q>p\,</math> it evaluates to the empty set and when both <math>p\,</math> and <math>q\,</math> are smaller than <math>m\,</math>, it is defined by <math>\beta_{ S_{m-1} } \left( C_q \mapsto C_p \right)</math>. | |||
A little more interesting is <math>\beta_{ S_m } \left( C_m \mapsto C_m \right)</math> | A little more interesting is <math>\beta_{ S_m } \left( C_m \mapsto C_m \right)</math> | ||
Revision as of 23:00, 16 November 2006
Author: Matthias Konrad
Related articles:
- Example for the model shown: DynBindModelExamples
- Haskel module that implements the model: DynBindModelHaskell
Motivation:
Eiffels dynamic binding is somewhat more complex than that of other languages. Its structure is still very simple and is described by the function:
Function contains both the static and dynamic binding part of the language. In the following feature:
f (a: ANY)
do
print (a.out)
end
The static binding part of call a.out can be decribed as:
Namely an evaluation of with a tuple containing the static type of the call and the name. The result of this is a function. This function evaluated at runtime will yield the right feature according to the dynamic type of a.
In the rest of this text, the construction of the function is shown, based on any given valid Eiffel system.
There is a special wiki page that shows an example calculation of the dynamic binding function for a complete system: DynBindModelExamples
Notation
This wiki uses the notation introduced in these slides by Prof. Jean-Raymond Abrial (ETHZ): notation The only difference is the symbol for override which is (This will be changed as soon as possible). The function operator is used for partial functions.
Some operators
We will give some rather informal definitions for the set-theoretic operators used here.
Operator: identity
Operator: inverse
Operator: domain
Operator: range
Operator: range restriction
is equivalent to:
Example:
Operator: override
is equivalent to:
Example:
Operator: union
is equivalent to:
Example:
is equivalent to:
Some fundamentals
We introduce the operator as the "ancestor of" and as "descendant of" operator.
Without loss of generality we can say that any Eiffel system is a set of classes such that if . In practice class will allways be class ANY but this is not of importance here.
The function:
Yields the features declared in a given class.
Yields the renamings of the different parent parts by a class:
gives the renamings in class D for the inherited class B.
Gives the classes from which a given class inherits:
Gives the base classes of the of class A.
Gives all the selected feature names of an inherited class of a class.
Furthermore we give the following shortcuts:
- for
- for
- for
- for
An example
For the following System:
class B feature f do ... end end |
class C inherit B rename f as f1 redefine f1 end feature f1 do ... end end |
class D inherit C B rename f as f2 redefine f2 select f2 end B rename f as f3 redefine f3 end feature f2 do ... end f3 do ... end end |
We get:
The naming function
The naming function shows for two classes how their feature names are related to each other:
In the previous example class C renames feature f to f1. thus evaluates to f1. evaluates to f2 the selected feature in class D. In this section the naming function of a system is shown:
The range of is a function. This means, that every name is mapped to just one name. The naming function doesn't only reflect the renaming semantics of a system but also the selects.
We will give a recursive definition of . Meaning that we will give given that we already now
This is valid since:
An example
Before we proceed to the definition we show how looks like for the example from the previous section:
|
|
|
|
| |
|
|
Definition of the naming function
The trivial function is just an empty set. It remains to define for given that we know . This is done by showing what evaluates to for and . There are two trivial cases. When it evaluates to the empty set and when both and are smaller than , it is defined by .
A little more interesting is
As a helper function we also need these functions:
And finally the naming function:
Where
And:
The dynamic binding function
With the naming function defined it is surprisingly simple to give the dynamic binding function. To make it even easier we define the function:
With this function defined we can derive :
What remains is to define . As with the naming function we do it recursively. We define based on since the following holds:
The definition: