comp.lang.ada
 help / color / mirror / Atom feed
* Renaming primitives.
@ 2024-01-10 10:37 Blady
  2024-01-10 11:38 ` Jeffrey R.Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Blady @ 2024-01-10 10:37 UTC (permalink / raw)


Hello,

Is a procedure renaming equivalent to a simple call?
For instance:
    procedure Log (Msg : String) is
    begin
       Ada.Text_IO.Put_Line (Msg);
    end Log;
    procedure My_Log_1 (Msg : String) is
    begin
       Log (Msg);
    end My_Log_1;
    procedure My_Log_2 (Msg : String) renames Log;

Almost, My_Log_1 is equivalent to My_Log_2, isn't it?

Is it the same with primitives?

For instance:
    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;

To my surprise (well I hoped) My_Log_3 is compiled by GNAT.
Is it conformed to the Ada standard?

What is happening if My_Generic_Handler change?

For instance:
       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.

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?

Full source code on demand.

Thanks.
Happy New Year to all!
Pascal.

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

end of thread, other threads:[~2024-01-12 23:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10 10:37 Renaming primitives Blady
2024-01-10 11:38 ` Jeffrey R.Carter
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

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