From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Running a preprocessor from GPS? Date: Thu, 30 Jul 2015 15:38:15 +0200 Organization: cbb software GmbH Message-ID: References: <2df4698f-4c8e-457c-822d-209cb2f8ab5e@googlegroups.com> <014427b1-ff7a-4a69-82e6-0330af77ed96@googlegroups.com> <1438244829.17005.26.camel@obry.net> <1438260153.17520.14.camel@obry.net> <3825fe2a-b768-4cd5-b3c3-3dc97ddd997a@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: ChlmA4XFxcJoDoqGdDSflw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:27207 Date: 2015-07-30T15:38:15+02:00 List-Id: On Thu, 30 Jul 2015 06:21:42 -0700 (PDT), EGarrulo wrote: > On Thursday, July 30, 2015 at 2:42:36 PM UTC+2, Pascal Obry wrote: >> Le jeudi 30 juillet 2015 à 04:54 -0700, EGarrulo a écrit : >>> By the way, the implementation of GNAT.Formatted_String is cryptic. >>> Isn't Ada code supposed to be readable? >> >>> I must be missing something. >> >> Yes, sure: Open Mind score below 0! > > Not really. Compare the arbitrary overloading of "+", "-" and > "&" (and the cryptic "#") in GNAT.Formatted_String here: > > procedure Fout is > F : Formatted_String := +"%c %% %#08x"; > Vc : Character := 'v'; > Vi : Integer := 12; > begin > F := F & Vc & Vi; > Put_Line (-F); -- Prints: "v % 0x00000c" > end Fout; > > with the explicit formatting directives here (I am not sure that > this is valid Ada, but you should get the idea): > > procedure Fout is > F : Formatted_String; > Vc : Character := 'v'; > Vi : Integer := 12; > begin > F := ("%A %% %A", (Format (Vc), > Format (Vi, > Prefix => "0x" > Base => 16, > Width => 8, > Filler => "0")); > Put_Line (F); -- Prints: "v % 0x00000c" > end Fout; > > The only convention that you need to know is that "%A" inserts > an argument and that "%%" inserts a literal "%". Much simpler, > don't you think? And extensible! You can define "Format" > for your own types, independently from "Formatted_String". declare Text : String (1..40); Pointer : Integer := Text'First; begin Put (Text, Pointer, Vc & " % 0x"); Put (Text, Pointer, Vi, Base=>16,Fill=>'0',Field=>6,Justify=>Right); Put_Line (Text, 1..Pointer - 1); -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de