comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: Function name problem
Date: 2000/01/17
Date: 2000-01-17T00:00:00+00:00	[thread overview]
Message-ID: <Mfvg4.948$4R4.34060@newsread1.prod.itd.earthlink.net> (raw)
In-Reply-To: B4A7F12A.45EC%Harald.Schmidt@tomcat.de

In article <B4A7F12A.45EC%Harald.Schmidt@tomcat.de> , Harald Schmidt 
<Harald.Schmidt@tomcat.de>  wrote:

> ...my intenstion was not to implement a functional operator
> equivalent to C/C++. My primary business is Smalltalk, and
> I was trying to implement the equal method "=", means
> equality of any attribute of two given objects. The second
> method "==" (basis for this discussion) is a identity
> method comparing the identity of two given objects.

OK.

Smalltalk has reference semantics.  To implement a by-reference type in
Ada(95), use access types.  "Comparing identity" in Ada95 means
comparing access objects.

package P is

  type T (<>) is abstract tagged limited null record;

  type TA is access all T'Class;

  function "=" (L, R : T) return Boolean is abstract;

  procedure Op (O : access T) is abstract;

end P;

package P.C is

  type NT is new T with private;

  function New_NT return TA;

  procedure Op (O : access NT);

  function "=" (L, R : NT) return Boolean;

private

  type NT is new T with record ...;

  ...

end P.C;


A client of a by-reference abstraction declares an access object, and
then calls the constructor for the type:

declare
  O1, O2 : TA := New_NT;
begin
  ...
  if O1.all = O2.all then   -- compare values

  if O1 = O2 then           -- compare identities


In neither case do you require an "==" operator.


--
"I do not feel obliged to believe that the same God who has endowed us
with sense, reason, and intellect has intended us to forgo their use."

Galileo Galilei





  parent reply	other threads:[~2000-01-17  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-15  0:00 Function name problem Harald Schmidt
2000-01-15  0:00 ` Matthew Heaney
2000-01-15  0:00 ` Pascal Obry
2000-01-15  0:00 ` Jeff Carter
2000-01-16  0:00   ` Harald Schmidt
2000-01-16  0:00     ` David Starner
2000-01-16  0:00       ` David C. Hoos, Sr.
2000-01-16  0:00         ` David Starner
2000-01-18  0:00         ` Howard W. LUDWIG
2000-01-16  0:00       ` David A. Cobb
2000-01-16  0:00         ` David Starner
2000-01-17  0:00           ` David A. Cobb
2000-01-17  0:00             ` David Starner
2000-01-17  0:00               ` Jeff Carter
2000-01-16  0:00     ` Matthew Heaney
2000-01-16  0:00       ` Harald Schmidt
2000-01-16  0:00         ` Gautier
2000-01-17  0:00         ` Matthew Heaney [this message]
2000-01-26  0:00       ` Florian Weimer
replies disabled

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