On Fri, 3 Apr 1998, Van Snyder wrote:
> Werner Schulz wrote:
>
> > I was not calling for turning Fortran into a language with
> > all keywords reserved, just maybe some local constraints.
> > I was thinking of the word SELF (this in C++) for object-oriented
> > programming which has some very useful properties that are
> > very hard to do in other ways.
>
> C++ uses this->. Ada 95 has no special name for "this" since
> it doesn't use the "send a message to an object" paradigm for
> object-oriented programming. Thus, no new concept, beyond those
> already present for the purpose of accessing dummy arguments,
> is needed.
>
> > The Fortran committee on OOP is not proposing SELF currently.
>
> Because it's not needed.
I have looked through the current J3 papers and cannot find a
specific sentence or example on how inheritance is deals with
the change of a type. There is only a construct called PASS_OBJ
which is obviously not type-safe.
All current OOP languages deal with inheritance in two ways, let me call
them the Ada95 and the C++ way.
Ada95 changes implicitily the types of all variables that have the
type of the parent-type when they are inherited in a new type.
So (now in F2000 notation):
TYPE, EXTENSIBLE :: Point
REAL :: x, y
CONTAINS
PROCEDURE :: Length
END TYPE Point
FUNTION Length( p )
TYPE(Point) :: p
REAL :: Length
Length = SQRT( p%x**2 +p%y**2 )
END FUNCTION Length
TYPE, EXTENDS(Point) :: CPoint
COMPLEX :: f
END TYPE CPOINT
Program PointTest
TYPE(Point) :: r
TYPE(CPoint) :: s
Real :: PLen
Plen = r%Length()
Plen = s%Length()
END Program PointTest
Unless some action is taken the call "s%length" is passing the wrong
kind of variable. Ada95's version of the inherited Length function
would replace Point with CPoint.
C++ uses an implicit version with Self, now with a fictitious Fortran notation:
CLASS :: Point
REAL :: x, y
FUNTION Length()
REAL :: Length
Length = SQRT( SELF%x**2 +SELF%y**2 )
END FUNCTION Length
END CLASS Point
CLASS(Point) :: CPoint
INHERIT :: Point
COMPLEX :: f
END CLASS CPOINT
Program PointTest ! is the same as above except
! using CLASS instead of TYPE
END Program PointTest
SELF is only defined inside the procedures of a CLASS and always has
the type of the current class, so in Point it has Point, in CPoint
it has CPoint.
Both versions are possible and both are type-safe. The "Ada95"-style uses
syntactic overloading, the "C++"-style uses semantic overloading.
With a few and better rules the "C++"-style can be made more flexible
and also safer than the original C++ and Ada95 OOP features.
So how will F2000 do the automatic type-change required by inheritance?
Cheers,
WWS
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|