Re: ARRAY EQUATION VS FORALL
- From: nospam@xxxxxxxxxxxxx (Richard E Maine)
- Date: Wed, 22 Nov 2006 08:03:15 -0800
Beliavsky <beliavsky@xxxxxxx> wrote:
One can write
a(:) = b(:)
instead of
a = b
to address this.
I personally dislike this style. It is mostly a matter of style choice
and therefore not quite appropriate for me to state as a recommendation,
but I'm tempted to anyway.
The main reason I dislike/disrecommend the style is that it doesn't
quite mean the same thing in all circumstances. People who just get used
to globally writing b(:) as a substitute for b are going to get bit by
the difference some day. B is a whole array, while b(:) is an array
slice. The slice happens to include all of the same elements, but it is
still a slice and there are situations where it matters.
1. The lower bound can be different. In most cases, the lower bounds
don't matter except when indexing the array (and I presume that people
aren't trying to write b(:)(i), which won't work). It does matter for
ubound and lbound.
2. The slice doesn't always have all the same attributes as the whole
array. In particular, an array slice is never a pointer or allocatable.
Never. Thus there are cases where both b and b(:) are valid, but they
mean different things because they have different attributes. In
particular, the f2003 allocatable stuff means that the assignment
b=something
can cause reallocation, while
b(:)=something
cannot.
Fortran does make some attempt to live up to the original derivation of
its name (FORmula TRANslation). In math, one can and often would, write
simply a=b. In Fortran, we already have multiple meanings of a=b, and
have since day one. The assignment has always done different things
depending on what kind of variable is on the left-hand side. a=b for
complex is not the same thing as a=b for integer. They are related, but
not the same thing. Seems to me that they are related to each other in
much the same way that a=b for an array is related to them.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.
- References:
- ARRAY EQUATION VS FORALL
- From: jdturner
- Re: ARRAY EQUATION VS FORALL
- From: Mark Westwood
- Re: ARRAY EQUATION VS FORALL
- From: David Flower
- Re: ARRAY EQUATION VS FORALL
- From: Beliavsky
- ARRAY EQUATION VS FORALL
- Prev by Date: Re: ARRAY EQUATION VS FORALL
- Next by Date: Re: ARRAY EQUATION VS FORALL
- Previous by thread: Re: ARRAY EQUATION VS FORALL
- Next by thread: Re: ARRAY EQUATION VS FORALL
- Index(es):
Relevant Pages
|