comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <rm-dash-bau-haus@dash.futureapps.de>
Subject: Re: Text_IO, was: Re: Something I don't understand
Date: Mon, 17 Feb 2014 16:32:15 +0100
Date: 2014-02-17T16:32:16+01:00	[thread overview]
Message-ID: <53022b7f$0$6661$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <ldt0m5$2ad$1@dont-email.me>

On 17.02.14 13:52, Simon Clubley wrote:
> On 2014-02-16, Robert A Duff <bobduff@shell01.TheWorld.com> 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.



  reply	other threads:[~2014-02-17 15:32 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13 23:57 Something I don't understand Laurent
2014-02-14  0:18 ` adambeneschan
2014-02-14  7:05   ` Charles H. Sampson
2014-02-15 15:27   ` Laurent
2014-02-15 19:10     ` Laurent
2014-02-15 20:05       ` Niklas Holsti
2014-02-15 21:16         ` Laurent
2014-02-15 21:40       ` Jeffrey Carter
2014-02-16  1:39       ` Robert A Duff
2014-02-16  9:08         ` Text_IO, was: " Simon Clubley
2014-02-16  9:43           ` Dmitry A. Kazakov
2014-02-16 16:57             ` Dennis Lee Bieber
2014-02-16 16:17           ` Robert A Duff
2014-02-17 12:52             ` Simon Clubley
2014-02-17 15:32               ` G.B. [this message]
2014-02-17 15:35                 ` G.B.
2014-02-17 17:34                 ` Mike H
2014-02-17 16:59               ` Niklas Holsti
2014-02-17 17:17                 ` Dmitry A. Kazakov
2014-02-17 17:42                   ` Niklas Holsti
2014-02-17 19:55                     ` Dmitry A. Kazakov
2014-02-18  7:14                       ` Niklas Holsti
2014-02-18  8:40                         ` Dmitry A. Kazakov
2014-02-18  9:00                           ` Niklas Holsti
2014-02-18  9:31                             ` Dmitry A. Kazakov
2014-02-19  8:36                               ` Niklas Holsti
2014-02-19  9:40                                 ` Dmitry A. Kazakov
2014-02-19 13:20                                   ` Niklas Holsti
2014-02-19 14:13                                     ` Dmitry A. Kazakov
2014-02-19 15:37                                       ` Georg Bauhaus
2014-02-19 16:32                                         ` Laurent
2014-02-19 17:46                                           ` Simon Clubley
2014-02-20  2:39                                         ` Dennis Lee Bieber
2014-02-20 11:44                                           ` G.B.
2014-02-19 21:45                                       ` Niklas Holsti
2014-02-20  9:52                                         ` Dmitry A. Kazakov
2014-02-20 18:19                                           ` Niklas Holsti
2014-02-19 15:06                                     ` Robert A Duff
2014-02-19 17:03                                       ` Niklas Holsti
2014-02-19 22:30                                         ` Robert A Duff
2014-02-17 18:13                 ` Simon Clubley
2014-02-17 20:09                   ` Dmitry A. Kazakov
2014-02-18  7:50                     ` Georg Bauhaus
2014-02-18  8:28                       ` Dmitry A. Kazakov
2014-02-17 20:22                   ` Niklas Holsti
2014-02-18  0:50                     ` Simon Clubley
2014-02-18  6:56                       ` Niklas Holsti
2014-02-18  8:04                         ` Georg Bauhaus
2014-02-19 22:01                     ` Robert A Duff
2014-02-20  8:25                       ` Dmitry A. Kazakov
2014-02-20 15:54                         ` Robert A Duff
2014-02-20 17:54                           ` Dmitry A. Kazakov
2014-02-20 20:45                       ` Niklas Holsti
2014-02-19 21:52                   ` Robert A Duff
2014-02-20  0:50                     ` Simon Clubley
2014-02-19 21:46                 ` Robert A Duff
2014-02-20  0:09                   ` Jeffrey Carter
2014-02-20  1:09                     ` Simon Clubley
2014-02-20  7:06                       ` Niklas Holsti
2014-02-20 13:05                         ` Simon Clubley
2014-02-20 11:51                       ` G.B.
2014-02-20 12:53                         ` Simon Clubley
2014-02-21 11:50                       ` Brian Drummond
2014-02-23 21:37                         ` AdaMagica
2014-02-23 23:23                           ` Bill Findlay
2014-02-24  4:29                           ` AdaMagica
2014-02-24 12:22                           ` Brian Drummond
2014-02-24 19:03                             ` AdaMagica
2014-02-20 20:02                   ` Niklas Holsti
2014-02-19 21:15               ` Robert A Duff
2014-02-19 22:01                 ` Simon Clubley
2014-02-16 14:50         ` Mike H
2014-02-17 16:09         ` Laurent
2014-02-17 17:42           ` Mike H
2014-02-18  1:05             ` Dennis Lee Bieber
2014-02-17 22:31           ` Jeffrey Carter
2014-02-19 12:51             ` Laurent
replies disabled

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