I propose a contribution towards making Fortran more object
oriented allowing the passage to a subroutine of a data not
of only one type but of a family of derivate type,
sharing common characteristics too.
http://www.cilea.it/~bottoni/f90/template_instruction.htm
Differing from a class, the "template instruction"
allows "grouping" of data types depending only on the
subroutine requirements and so would allow the creation
of "dynamic classes" that is of "temporary classes" becoming so
more powerful than the traditional C++ or Java language class.
My obvious question is: what do you think about ?
I avail myself of the opportunity for present again the
"with" instruction that, proposed a year ago, has been probably iudged
of marginal importance and only seldom useful.
Obviousy I dont't think so ;-)
I regard the derivate type as a kind of (C: or A: or D:) disk of our PC.
Noone think that, to specify a file, is necessary to write the
whole path before the file name!
Than, the derivate type variable name ( for eg. c is the Fortran name)
is analogous to the name of disc C: or D: or what you like!
Then,why I am forced to write c%xxx%yyy%zzz%mycomponent and I can't write
mycomponent only, living out the whole path ?
It's true: I can pass mycomponent to a subroutine:
call myusefull(...,c%xxx%yyy%zzz%mycomponent,...)
but so a lot of subroutines must be created only to avoid writing the
path; mereover each subroutine doesn't see the other variables of
the calling subroutine.
To make "myusefull" contained could be a way out but
the solution so obtained is not only inefficient
but tiring too because if many variables with the same
path are required, a subroutine with a very large arguments list
is necessary !
And maybe a second subroutine and than a third once and so on...
In short, the "with" instruction defining default path
according to the temporary necessities
would be very useful and, above all, helpful in the
"thread safe" subroutines creation.
The present multiprocessor computer spreading would enhance
the "with" usefulness!
To the address:
http://www.cilea.it/~bottoni/f90/fortran_with_proposal.htm
I explain why the "with" instruction would be useful in
parallel calculation.
Synthetically, the typical situation is the following:
subroutine climate(mercury)
type(planet)::mercury
with(mercury) then
... all about mercury without mercury% ....
end with
end subroutine climate
Note: climate with only one argument, not hundred of arguments...
I tried to make more powerful the "with" instruction
(already used in JavaScript) allowing to use not only
a single default path but a default path list too.
If a component with the same name is present in different paths,
the clash is worked out using the first path, preceding the other in
the "with" path list.
Eg. If exist earth%mass and moon%mass :
with(earth,moon) then
tmass=tmass+mass
end with
is equivalent to:
tmass=tmass+earth%mass
If I, unfortunately, need to use both the components with the
same name, I can use the name only for the first component
but for the second one I must use the whole path.
tmass=tmass+moon%mass + mass
Best regards
G.Bottoni
|