comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: making a son benefit access ton an instanciation of a generic package required as a formal parameter to his father and instanciated by him
Date: Mon, 22 Jan 2018 09:28:20 +0100
Date: 2018-01-22T09:28:20+01:00	[thread overview]
Message-ID: <p447b4$tg2$1@gioia.aioe.org> (raw)
In-Reply-To: 531299d8-af8e-45b4-9531-61a3bff7b42c@googlegroups.com

On 22/01/2018 00:07, Mehdi Saada wrote:
> I think I already got the idea, and wrote things accordingly... Though a (generic) child of a generic package WILL access through prefixing with his parents'name, not the name of this instance. So in this case things are really declared in the generic package. But I've no problem with that here:
> 
> An exception is declared in an package, P1, instance of P1_G, and the RM says I can't use it in a handler... why so ?

No, it does not say so. As Jeffrey already explained, generic package is 
not a package. An exception declared in a generic package is not an 
exception until the package is instantiated. You cannot reference to 
that fake exception as a normal one.

    generic
    package P is
       E : exception; -- This is not an exception yet
    end P;

    package True_Thing is new P;

    True_Thing.E -- This is an exception proper

Now consider this:

declare
    package True_Thing_1 is new P;
    package True_Thing_2 is new P;
begin
    ...
exception
    when True_Thing_1.E => -- Catch one E
       ...
    when True_Thing_2.E => -- Catch another E
       ...
end;

The fake exception within P refers to the true exception values from 
both instances, from all possible instances, actually. There are 
situations when that *generic* reference is ambiguous or undefined. This 
is the reason for limitations like the one you encountered.

> Renaming doesn't work either.

Renaming cannot change anything here.

> It's stupid, why doesn't it behave like a normal package !

Because generics are macro expansions, they are not Ada, they are 
meta-language on top of normal Ada ("object language" is the term).

Ada designers did a very tough job making generics act as if they were 
of the object language but there are limits of possible.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


  parent reply	other threads:[~2018-01-22  8:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-21 15:43 making a son benefit access ton an instanciation of a generic package required as a formal parameter to his father and instanciated by him Mehdi Saada
2018-01-21 15:58 ` Simon Wright
2018-01-21 17:30   ` Mehdi Saada
2018-01-21 17:39     ` Simon Wright
2018-01-21 17:50     ` Dmitry A. Kazakov
2018-01-21 20:15       ` Mehdi Saada
2018-01-21 20:41         ` Dmitry A. Kazakov
2018-01-21 21:29           ` Mehdi Saada
2018-01-21 21:31             ` Mehdi Saada
2018-01-21 22:20               ` Jeffrey R. Carter
2018-01-21 23:07                 ` Mehdi Saada
2018-01-21 23:10                   ` Mehdi Saada
2018-01-22  8:28                   ` Dmitry A. Kazakov [this message]
2018-01-22  9:25                     ` Simon Wright
2018-01-23  1:23           ` Randy Brukardt
2018-01-21 22:04         ` J-P. Rosen
2018-01-22 15:36           ` Mehdi Saada
2018-01-22 15:54             ` Mehdi Saada
2018-01-22 15:52           ` Simon Wright
2018-01-23  1:33             ` Randy Brukardt
2018-01-23 14:05   ` Mehdi Saada
2018-01-23  1:13 ` Randy Brukardt
replies disabled

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