comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: Adding "()" operator to Ada 200X
Date: Tue, 03 Jun 2003 14:59:44 GMT
Date: 2003-06-03T14:59:44+00:00	[thread overview]
Message-ID: <AJ2Da.34247$ca5.13684@nwrdny02.gnilink.net> (raw)
In-Reply-To: 1ec946d1.0306021542.58714996@posting.google.com

"Matthew Heaney" <mheaney@on2.com> wrote in message
news:1ec946d1.0306021542.58714996@posting.google.com...
> But all you've done is change the syntax.  None of your suggestions
> allow you to do more than is already provided by the library.

But isn't the same thing true of all operators? Instead of defining "+" for
my types, I could define a function named Sum. It would have the same
functionality as the "+", it would just read differently.

OTOH, how an expression reads is very important! One of Ada's strengths is
its readability, and I would consider

    D := B * B - 4 * A * C;

to be more readable than

    D := Difference( Product( B, B ), Product( Product( 4, A ), C ) );

Part of why the former expression is clearer is that it uses the standard
arithmetic notation that one uses for numeric types. Thus, even if A, B, C
and D are not a numberic type (they could be matrices, for example), we
understand the author's intentions here.

From the very beginning, Ada has allowed programmers to define operators
such as "+", "*", "and", etc. for user defined types, so that the user types
can use the same notation as the predefined types. By analogy, why not do
the same for a user type that is analgous to an array? Isn't

    B( I ) := A( P( I ) ) + C( I );

clearer than

    Replace_Element( B, I, Element( A, Element( P, I ) ) + Element( C,
I ) );

> If you're going to make a change in the syntax of the language, then
> it has be because it allows you to do something you can't do already.
> For example, there's no way to declare an access subtype right now
> that means "all the access values except null."  A useful language
> change would be to allow the declaration:
>
>   type Element_Access_Base is access all Element_Type;
>
>   subtype Element_Access is Element_Access_Base range not null;

This is an interesting idea, and we should probably pursue it further in
another. Constraint checking has always been tremendously helpful. There is
one potential (but not insurmountable) problem with this proposal: in the
absence of explicit initializations, an access variable is initialized to
null.





  reply	other threads:[~2003-06-03 14:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-02 16:35 Adding "()" operator to Ada 200X Frank J. Lhota
2003-06-02 23:42 ` Matthew Heaney
2003-06-03 14:59   ` Frank J. Lhota [this message]
2003-06-03 15:09     ` Frank J. Lhota
2003-06-03 16:04     ` Martin Krischik
2003-06-04 17:28       ` Matthew Heaney
2003-06-04 18:21         ` Frank J. Lhota
2003-06-05  1:15           ` Robert I. Eachus
2003-06-05 14:59             ` Frank J. Lhota
2003-06-05 17:25             ` Matthew Heaney
2003-06-03 20:24     ` Randy Brukardt
2003-06-03 19:52   ` Francisco Javier Loma Daza
2003-06-03  2:56 ` Fionn mac Cuimhaill
2003-06-03 14:02   ` Matthew Heaney
2003-06-03 16:23   ` Mário Amado Alves
2003-06-05 19:02     ` Dmitry A. Kazakov
2003-06-06 10:56       ` Mário Amado Alves
2003-06-06 16:55         ` Chad R. Meiners
2003-06-06 19:01         ` Frank J. Lhota
2003-06-09 14:15           ` Matthew Heaney
2003-06-07  8:36         ` Dmitry A. Kazakov
replies disabled

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