TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Michael Feldman <[log in to unmask]>
Wed, 21 Apr 1999 16:09:56 -0400
text/plain (40 lines)
[said Tucker to Rick]

> > 1. Is it possible to generate user defined binary operators?
> No.
> > 2. If not, then why not?
> Presumably if you overload "+" or "*" you would do so only when you
> are defining an operation that has a lot in common with "+" or "*"
> respectively, and you like the "precedence" implied.   However, someone
> reading code scattered with the use of a "#" operator would have
> no way of "intuiting" what it means, nor what is its precedence.

Readability is an important issue here, and implementation is another.
Allowing arbitrary operator symbols would require the writer to
specify, somehow, what the precedence of the new operator was. This
would, in turn, require some new syntax to specify it, and would
also require compilers to support arbitrarily large and complex
precedence tables.

The next question would be "well, then, why not ternary operators
like the ? : thing in C?", etc. etc. That would result in a very
different Ada! Think of the syntax rules if each of us could
specify our own operators of arbitrary rank and precedence.
Nice thought (and has made for interesting research), but Ada
compilers are quite complex enough already.:-)
> The number of keystrokes saved by writing "Value1 # Value2" versus writing
> "Max(Value1, Value2)" was not felt to pay off in the long run,
> given that code is read much more frequently than it is written.
> At least that's the official rationale...
To put it a bit differently, operator overloading lets you add
semantic content to the language without changing the syntax.
Ada is extensible, but not _that_ extensible.

Mike Feldman