Article View: comp.lang.c
Article #1359Re: Rationales for result type of operations using operators like '+='
From: Janis Papanagnou
Date: Fri, 06 Nov 2026 18:11
Date: Fri, 06 Nov 2026 18:11
80 lines
4404 bytes
4404 bytes
On 2026-11-06 12:29, Rosario19 wrote: > On Fri, 6 Nov 2026 00:27:15 +0000, bartc wrote: >> 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 > > this would change base and number... for me would be ok If that was your intention to program it's of course okay. - But the sample had another intention; it was to illustrate a practically used "pipelined" processing, something that is (in that form) not possible in "C". Personally I don't like side-effects that change another object in the midst of an expression. But I've adopted quite some code-pattern of this type that are typical in "C"; e.g. for ((fd = fopen(...)) != NULL) but here, in that simple expression, it's clearer (and values suffice to be returned). While in the *= and += example we had another case. > >> I did a brief speed test using A68G. That version was 50% slower than: >> >> number := number * base + digit; > > this would change only number Yes. And the Algol 68 semantics of the former sample would make it unnecessary to duplicate the "number" in the expression; you'd just say: "Change number by multiplying it by "base" and add "digit", and that is done quite naturally from left to right. In Algol 68 number *:= base +:= digit or more verbosely number TIMESAB base PLUSAB digit where the latter variant *might* also reduce the "confusion" since it contains no '=' as part of the operator. Just don't confuse the Algol 68 semantics with "C" semantics. Janis
Technical Details
Message-ID:
<11cl585$23539$8@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-mailReferences:
<11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me> <11cj0n7$85p3$8@dont-email.me> <11cj6t3$242aq$1@dont-email.me> <39erel9pi4nq3uctk7clc605evnmqm3q8i@4ax.com>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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Rationales for result type of operations using operators like '+=' Date: Fri, 6 Nov 2026 19:11:17 +0100 Organization: A noiseless patient Spider Lines: 80 Message-ID: <11cl585$23539$8@dont-email.me> References: <11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me> <11cj0n7$85p3$8@dont-email.me> <11cj6t3$242aq$1@dont-email.me> <39erel9pi4nq3uctk7clc605evnmqm3q8i@4ax.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 06 Nov 2026 18:11:17 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2200681"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BdaNKLtqZCWhMcblSHJXr"; posting-host="a1c3eccefbcc1d6f648cf481fadc4299" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:1hm8iQ93YpLD0p+nfA7eTDZtaLU= sha256:Qv+1OcGnnQUTI1a/zaYVZwa7KJEgWZ8FT6MZ8TQdvJU= sha1:/IkFiUGpMHH8tFoy8gurulGQ/b0= sha256:SYEqFQb+frWE9gzLPshaSQ3yvPsnGO1nkx3lUst40jQ= Content-Language: en-US In-Reply-To: <39erel9pi4nq3uctk7clc605evnmqm3q8i@4ax.com>