Re: ARRAY EQUATION VS FORALL



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
.



Relevant Pages

  • Re: Q about Array Manipulation in F90
    ... Bis an array slice - not the whole array. ... Places where any of several attributes matter. ... the left-hand-size is reallocated as ...
    (comp.lang.fortran)
  • Re: Q about Array Manipulation in F90
    ... Bis an array slice - not the whole array. ... Places where any of several attributes matter. ... the left-hand-size is reallocated as ...
    (comp.lang.fortran)
  • Re: BIGLOO vs FORTRAN
    ... multidimensional array if you wanna slice lets say: ... various dimensions and orders. ... (vector->list erg) ...
    (comp.lang.scheme)
  • Re: unsigned type
    ... says that for a slice, "If the slice is not a null slice (a slice ... that all index must be valid before checking for a null array. ... work with modular index types because the 'First of the string is the ...   ...
    (comp.lang.ada)
  • Re: Converting access values
    ... Duncan Sands writes: ... > rest of your program to see as an array of an unconstrained array type. ... > You need to do some pointer manipulations in C when first allocating them to ... I have to "copy" a slice ...
    (comp.lang.ada)