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: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx17.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to get this space away? References: <0b23f4af-9a55-4d1d-be90-f74b316a95cf@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Message-ID: NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1433766817 68.145.219.148 (Mon, 08 Jun 2015 12:33:37 UTC) NNTP-Posting-Date: Mon, 08 Jun 2015 12:33:37 UTC Date: Mon, 08 Jun 2015 06:33:37 -0600 X-Received-Bytes: 4252 X-Received-Body-CRC: 1336102043 Xref: news.eternal-september.org comp.lang.ada:26216 Date: 2015-06-08T06:33:37-06:00 List-Id: On 2015-06-03 05:00 PM, Randy Brukardt wrote: > "J-P. Rosen" 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