comp.lang.ada
 help / color / mirror / Atom feed
* The equals function.
@ 1986-09-25 14:24 Roger Racine
  1986-09-30  9:31 ` Jan Kok
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Racine @ 1986-09-25 14:24 UTC (permalink / 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.
-------

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: The equals function.
@ 1986-09-29 17:43 BBardin
  0 siblings, 0 replies; 4+ messages in thread
From: BBardin @ 1986-09-29 17:43 UTC (permalink / raw)




In response to your question "Where are the predefined operations for
array, access and record types defined if not in package 'Standard':

I think the answer follows from the realization that the predefined
types 'Integer', 'Characer' and 'Boolean' are quite different things
than array, record and access types.  The later are classes (or types)
of types, while the former are instances of Ada type classes.
i.e., The predefined type 'Integer' is just one instance of all possible
integer types, while 'Boolean' and 'Character' are predefined 
enumeration types (enumeration being the class).   

ARM 3.3.3(2) states that the predefined operations for a type (not a
type class) occur after the type declaration (an instance of the
class).  The predefined operations for 'Integer', 'Character' and
'Boolean' are found in 'Standard' because that is where the type
declarations for these types are found.  There are no predefined
operations for 'array', 'record', and 'access' qua type classes, only
for actual array, record and access types.

Note that 'String' is a predefined array type, (just as 'Integer' is a
predefined integer type) and the predefined operations for 'String'
are found immediately following the declaration in package 'Standard'.
Note also that the term 'integer' has been overloaded to refer to both
a class of types (as in "... 'Short_Integer' is an integer type ...")
and a specific instance of a type (as in "... the predefined type
'Integer' ...").

I hope this has been of some help,

John Prentice,
GMHEC
-------

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1986-09-30 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-09-25 14:24 The equals function Roger Racine
1986-09-30  9:31 ` Jan Kok
1986-09-30 14:22   ` Jan Kok
  -- strict thread matches above, loose matches on Subject: below --
1986-09-29 17:43 BBardin

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