From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: Renaming primitives. Date: Wed, 10 Jan 2024 12:38:25 +0100 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 10 Jan 2024 11:38:25 -0000 (UTC) Injection-Info: dont-email.me; posting-host="9f8a5ac2dea7306d78f02eb3adb3b506"; logging-data="2591952"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//B0v2HHmYMyPg+UDETESSO+UHoDHhtt4=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:t6BVDBD4hLExuUdgUgY6gew6OCM= Content-Language: en-US In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:65978 List-Id: 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 : Loggings.Logging renames My_Generic_Handler.all; procedure My_Log_3 (Handler : Loggings.Logging := ; 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 .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