comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: How to get this space away?
Date: Mon, 8 Jun 2015 14:47:38 -0500
Date: 2015-06-08T14:47:38-05:00	[thread overview]
Message-ID: <ml4rgr$la5$1@loke.gir.dk> (raw)
In-Reply-To: BYfdx.40257$ic6.28837@fx17.iad

"Brad Moore" <brad.moore@shaw.ca> wrote in message 
news:BYfdx.40257$ic6.28837@fx17.iad...
> On 2015-06-03 05:00 PM, Randy Brukardt wrote:
...
>> 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.

It's not *that* awkward. Since 'Image has to return a string that 'First = 
1, the following works fine (7 lines, well-formatted, could be less - 
assuming the parts are declared as bytes appropriately as they are in 
Claw.Sockets):

declare
    A_Img : constant String := Byte'Image(IP.A);
    B_Img : constant String := Byte'Image(IP.B);
    C_Img : constant String := Byte'Image(IP.C);
    D_Img : constant String := Byte'Image(IP.D);
begin
    Put (A_Img(2..A_Img'Last) & '.' & B_Img(2..B_Img'Last) & '.' & 
C_Img(2..C_Img'Last) & '.' & C_Img(2..C_Img'Last);
end;

And of course such a thing should be a subprogram (in any language) because 
you're going to use it enough (at least for debugging) that repeating it is 
silly.

Now, if you prefer to have each part to take up three characters with 
leading zeros except for the first (so they're all the same length) --  
that'll take a bit more than a handful of lines in Ada. Ada's formatting is 
primitive, except in the rarely thought of Annex F (does anyone use that?).

                                        Randy.


  reply	other threads:[~2015-06-08 19:47 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
2015-06-08 19:47           ` Randy Brukardt [this message]
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