To Giampaolo Bottoni:
The Fortran committee decided that the ASSOCIATE construct is needed to
solve a different set of problems from the ones you have in mind that
are neatly solved by an exact copy of the Pascal WITH construct.
The primary difference between the proposed Fortran ASSOCIATE construct
and the Pascal WITH construct is that in the proposed Fortran ASSOCIATE
construct one specifies a (presumably shorter) name for an object of
derived type, and one can specify several of them. In Pascal, if you
have two objects of record type you need to nest two WITH constructs.
If they have components of the same name, WITH gets confused.
Let us suppose that we have two objects of some arbitrary types, but deep
within their type hierarchies there are components of type polygon, with
components named "color". In Fortran 2000, one could write
ASSOCIATE ( Z => firstThing(i,j)%images%poly1, &
& X => newThings(k)%toDraw%thePolygons(m) )
z%color = x%color
END ASSOCIATE
In Pascal, since the ultimate components you're dealing with have the
same name, you would need to write something like
WITH ( firstThing[i,j].images )
WITH ( newThings[k].toDraw )
poly1.color := thePolygons(m).color;
END; (* with *)
END; (* with *)
The Pascal construct is simpler in the simple case, and much more verbose
in the more complex case. It also puts a heavier burder on the optimizer.
Suppose several components of thePolygons(m) are referenced from within the
construct, and they have the same names as components of poly1. The Fortran
ASSOCIATE construct syntactically lifts the subscripting by (m) out of the
body of the construct, while in Pascal, the compiler would be responsible to
figure out it can be done.
The Fortran construct also reduces maintenance costs. By looking at the
body of the construct, you can see that firstThing(i,j)%images%poly1%color
is getting a value from newThings(k)%toDraw%thePolygons(m)%color. To
arrive at the same conclusion in Pascal, one is required to look at the
variable and type definitions for everything mentioned in the WITH statements.
Your example is more interesting if "myobj" is a deeply qualified reference,
perhaps with many subscripts in it, say "myFirstObj(i,j)%aComponent(k)%val(:)"
(The (:) makes things more interesting, doesn't it?) Then you could write
ASSOCIATE ( M => myFirstObj(i,j)%aComponent(k)%val(:) )
m%a = m%b + m%c + m%d .... ! Add up arrays of components.
END ASSOCIATE
This is admittedly not as terse as you might like, but the extra power
conferred by the construct is well worth the extra verbosity, at least in
the eye of the Fortran committee. I don't think the committee could
be convinced to use your suggested syntax
ASSOCIATE ( * => myFirstObj(i,j)%aComponent(k)%val(:)%* )
in the simplest case, but I will discuss it informally at the next meeting
(next week).
I hope this reduces your uneasiness about the Fortran ASSOCIATE construct.
Best regards,
Van Snyder
|