From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e0433e9cff080c9c,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-19 13:58:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!wfindlay.demon.co.uk!not-for-mail From: Bill Findlay Newsgroups: comp.lang.ada Subject: Update-in-place assignment Date: Wed, 19 Jun 2002 21:57:28 +0100 Message-ID: NNTP-Posting-Host: wfindlay.demon.co.uk X-NNTP-Posting-Host: wfindlay.demon.co.uk:158.152.131.179 X-Trace: news.demon.co.uk 1024520267 nnrp-10:24435 NO-IDENT wfindlay.demon.co.uk:158.152.131.179 X-Complaints-To: abuse@demon.net User-Agent: Microsoft-Entourage/10.1.0.2006 Mime-version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Xref: archiver1.google.com comp.lang.ada:26439 Date: 2002-06-19T21:57:28+01:00 List-Id: On 18/06/2002 18:12, in article fSJP8.2780$ua4.1557@nwrddc03.gnilink.net, "Frank J. Lhota" wrote: >> I prefer :=, and if I could change C I would change = to := and modify >> all of the shorthand operators to look like Icon (:+= and the like). > > Actually, the Icon augmented assignment operators look like this: "+:=". > > I think that the Icon augmented assignment operators would be a worthwhile > addition to Ada, not so much for optimizations but for readability. A smart > compiler could probably optimize > > Whatchama_Callit.Thingy( Here ).Do_Hickey.Count := > Whatchama_Callit.Thingy( Here ).Do_Hickey.Count + 1; > > but then you're requiring the reader to visually confirm that the expression > on the left of the assignment is the same as the expression on the left of > the "+". > There is a case to be made for being able to specify that a component of an expression being assigned is the same as the destination of the assignment. Such a feature makes the code easier to read and to modify when the name of the destination is verbose, as above; makes it easier for the compiler to generate efficient code when it takes a nontrivial amount of code to determine the address of the destination; and makes it crystal clear that update-in-place is the programmer's intended semantics (the best reason). The trouble with the C* "?=" operators, and the derivative proposals made in this thread, is that they provide a very restricted subset of a much more general facility. E.g., and obviously, they would let me write i -:= 1; for i := i - 1; but they would provide no shorter way of expressing i := 1 - i; A way of achieving what the C* people say they want (i.e. expressive power), is to have a notation (I'll use here the new reserved word "idem", but it could be a special symbol instead) that may appear as an operand in the right-hand side of an assignment statement, without restriction, and denotes there the object named on the left-hand side. E.g. we might have i := idem -1; or i := 1 - idem; or even x := 0.5 * (1.0 + a*idem); What that does not give the C* people is maximal brevity. The extra expressiveness should more than compensate. Unlike the C* 'solution' it does not require the introduction of a new assignment operator for each dyadic operator, and it supports the non-commutative operators (and more general expressions) as effectively as it does the commutative ones. -- Bill-Findlay chez Blue-Yonder.co.uk ("-" => "")