comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: pragma Pure (Ada)
Date: Mon, 10 Oct 2011 08:06:26 -0700 (PDT)
Date: 2011-10-10T08:06:26-07:00	[thread overview]
Message-ID: <02d770c9-8e80-45a9-aa40-fc38215a12af@20g2000prg.googlegroups.com> (raw)
In-Reply-To: op.v211w2a2ule2fv@index.ici

On Oct 8, 3:54 pm, Yannick Duchêne (Hibou57)
<yannick_duch...@yahoo.fr> wrote:
> Le Sat, 08 Oct 2011 03:37:53 +0200, Adam Beneschan <a...@irvine.com> a  
> écrit:> So a special rule had to be added to make the language *prefer* the
> > "universal access" equality function over any other function.
>
> > Hope this helps,
>
> Yes Adam, that help, but raise another question: the choice of the  
> anonymous access type operator is surprising to me. Why was the choice of  
> the more specific operator rejected ?  I guess this may be because the  
> anonymous access type may not always be a valid parameter for the more  
> specific redefined operator of the named access type (ex. different  
> storage pool), but the choice of the least specific operator, is  
> counterintuitive,

Actually, I think the opposite is true.  Say you have a package that
defines a record type Rec1 which defines an element of a linked list,
and it has a Link field:

   Link : access Rec1;

Now, in another package P2, you have some reason for defining your own
access type that accesses Rec1.  Maybe it's declared as a private
type:

   type Employee is private;

but you decide to implement it as an access-to-Rec1, in the private
part:

   type Employee is access all Rec1;

If we followed the rule you say is "intuitive", then any time in the
body of P2, you wrote

   if A.Link = B.Link then ...

the Link fields would suddenly be treated as having type Employee
(because the "=" operator on Employee would be used), even though Link
wasn't declared as having type Employee and the Employee type wasn't
even visible at the point the Link was declared.  This, to me, is
counter-intuitive.  So I think you've gotten it backwards.

The example is somewhat contrived; it's hard for me to think of a good
real-life example.  In practice, "=" won't be redefined that often,
which means it really doesn't matter which one the compiler picks.
You're going to be comparing two addresses for equality, no matter
which one is picked.  But there have to be some rules to allow the
compiler to pick one.  And, as Niklas pointed out, if there are
multiple named access types visible that access the same designated
type, using the "more specific" operator would still produce ambiguous
errors, which is not desired.

                                  -- Adam



  parent reply	other threads:[~2011-10-10 15:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-01  1:50 pragma Pure (Ada) Yannick Duchêne (Hibou57)
2011-10-01  2:11 ` Yannick Duchêne (Hibou57)
2011-10-08  1:37   ` Adam Beneschan
2011-10-08 22:54     ` Yannick Duchêne (Hibou57)
2011-10-09  6:34       ` Niklas Holsti
2011-10-10 15:06       ` Adam Beneschan [this message]
2011-10-01  2:28 ` Yannick Duchêne (Hibou57)
2011-10-08  1:08   ` Randy Brukardt
2011-10-08 23:00     ` Yannick Duchêne (Hibou57)
2011-10-01  3:09 ` Adam Beneschan
replies disabled

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