From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Ada self-referential operators
Date: 9 Feb 1995 17:30:10 GMT
Date: 1995-02-09T17:30:10+00:00 [thread overview]
Message-ID: <3hdjf2$12km@watnews1.watson.ibm.com> (raw)
In-Reply-To: D3nsJJ.6qz@swlvx2.msd.ray.com
In article <D3nsJJ.6qz@swlvx2.msd.ray.com>, jgv@swl.msd.ray.com (John
Volan) writes:
|> Realize that the relationship between "=" and "/=" is *unique* within
|> Ada.
Sad but true. I wish the ordering operators worked analogously: For two
operands of a given type T and a result of type Boolean, you would be
allowed to define (or override a predefinition) of exactly one of "<",
">", "<=", or ">=", and the others would be implicitly defined for you.
If the programmer chose to define "<", the others would be implicitly
defined as follows:
function ">" (Left, Right: T) return Boolean is
begin
return Right < Left;
end ">";
function "<=" (Left, Right: T) return Boolean is
begin
return Left < Right or Left = Right;
end "<=";
function ">=" (Left, Right: T) return Boolean is
begin
return Right < Left or Right = Left;
end ">=";
If the programmer chose to define "<=", the others would be implicitly
defined as follows:
function "<" (Left, Right: T) return Boolean is
begin
return Left <= Right and Left /= Right;
end "<";
function ">" (Left, Right: T) return Boolean is
begin
return Right <= Left and Right /= Left;
end ">=";
function ">=" (Left, Right: T) return Boolean is
begin
return Right <= Left;
end ">=";
This would only be allowed for types with an "=" operator (nonlimited
types and limited types with programmer-defined "=").
(For some relations it may be most straightforward to define "<"
explicitly, but for others, such as set containment, it is more
straightforward to define "<=" explicitly. Note that we do NOT define
A>=B, for example, to be equivalent to not(A<B). That relationship does
not hold for partial orders such as the set containment relation.)
The advantages of this approach would be:
- Guaranteed consistency among the ordering operators.
- Avoidance of tedious, redundant work to provide a complete set of
ordering operators.
- Ability to declare a single ordering operator to a generic formal
function but to have operator clearest in a given context
available anywhere in the generic template.
--
Norman H. Cohen ncohen@watson.ibm.com
next prev parent reply other threads:[~1995-02-09 17:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-02-01 9:34 Ada self-referential operators 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 [this message]
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
-- strict thread matches above, loose matches on Subject: below --
1995-02-10 17:07 R.A.L Williams
1995-02-11 5:34 ` Keith Thompson
[not found] <3id0oo$e64@gnat.cs.nyu.edu>
1995-02-23 17:45 ` Brian Hanson
1995-03-01 18:41 ` Thomas G. Coles (1W0)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox