From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Parameterised 'Image Attributes
Date: Mon, 21 Aug 2023 18:11:19 -0500 [thread overview]
Message-ID: <uc0qu4$239o4$1@dont-email.me> (raw)
In-Reply-To: ubsmak$1a024$1@dont-email.me
Your #3 is the point of course. If a reasonable library can be written, you
should use that. After all, the Ada philosophy is that it is suspicious to
use any built-in types. Why then should it be less suspicious to use other
things that are built-in??
The best approach for Ada going forward is the add things that make it
easier to build good libraries (as in user-defined literals). And minimize
magic.
Randy.
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:ubsmak$1a024$1@dont-email.me...
> On 2023-08-20 09:53, G.B. wrote:
>
>> Could there be a language defined type F whose purpose is to support
>> the description of formats? Objects of type F would "configure"
>> what 'Image does when computing a representation of a date, a number, ...
>
> Not without multiple dispatch support and classes:
>
> Type x Format [ x Target ]
>
> Otherwise you get an untyped mess as in C:
>
> printf ("%s", 123);
>
> In the case of 'Image the dispatch is hard-wired. The compiler generates
> it according to one of built-in classes like 'integer type'. So yes it
> would be no problem to add parameters specific to each of the classes as
> well as common parameters like padding or alignment inside a field. But it
> will never ever happen.
>
> You seem suggesting a class-wide parameter type instead:
>
> type Format_Type is tagged record
> Width : Natural := 0;
> Alignment : Alignment_Type := Left;
> Padding : Character := ' ';
> end record;
> type Integer_Format is new Format_Type with record
> Plus_Sign : Boolean := False;
> Base : Base_Type := 10;
> end record;
>
> X'Image (Format => Format_Type'Class)
>
> This still requires a change that will be outright rejected on highest
> philosophical grounds. (:-))
>
> However with a Format_Type you do not need 'Image. You can simply use a
> binary operation, e.g.
>
> function "/" (Value : Integer; Format : Integer_Format)
> return String;
>
> So would do
>
> Put_Line ("X=" & X / (Width=>10, Padding=>'0', Alignment=>Right));
>
> instead of
>
> Put_Line ("X=" & X'Image (Width=>10, Padding=>'0', Alignment=>Right));
>
> Of course it must be generic, which kills all fun.
>
> Ergo
>
> 1. Compiler magic is necessary because the language type system is too
> weak to express things like formatting.
>
> 2. No proposal however useful and reasonable will survive ARG because of
> #1.
>
> 3. Use a library that does the stuff. E.g.
>
> http://www.dmitry-kazakov.de/ada/strings_edit.htm#Integer_Edit
>
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de
>
next prev parent reply other threads:[~2023-08-21 23:11 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-18 7:18 Parameterised 'Image Attributes Rod Kay
2023-08-18 8:25 ` Luke A. Guest
2023-08-19 9:14 ` J-P. Rosen
2023-08-19 10:03 ` Dmitry A. Kazakov
2023-08-19 11:45 ` Luke A. Guest
2023-08-19 11:56 ` J-P. Rosen
2023-08-19 13:01 ` Dmitry A. Kazakov
2023-08-19 15:27 ` Jeffrey R.Carter
2023-08-20 7:53 ` G.B.
2023-08-20 9:27 ` Dmitry A. Kazakov
2023-08-21 23:11 ` Randy Brukardt [this message]
2023-08-21 23:37 ` Randy Brukardt
2023-08-22 7:38 ` Dmitry A. Kazakov
2023-08-19 16:49 ` moi
2023-08-20 7:25 ` Randy Brukardt
2023-08-20 9:43 ` Dmitry A. Kazakov
2023-08-21 23:34 ` Randy Brukardt
2023-08-22 8:13 ` Dmitry A. Kazakov
2023-08-23 10:20 ` Stephen Davies
2023-08-23 16:16 ` Dmitry A. Kazakov
2023-08-24 19:59 ` Stephen Davies
2023-08-25 7:26 ` Dmitry A. Kazakov
2023-08-25 9:04 ` Stephen Davies
2023-08-25 13:02 ` Dmitry A. Kazakov
2023-08-28 9:18 ` Stephen Davies
2023-08-28 10:58 ` Dmitry A. Kazakov
2023-08-28 15:42 ` Stephen Davies
2023-08-28 16:09 ` Dmitry A. Kazakov
2023-08-28 17:33 ` G.B.
2023-08-28 19:08 ` Dmitry A. Kazakov
2023-08-28 17:58 ` Niklas Holsti
2023-08-28 19:08 ` Dmitry A. Kazakov
2023-09-07 1:04 ` Randy Brukardt
2023-09-07 9:01 ` Dmitry A. Kazakov
2023-08-18 18:53 ` Keith Thompson
2023-09-23 10:00 ` Rod Kay
2023-09-26 5:47 ` Vadim Godunko
2023-09-26 10:15 ` Rod Kay
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox