comp.lang.ada
 help / color / mirror / Atom feed
From: Blady <p.p11@orange.fr>
Subject: Re: Renaming primitives.
Date: Thu, 11 Jan 2024 11:06:45 +0100	[thread overview]
Message-ID: <unoejn$2uqo6$1@dont-email.me> (raw)
In-Reply-To: <unlvjh$2f36g$1@dont-email.me>

Le 10/01/2024 à 12:38, Jeffrey R.Carter a écrit :
> On 2024-01-10 11:37, Blady wrote:
>>     procedure My_Log_3 (Msg : String) renames My_Generic_Handler.Log;
> 
> My_Generic_Handler.Log is shorthand for My_Generic_Handler.all.Log. 
> According to AARM 8.5.4(5.e/5) 
> (http://www.ada-auth.org/standards/22aarm/html/AA-8-5-4.html), the 
> renaming also renames the prefixing object and passes it to calls to the 
> renamed subprogram: "The prefix in such a case is essentially renamed 
> and passed to any calls of the renamed subprogram."
> 
> So if I understand this correctly the renaming is roughly equivalent to
> 
> <anonymous> : Loggings.Logging renames My_Generic_Handler.all;
> procedure My_Log_3 (Handler : Loggings.Logging := <anonymous>; Msg : 
> String) renames Loggings.Logging.Log;
> 
> except that My_Log_3 is called with only a String parameter even when 
> using positional notation.
> 
> Another way to look at it is that
> 
>     My_Log_3 ("msg");
> 
> is implemented as
> 
>     <anonymous>.Log (Msg => "msg");

Thanks for your useful explanation.

>  > What is happening if My_Generic_Handler change?
>  >
>>        type Full_Logging is new Logging with null record;
>>        procedure Log (Handler : Full_Logging; Msg : String);
>> ...
>>     My_Full_Handler : aliased Loggings.Full_Logging := (Output => 
>> Ada.Text_IO.Current_Output);
>> ...
>>     My_Generic_Handler := My_Full_Handler'Access;
>>
>> Well, logically (?), My_Log_3 follows the change and outputs with 
>> Full_Logging.
> 
> No, My_Log_3 continues to call Log with My_Handler as the object, IIUC.

Yet, the code:
    My_Log_3 ("Hei");
    My_Generic_Handler := My_Full_Handler'Access;
    My_Log_3 ("Hei");
gives:
Hei
Full Hei

I thought that was correct, wasn't it?

Pascal.

  reply	other threads:[~2024-01-11 10:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 10:37 Renaming primitives Blady
2024-01-10 11:38 ` Jeffrey R.Carter
2024-01-11 10:06   ` Blady [this message]
2024-01-11 11:06     ` Jeffrey R.Carter
2024-01-10 12:13 ` Dmitry A. Kazakov
2024-01-11  2:09   ` Randy Brukardt
2024-01-11  2:18 ` Randy Brukardt
2024-01-11 10:09   ` Blady
2024-01-12  3:59     ` Randy Brukardt
2024-01-12  9:47       ` J-P. Rosen
2024-01-12 23:36         ` Lawrence D'Oliveiro
2024-01-12 10:29       ` Blady
2024-01-12 10:42     ` Blady
replies disabled

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