comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <brad.moore@shaw.ca>
Subject: Re: How to get this space away?
Date: Mon, 08 Jun 2015 06:33:37 -0600
Date: 2015-06-08T06:33:37-06:00	[thread overview]
Message-ID: <BYfdx.40257$ic6.28837@fx17.iad> (raw)
In-Reply-To: <mko0v6$2b5$1@loke.gir.dk>

On 2015-06-03 05:00 PM, Randy Brukardt wrote:
> "J-P. Rosen" <rosen@adalog.fr> wrote in message
> news:mknp7j$4s1$1@dont-email.me...
>> Le 03/06/2015 21:07, Laurent a écrit :
>>> On Wednesday, June 3, 2015 at 12:28:34 AM UTC+2, Jeffrey R. Carter wrote:
>>>
>>>>> 'Image always adds a leading space
>>>>> for a non-negative value. Nobody seems to like it, but the ARG won't
>>>>> change it.
>>> Does the ARG give a reason for not wanting to change it? Does that mean
>>> that in the
>>> case of a negative value you have to add it yourself? Doesn't really make
>>> sense.
>>>
>> This dates back to Ada83. The initial idea was that a positive number
>> and its opposite (negative) number should have the same number of
>> characters. Forcing a '+' to all positive number would not have been
>> pretty, so the design team chose to put a space for positive numbers
>> (negative numbers just have an initial '-').

Note that this behaviour was further reinforced in Ada95, when modular types
were introduced. However, in this case, the explanation doesn't quite work,
since modular types are never negative, and thus also should rarely need
to be seen with a '+' sign either. I suspect the leading space was kept for
consistency with signed types in this case.

>>
>> At first, it looked like a good idea, especially since 'Image was not
>> intended to be used extensively, but just for debugging purposes. For
>> IOs, people are supposed to use Text_IO, which provides all the desired
>> formatting. In practice, it turned out to be a bad idea, and lots of
>> programs have some functions to remove the initial space - and now,
>> changing that would break all these programs. And the ARG is very picky
>> about upward compatibility.
>
> "all these programs" should be "most of these programs". Programs using
> Trim, as Jeff suggested, won't break.
>
> But my code does a lot of this:
>
>      declare
>          Img : constant String := Natural'Image(Something);
>      begin
>          Log ("Something out of range; Something=" & Img(2..Img'Last));
>      end;
>
> and that would break horribly if the space was removed.
>
> The upcoming Corrigendum adds Obj'Image (The GNAT 'Img is used so much that
> it seems silly to not make it part of the standard); we spent a few minutes
> discussing that leading space, but eventually we decided that taking it out
> would be just as confusing (to experts) as leaving it in is (to novices).
>
>> The only possibility would be to define a new attribute. Small effort,
>> small value.

I think another possibility would be to define an aspect which could be applied to a subtype.

eg.

    subtype My_Positive is Positive with Short_Image;

The implication would be that the Short_Image aspect cause 'Image to eliminate the leading space for that subtype.
If this is workable, it strikes me as being easier to fit into the language than introducing another attribute.


>
> Right, and the effort (in the Standard and especially for implementers)
> probably outweights the value.

Try formatting 4 unsigned byte values as an quad dot IP address string, for example.
Something that can be easily expressed in another language such as C in one line of code is very awkward and ugly to write in Ada.

Brad

  parent reply	other threads:[~2015-06-08 12:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-02 20:32 How to get this space away? Laurent
2015-06-02 20:53 ` Simon Wright
2015-06-03 18:59   ` Laurent
2015-06-03 19:30     ` Simon Wright
2015-06-02 22:28 ` Jeffrey R. Carter
2015-06-03 19:07   ` Laurent
2015-06-03 20:50     ` J-P. Rosen
2015-06-03 23:00       ` Randy Brukardt
2015-06-05  9:26         ` Stephen Davies
2015-06-08 12:33         ` Brad Moore [this message]
2015-06-08 19:47           ` Randy Brukardt
2015-06-08 20:25             ` Jeffrey R. Carter
2015-06-09 14:38               ` Brad Moore
2015-06-04  9:37       ` Georg Bauhaus
2015-06-04 12:32         ` Dmitry A. Kazakov
2015-06-05 13:02       ` Laurent
2015-06-06  0:02         ` Dennis Lee Bieber
2015-06-03  7:28 ` Dmitry A. Kazakov
2015-06-03 19:19   ` Laurent
2015-06-08 22:43 ` wowwomenonwheels205
replies disabled

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