comp.lang.ada
 help / color / mirror / Atom feed
From: Bill Findlay <bill@wfindlay.demon.co.uk>
Subject: Update-in-place assignment
Date: Wed, 19 Jun 2002 21:57:28 +0100
Date: 2002-06-19T21:57:28+01:00	[thread overview]
Message-ID: <B936AEC8.1C013%bill@wfindlay.demon.co.uk> (raw)

On 18/06/2002 18:12, in article fSJP8.2780$ua4.1557@nwrddc03.gnilink.net,
"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> 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 ("-" => "")




             reply	other threads:[~2002-06-19 20:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-19 20:57 Bill Findlay [this message]
2002-06-19 21:38 ` Update-in-place assignment Hyman Rosen
2002-06-20 22:35 ` Jacob Sparre Andersen
2002-06-21 18:18   ` Bill Findlay
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox