[J3] Why is += missing?
Ondřej Čertík
ondrej at certik.us
Wed Aug 25 14:15:04 UTC 2021
Hi Jeff,
Thank you for bringing this up. See the discussion here:
https://github.com/j3-fortran/fortran_proposals/issues/113
and the arguments there and link to prior proposals and why they were rejected.
All things considered (I read all the comments there and emails here), I vote to include "+=" into the language.
I don't think we even need "-=", but we can add it too. "*=" is very rarely used in my experience. So is "/=". The "+=" operation is extremely common for most array oriented code, because you typically have to add up things, both in arrays and in scalars. As pointed at the issue #113, there are also some performance implications, but I think compilers should be able to optimize well even without it. The main advantage is simpler and less error prone code and that is what Fortran is all about.
I also volunteer to prototype this feature in a compiler. :)
Ondrej
On Wed, Aug 25, 2021, at 7:46 AM, Holcomb, Katherine A (kah3f) via J3 wrote:
>
> I too have wished for += and friends but was discouraged due to it
> being pointed out that /= is (probably) a nonstarter, and it’s odd to
> support one (or two) without the others. But it is incredibly awkward
> to type things like
> X%Y(n)%Z=X%Y(n)%Z+1
> I have actual code which requires far more keystrokes than the above
> for this simple operation.
>
> I don’t see the conventional divide symbol on my keyboard and would not
> be in favor of using characters outside the standard character set but
> maybe some other sequence could be invented.
>
> But only += and -= without the others would be a win since it seems
> likely those are by far the most commonly used.
>
> Katherine Holcomb
> UVA Research Computing https://www.rc.virginia.edu
> kah3f at virginia.edu 434-982-5948
>
> *From:* J3 <j3-bounces at mailman.j3-fortran.org> *On Behalf Of *Brad
> Richardson via J3
> *Sent:* Wednesday, August 25, 2021 9:34 AM
> *To:* j3 at mailman.j3-fortran.org
> *Cc:* Brad Richardson <everythingfunctional at protonmail.com>
> *Subject:* Re: [J3] Why is += missing?
>
> > += and -=, which are more likely to have hardware support anyways.
>
> This is I think the compelling argument that might win over more of the
> committee; that it will make it easier for compilers to take advantage
> of newer hardware/instruction sets for these cases. As much as I am
> convinced by the convenience of the "syntactic sugar", I think improved
> performance is the selling point for Fortran.
>
> Brad
>
> On Wed, 2021-08-25 at 13:27 +0000, Jeff Hammond via J3 wrote:
> > I will argue that it is syntactic sugar in the same sense that multidimensional arrays are. Below is the perfectly functional C code I wrote to match my Fortran years ago (because computer scientists don’t know their history). There is no actual need for multidimensional arrays in Fortran, just the practical difficulty of not having them.
> >
> > // t3(h3,h2,h1,p6,p5,p4)+=t1(p4,h1)*v2(h3,h2,p6,p5);
> > t3[h3+h3u*(h2+h2u*(h1+h1u*(p6+p6u*(p5+p5u*p4))))] += t1[p4+p4u*h1] * v2[h3+h3u*(h2+h2u*(p6+p6u*p5))];
> >
> > I think the relative usage of +=, -=, *=, ÷=, and **= if they were added justifies the pragmatic solution of just doing += and -=, which are more likely to have hardware support anyways.
> >
> > Jeff
> >
> > *From:*J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Steve Lionel via J3 <j3 at mailman.j3-fortran.org>
> > *Date: *Wednesday, August 25, 2021 at 4:13 PM
> > *To: *j3 at mailman.j3-fortran.org <j3 at mailman.j3-fortran.org>
> > *Cc: *Steve Lionel <steve at stevelionel.com>
> > *Subject: *Re: [J3] Why is += missing?
> > *External email: Use caution opening links or attachments*
> >
> > On 8/25/2021 8:07 AM, Jeff Hammond via J3 wrote:
> >> After 15 years as a Fortran programmer, I am still annoyed on a daily basis about the tedium imposed on me because Fortran lacks +=.
> > This was considered - there were a few requests for it in the 202X survey we ran 2017-2018. I suspect it fell off the list because of 1) it is "syntactic sugar", not adding any new capability and 2) the existing use of /= requiring some complicated exceptions. It could be done, sure, but the demand seems low. We'll soon start the process for 202Y features - feel free to put it forward then.
> >
> > Steve
More information about the J3
mailing list