From: "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not>
Subject: Re: Renaming primitives.
Date: Wed, 10 Jan 2024 12:38:25 +0100 [thread overview]
Message-ID: <unlvjh$2f36g$1@dont-email.me> (raw)
In-Reply-To: <unls1j$2f0up$3@dont-email.me>
On 2024-01-10 11:37, Blady wrote:
>
> package Loggings is
> type Logging is tagged record
> Output : Ada.Text_IO.File_Access;
> end record;
> procedure Log (Handler : Logging; Msg : String);
> end Loggings;
> My_Handler : aliased Loggings.Logging := (Output => Ada.Text_IO.Current_Output);
> My_Generic_Handler : access Loggings.Logging'Class := My_Handler'Access;
> 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");
> 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.
> Unfortunately, GNAT claims renaming with several parameters.
> I add:
> procedure Log (Handler : Logging; Msg : String; Err : Natural);
> ...
> procedure My_Log_4 (Msg : String; Err : Natural) renames
> My_Generic_Handler.Log;
>
> I got:
> test_20240110_renproc.adb:47:14: error: too many arguments in call to "log"
>
> Is it a correct or a GNAT issue?
I'm not sure what is going on here. This looks correct to me.
--
Jeff Carter
"Fundamental improvements in performance
are most often made by algorithm changes,
not by tuning."
Elements of Programming Style
201
next prev parent reply other threads:[~2024-01-10 11:38 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 [this message]
2024-01-11 10:06 ` Blady
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