On Saturday, September 16, 2017 at 5:20:15 AM UTC+9,
herrman...@gmail.com wrote:
> On Friday, September 15, 2017 at 11:56:13 AM UTC-7, Ev. Drikos wrote:
>
> (snip, I wrote)
>
> > > Without adding general expressions as statements, one could
> > > add new assignment statements, such that:
>
> > > i += 2
>
> > What would offer such a shorthand to Fortran?
>
> Not all that much in that case, but consider
>
> bigarray(i+j, k-l, m-i)%somemember(l-m) += y(x)
>
> For even slightly complicated left sides, it means you
> don't have to verify that the two are the same every time
> you look at it, debug it, or change it.
>
Yes, I have been using some macro exactly for this purpose (i.e., to avoid
writing a long-name thing twice).
When I was using F77, I needed to write a lot of 6-dimensional loops for some
calculation, and it was tedious to check the exact match of indices
on the left- and right-hand sides of an assignment, something like
somevecA( i1, i2, i3, i4, i5, i6 ) = somevecA( i1, i2, i3, i4, i5, i6 ) + otherVecB3( i1, i2, i3+m, i4, i5, i6 ) * hmat( i5, i6 )
(please don't worry about details... I just don't remember it :)
To make it even a bit easier to read the expression, I often wrote it like
somevecA( i1, i2, i3, i4, i5, i6 ) =
somevecA( i1, i2, i3, i4, i5, i6 ) + otherVecB3( i1, i2, i3+m, i4, i5, i6 ) * hmat( i5, i6 )
After F90, I have been using
_( somevecA( i1, i2, i3, i4, i5, i6 ) ) + otherVecB3( i1, i2, i3+m, i4, i5, i6 ) * hmat( i5, i6 )
by defining
#define _(x) x = x
(which is included by my "default" header file).
So, I would really appreciate if += etc are included into the standard :-)
# I guess /= will not have ambiguity because the conditional part in IF statements
do not allow assignment. Another possibility of ambiguity is boolean (e.g., a /= b /= c), but if a /= b is regarded as boolean, it is simply illegal because it means assignment to boolean values.