comp.lang.ada
 help / color / mirror / Atom feed
From: RRACINE@ADA20.ISI.EDU (Roger Racine)
Subject: The equals function.
Date: Thu, 25-Sep-86 10:24:45 EDT	[thread overview]
Date: Thu Sep 25 10:24:45 1986
Message-ID: <8609252153.AA03089@ucbvax.Berkeley.EDU> (raw)

The problem, according to Pat Rogers is:
<Dear Ada language-lawyers,
<
<Here's a question:
[I deleted a discussion of a possible recursion problem that he 
wants to avoid]
<Now the question: suppose that LP is actually an access type, rather than 
<derived from Integer. So,
<
<
<    package P is
<
<      type LP is limited private;
<
<      function "="( Left, Right : LP ) return Boolean;
<
<    private
<
<      type LP is access Integer;  -- or access whatever
<
<    end P;
<
<
<In the body, the above approach cannot be used, since there is no 
<conversion or qualification type available. To wit,
<
<    package body P is
<
<      function "="( Left, Right : LP ) return Boolean is
<      begin
<    	if Left = null then ...
<
<This is a recursive call to P."=" on my compiler (yes, validated).
<
<
<
<One could simply do the following (my current approach), 
<
<    begin
<      return Left.all = Right.all;  -- null pointer dereference possible
<    exception
<      when Constraint_Error =>  
<        return False;
<    end "=";
<
<However, in some situations it may be desirable to check for the null
<value rather than relying on Constraint_Error (which might be suppressed later
<by another programmer, etc... ). Maybe it is just correct in some particular
<application to have two objects of type LP be equal if they are both null. 
<
<In those cases, what can be done ?
<
<Is the compiler correct ?   I've not had time to check it on some others.
<
<Any suggestions will be appreciated.
<
<Thanks !
<

This actually is a more interesting problem than I thought at first.
People tend to like the "infix" notation for operators. They never think
about using the fully qualified name. Therefore, I thought that all that
was needed was:

      if STANDARD."="(LEFT, null) then

Unfortunately, the equality operator is not found in package STANDARD!
Appendix C of the reference manual states:
     This annex outlines the specification of the package STANDARD
     containing all predefined identifiers in the language.
This seems to say that the equality operator should be there. But it is not
there.

Section 8.6 states:
     The predefined types (for example the types BOOLEAN, CHARACTER
     and INTEGER) are the types that are declared in a predefined
     package called STANDARD; this package also includes the 
     declarations of their predefined operations. The package STANDARD
     is described in Annex C. Apart from the predefined numeric types,
     the specification of the package STANDARD must be the same for all
     implementations of the language.

Since an access type (and array types and record types) are not predefined
types (as opposed to INTEGER, et al), this would seem to allow for those
equality operators to be missing. In fact, since the specification "must
be the same" as the Annex C spec., they would seem to be required to be 
missing. WHERE ARE THEY DECLARED?

I checked with two validated compilers, and both rejected the STANDARD."="
approach.

Roger Racine
C.S. Draper Lab.
-------

             reply	other threads:[~1986-09-25 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-09-25 14:24 Roger Racine [this message]
1986-09-30  9:31 ` The equals function Jan Kok
1986-09-30 14:22   ` Jan Kok
  -- strict thread matches above, loose matches on Subject: below --
1986-09-29 17:43 BBardin
replies disabled

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