missing ->= operator

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Thu May 2 18:54:51 AEST 1991


In article <1991Apr30.165110.4165 at unhd.unh.edu>, jwm712 at unhd.unh.edu (Jonathan W Miner) writes:
> It is my opinion that the +=, &= etc operators were implemented on systems,
> such as DEC VAX that has two operand instructions.

Well, of _course_ they were _implemented_ on such machines.
But it is a MYTH that they reflect the behaviour of any machine.
The designers of C have repeatedly denied this malignant rumour
(there was a letter in SigPlan Notices last year about it),
pointing out that
    -- C inherited the operations from B
    -- B was implemented as an *interpreter*, so hardware features
       weren't particularly relevant
    -- and if I remember correctly, the machine B was implemented
       on _didn't_ have such instructions.

I would point out that
    -- Algol 68 has a whole raft of operators +:=, -:=, /:=, and so on.
       It was part of the culture at the time that "update operators"
       made programs clearer.  An example from some Pascal code of mine:
	n.items[o.first + o.count] := n.items[o.first + o.count] + 1;
       Much clearer as
	n.items[o.first + o.count] +:= 1;
       The hardware very definitely did _not_ show through in Algol 68!
    -- Burroughs Extended Algol had a gimmick where the first <primary>
       following an assignment symbol could be '*', meaning "same variable
       as the one preceding the assignment symbol".  Thus the BEAlgol
       version of the assignment above would be
	n.items[o.first + o.count] := * + 1;
       A virtue of that approach was that there was nothing special about	
       binary operators:
	x := not *;
	x := - *;
        x := *.[0:8];	% extract bits
       an so on worked just fine.  I can assume you that there was
       absolutely nothing on the Burroughs machine corresponding to
       "two operand instructions".

> Although it would
> be nice to have a ->=, it would be a programmer convenience, and it would
> still be compiled into the same code as p = p->next.  

What's wrong with programmer conveniences?  What else is a 'for' loop?
Heck, _types_ in C are just a programmer convenience; C's ancestors
managed without.  (Yes, I have written BCPL programs, and yes, I have
written "+" (integer add) when I meant "#+" (floating-point add).)

-- 
Bad things happen periodically, and they're going to happen to somebody.
Why not you?					-- John Allen Paulos.



More information about the Comp.lang.c mailing list