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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca.giganews.com!nntp.giganews.com!goblin1!goblin.stu.neva.ru!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 17 Feb 2014 16:32:15 +0100 From: "G.B." User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Text_IO, was: Re: Something I don't understand References: <4a3e55f6-9f54-4084-9f37-96efd4b0d349@googlegroups.com> <0b358700-871b-4603-addd-65e07c7d59e5@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <53022b7f$0$6661$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 17 Feb 2014 16:32:16 CET NNTP-Posting-Host: bbcf4e50.newsspool2.arcor-online.net X-Trace: DXC==kB4D9dQ; 3:U`5g[@c]@J1A9EHlD; 3Yc24Fo<]lROoR18kF:Lh>_cHTX3j=QKUBbL^:Pk7 X-Complaints-To: usenet-abuse@arcor.de Xref: number.nntp.dca.giganews.com comp.lang.ada:184933 Date: 2014-02-17T16:32:16+01:00 List-Id: On 17.02.14 13:52, Simon Clubley wrote: > On 2014-02-16, Robert A Duff wrote: >> A simplified and type-safe version of C's printf style >> (template-based) formatting would be more readable than >> concatenating a bunch of strings together to print messages, >> and MUCH better than using a series of Put calls to print >> a single message. >> > > _Totally_ agree with this. It would also be nice if one could write > something like this (pseudo Fortran style to get the idea across): > "5(I4,2X,F10.4,2X)" so you could specify the layout for 5 columns worth > (in this example) of data cleanly. I wonder if this feature could be tacked onto the string types? With the help of attribute functions and named bindings, formatting could be handled flexibly, leaving room for internationalization, for example. Formatting could also be handled conveniently, insofar as the language provides "obvious" default formatting. For_Invoice : constant Wide_String := -- not Ada Wide_String'Edited ("A total of %{Sum} %{Currency} for %{Pieces}") with Bindings => (Sum => (Value => <>, Money'Wide_Formatted => Using_Pic_String), Currency => (I18N.CU, Currency'Wide_Formatted => <>), Pieces => (Amount * 2.0, Three_Colums'Access)); Format : constant -- needs to be a static constant Wide_String'Edited := "Process # %{pnum} : %{n}µs"; A <> stands for the default choices, viz. a variable or parameterless function named "Sum" in the first row, and a default "formatter" in the third. When no specialized formatting is needed for an item, write with Bindings => (..., Foo => <>, ...); As an example of a flexible solution, "Using_Pic_string" from the first example above would be a function with a profile like that of 'Wide_Image. (Its body uses existing language features, in this case picture strings from Information Systems Annex.) Also, since the generics of Text_IO already provide for formatting numbers (Putting them into strings), these routines could be borrowed for the meaning of T'[Wide_][Wide_]_Formatted Safety of the template is guaranteed insofar as the number of items (and types, I think) in any actual binding is known at compile time; type checking looks possible. Hence, the simplest formatting would be String'Edited("%{n} bottles of beer on the wall") with Bindings (others => <>); It requires only that there be a variable/function named N.