🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1346

Re: Rationales for result type of operations using operators like '+='

#1346
From: bartc
Date: Fri, 06 Nov 2026 00:27
115 lines
4932 bytes
On 05/11/2026 22:41, Janis Papanagnou wrote:
> On 2026-11-05 13:17, bartc wrote:

> We still have the advantages that I mentioned elsethread. But that
> was not my question.
> 
> I remind: since they have introduced op= to return a value why did
> they do it the way they did. Specifically, what are the use-cases
> that they support by their implementation semantics (with rvalues
> and right-associativity).

Algol68 had this big idea that everything has to return some value, 
including compound assignment. Given that, it made these choices, which 
includes ordinary assignment having RTL precedence, and compound 
assignment being LTR.

Personally I don't see any great need to allow compound assignments to 
be chained at all, as it only leads to harder-to-understand code with 
too many things being updated within the same statement.

So my compound assignments return 'void'.


>> But doing it with ordinary assignment has some advantages:
>>
>> * Only one assignment is done, not 4 lots of /compound/ assignments.
> 
> This appears to me to be nonsensical given that we are talking about
> abstractions in a higher-level language, and that the transformation
> to machine instructions need not even result in different code.
> 
>>    With a poor implementation, that will be less efficient
> 
> With poor implementation everything will be less efficient.

 >    number *:= base +:= digit

I did a brief speed test using A68G. That version was 50% slower than:

     number := number * base + digit;


>>    i +:= 2 *:= i;
> 
> What is that supposed to implement in the first place is the question!

> I suggest to explain a sensible task,
The task doesn't matter. The behaviour needs to be well-defined. And 
here that might be unintuitive.

>> The second 'i' will have the new value i + 2, not the original, even 
>> though it has not obviously been modified.
> 
> Are you now speaking about a left-associative interpretation?

I'm speaking about observed behaviour from A68G:

  INT i:=100;
  i +:= 2 *:= i;
  print(i)

Output is 10404, or 102 * 102. It is not the same as either of:

   i := i + 2 * i;       # 300 #
   i := (i + 2) * i;     # 10200 #

It is also confusing in that here:

   number *:= base +:= digit

It looks as though 'base' is being modified too.


> Anyway, you seem to not see the obvious change of 'i' with '+:=', so
> I cannot help you.

That's the confusing bit; when does the change happen? Here:

   i +:= a +:= b +:= i +:= c +:= i

presumably at the first +:=, all the 'i' instances on the right 
simultaneously change their values, and by the second +:=, it's all 
change once more?!

But by the fourth +:=, the value of the middle 'i' is no longer a factor.



> I understand that it is confusing to you. I understand that you seem
> to consider it to be "fiddly". I understand that you are incapable of
> defining a clear semantics

The point is that the semantics are necessarily more obscure and less 
obvious compared with plain code which only has one assignment.

> so that it won't surprise anyone.

I understand that you've never had to implement any of this stuff.

>> It is problematical in C too:
>>
>>      int      a = 1000;
>>      unsigned b = 200;
>>      int      c = 300;
>>
>>      a += b += 100;
>>
>> 'a' ends up with the value 1044 rather than 1300.

> Are you hallucinating?

No. 'b' was supposed to have type 'unsigned char' as I confirmed when DB 
queried it. Interesting, the difference in attitude.

Technical Details
Message-ID: <11cj6t3$242aq$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me> <11cj0n7$85p3$8@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: bartc <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Rationales for result type of operations using operators like
 '+='
Date: Fri, 6 Nov 2026 00:27:15 +0000
Organization: A noiseless patient Spider
Lines: 115
Message-ID: <11cj6t3$242aq$1@dont-email.me>
References: <11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me>
 <11cj0n7$85p3$8@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 06 Nov 2026 00:27:16 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2230618"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1//MuLWLYbI5b8nK15JW/Xt"; posting-host="06e92dab06e7bbad2d3f6c6728786274"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8caHpwaGkACfGWZB2aUEbhwF9Lk= sha256:co7aptRPkChqVoJLFBv1UZZHEXzBRFxwYgT/KNAz/eA=
	sha1:E/aLTyQeu2bHrrZ46WOGgRPEeE4= sha256:hH/17SMrfFM+yvy5VwFfSpIl45YSEix/7DDUhi5Dl9E=
In-Reply-To: <11cj0n7$85p3$8@dont-email.me>
Content-Language: en-GB