Skip to content

Commit 7a33574

Browse files
Added augmented_assignment proposal.
1 parent c7aa0e1 commit 7a33574

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
To: J3 J3/XX-XXX
2+
From: Leonard Reuter
3+
Subject: Augmented Assignment Operators
4+
Date: 2021-November-1
5+
6+
Proposal for Fortran Standard: 202y
7+
8+
9+
1. Introduction
10+
11+
The proposal is to introduce augmented assignment operators. Example:
12+
13+
i +.= 1
14+
15+
Here, `i` is incremented by 1.
16+
17+
In the same manner, the operators `-.=`, `*.=`, `/.=`, `**.=` are proposed
18+
to be defined as well as the operator `.op.=` for a user-defined operator
19+
`.op.`.
20+
21+
This proposal originated at the J3 GitHub repository at [1].
22+
23+
2. Motivation
24+
25+
Augmented assignment operators improve the readability of code in making
26+
immediately clear to the reader, that the new value of the variable
27+
depends on the old one.
28+
29+
Furthermore, if a function is called during the evaluation of the
30+
left-hand side, the augmented assignment operators show, that this
31+
function is only called once:
32+
33+
real :: A(n)
34+
...
35+
A(get_index()) +.= x
36+
37+
If the above example were to be written without augmented assigment, how
38+
often `get_index` is called would depend on the compiler.
39+
40+
The dot is added between the operator and `=`, since `/=` is already in
41+
use.
42+
43+
3. References
44+
45+
[1] https://github.com/j3-fortran/fortran_proposals/issues/113

0 commit comments

Comments
 (0)