comp.lang.ada
 help / color / mirror / Atom feed
* Ada self-referential operators
@ 1995-02-10 17:07 R.A.L Williams
  1995-02-11  5:34 ` Keith Thompson
  0 siblings, 1 reply; 17+ messages in thread
From: R.A.L Williams @ 1995-02-10 17:07 UTC (permalink / raw)


In article <3grqrf$jkd@gnat.cs.nyu.edu> Robert Dewar wrote:
: A couple of things Bill, first you would like to see := be overloaded, but
: this is notoriously difficult to define cleanly, and people's first naive
: thoughts quickly founder on very tricky semantic rocks.

C++ seems to manage. Does Eiffel? I can't offhand remember.

OK, in Ada I can see that ":=" may have some implicit semantics not
present with other operators. For example, I believe constraint checking
is expected at this stage of the execution of a statement and not
before. In C++ this would be approached by inheriting from some base
operator.

Optimisation is obviously another problem. Optimisation is just not 
possible if the compiler doesn't understand the semantics of the
operators. After all, I could define something wierd like

procedure ":="(lhs : out Integer; rhs : in Integer) is
begin
  if rhs = 2 then
    lhs := 5;
  else
    lhs := 6;
  end if;
end;

Obviously, any compiler which tried to optimise a basic block containing
that would be in for a nasty surprise! So, OK, we disable statement level
optimisation where overloaded assignment is used. Caveat emptor (I don't
know the latin for programmer) -- if you use this construct, don't expect
optimisation.

: As I assume you know, Ada 95 does allow for the effect of user defined
: assignment, but not via providing a definition for the := "operator",
: which of course is not an operator at all.

My knowledge of Ada 95 is currently rudimentary, but improving. I did
a lot of Ada 83 code some years ago. I wasn't aware of 'User Defined
Assignment and Finalisation' (RM 7.6) until you pointed it out. I assume
from the LRM that to make use of this facility I need to derive the
types I want to perform 'adjustment' etc. on from 'Controlled'. 

Well, OK, with this model for assignment I can see that overlaoding ":="
is going to be inelegant. In fact, the equivalent that Ada 95 provides
*is* inelegant (IMO :-) Effectively, Ada 95 imposes a 'tree' view of
inheritance, and rules out the possibilty of a 'forest' if user defined
init/final/adj is needed. This is because, as I understand it, all classes
(sorry, object speak) must be inherited from Controlled or, presumably,
Limited_Controlled. Probably not a problem, but the sort of minor
irritation that we could do without.

BTW, I don't understand your assertion that ':= [...] of course not an
operator'. Perhaps not in Ada 95, with the semantics of package 
Ada.Finalization behind it, but the assignment operator is as good an 
operator as any other to my way of thinking. Can you explain your
reasoning here?

: Labor saving devices are indeed a good idea, PROVIDING that they save
: labour in the right places. In particular, I regard labor saving devices
: for code writers to be pretty unimportant. The only thing that is important
: is the ease of code reading, and it is CERTAINLY not the case that anything
: that makes code more compact makes it easier to read (if that were true,
: then as Bob Eachus points out, everyone would program everything in APL!)

Yes, but... (moderation in all things! Ada, sometimes makes us go to 
unnecessary lengths to do trivial operations; eg. bit shift in Ada 83
implemented with arrays of 1 bit variables! Let's face it, in a language
promulgated specifically for *embedded* applications, this was nonsense!)

: It is not that I think :+= is peculiar because it is not in the RM, rather
: +:= is not in the RM because it is peculiar, i.e. it would be VERY difficult
: to put it in without running into nasty semantic ramifications.

I'm sorry, I still don't see that. The trouble is that we still disagree
on the status of ":=" I think. If 'procedure ":=" (....)' were acceptable,
and I still don't understand why not, then I can't see anything wrong with
'procedure ":+="(...)' (although I think that "+=" looks nicer).

: I don't know how skilled you are as a language designer. Often it is 
: frustrating to plain users of the language that something that seems
: like it should be simple to do is not there, when it seems so simple
: to put it in.

I have designed a language and led the team writing a compiler for a 
specialist event driven application. Not a great deal of experience, and
not at all like Ada, but I have spent some time thinking about the
implementation of such features in C++. I still don't see where the 
problem is.

[delete]

: Indeed it was very nearly the case that Ada 95 ended up with no user
: defined assignment, since we couldn't find a way to do it. Then quite
: late in the process someone suggested the current approach, and that
: turned out to be tricky but practical, so it was put in.

I would be interested in seeing a discussion about these design decisions.
Some years ago I read the book "Engineering a Compiler" by some engineers
at Digital. Fascinating stuff, but I haven't seen much similar discussion
by language designers. I remain to be convinced, but I have an open mind
(honest).

Thanks for your comments.

Bill Williams




^ permalink raw reply	[flat|nested] 17+ messages in thread
* Ada self-referential operators
@ 1995-02-01  9:34 R.A.L Williams
       [not found] ` <3hnoe6$1aoi@info4.rus.uni-stuttgart.de>
       [not found] ` <3grqrf$jkd@gnat.cs.nyu.edu>
  0 siblings, 2 replies; 17+ messages in thread
From: R.A.L Williams @ 1995-02-01  9:34 UTC (permalink / raw)


In article <3g9nir$fpl@gnat.cs.nyu.edu> RobertDewar wrote:
: "The "+=" operator is MADE for this statement, but its ONLY benifit is
: to save me 11 characters in my source file."

: that's going a little far, the purpose of += is much more than saving
: characters, it abstracts the operation to be an increment instead of
: a computation and assignment that just happens to be an increment. 

[long and convincing rationale for += deleted]

: but still I think it is the right choice not to complicate the language to
: add these peculiar forms. Note that in C, where + cannot in any case be
: redefined, they are cleaner, and in algol-68, where parameters are strong
: enough (using ref) to describe variables, they are also cleanly addable.

You seem to be saying that 'because the LRM doesn't have these operators
there is something peculiar about them'. Forgive me if that was not your
intent. 

I'm very much in favour of these concise representations of what the
programmer really intends. I was recently a team leader on a project
(written in C, but that is not really relevant) where, because of constraints
on the target hardware, there was 100% code inspection before attempting
to integrate. Now when you're faced with the quantities of code that
we had and the task of verifying it against design specs and Yourdon
analysis (the design methodology retained p-specs into the coding stages
as design information) then you *really* appreciate every labour saving
device that the coder can introduce!

: Often in a lanuage there are things that would be nice but don't fit very 
: well. If nice is *very* nice, then sometimes we are willing to accept a
: complex wart in the language, but if nice is only a *little* nice, it's
: better to opt for cleanliness, and this is such a case I think in Ada 95.

So far as I can see, the main reason that allowing "+=" etc. to be
overloaded does not fit in with the rest of Ada is that ":=" cannot
be overloaded. Well, this again is an unfortunate oversight. In linear
algebra packages, for example, it is frequently desirable to have
an implicit garbage collection mechanism for temporary results. The
assignment operator is a good place to put this. In C++ the overloaded
assignment operator is often used to implement constraint checking.
While this is not as valuable in Ada, I know of at least one military
C3I system where a particular type, TX frequency, must be constrained
into three non-contiguous bands. This would be hard to represent
without an explicit test in Ada. (Since most of the code for that
particular system was originally written in Fortran I suppose the
issue never arose!)

Admittedly, the situation in C++ is different from Ada. In C++ every
expression has a value, and an assignment counts as an expression. It 
is therefore logical to allow overloading the assignment operator
as a function. In Ada, OTOH, ":=" would need to be overloaded by a
procedure, making it unique amongst the 'predefined operators'. I don't
see any other reason why this is not a 'clean' extension. Perhaps
":=" wouldn't stick out so much if it had "+=" etc. to keep it company?

Still, I suppose we must accept the consensus view on Ada9x. Perhaps
in Ada0x....?

Bill Williams



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~1995-03-08 23:26 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <3id0oo$e64@gnat.cs.nyu.edu>
1995-02-23 17:45 ` Ada self-referential operators Brian Hanson
1995-03-01 18:41   ` Thomas G. Coles (1W0)
1995-02-10 17:07 R.A.L Williams
1995-02-11  5:34 ` Keith Thompson
  -- strict thread matches above, loose matches on Subject: below --
1995-02-01  9:34 R.A.L Williams
     [not found] ` <3hnoe6$1aoi@info4.rus.uni-stuttgart.de>
     [not found] ` <3grqrf$jkd@gnat.cs.nyu.edu>
1995-02-06 20:51   ` Kenneth Almquist
1995-02-08  2:06     ` John Volan
1995-02-08  6:45       ` Jay Martin
1995-02-08  9:04       ` Brian Rogoff
1995-02-08 20:13         ` John DiCamillo
1995-02-09 23:52           ` David Weller
1995-02-10  6:48         ` pang
1995-02-10 16:15           ` Robert I. Eachus
1995-02-09 17:30       ` Norman H. Cohen
1995-02-11 13:56         ` Robert Dewar
     [not found]   ` <3id9qi$a7m@usenet.srv.cis.pitt.edu>
1995-02-25 13:28     ` Larry Kilgallen, LJK Software
1995-03-08 23:26     ` Val Kartchner

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