From: Jeffrey R. Carter on
Warren wrote:
>
> True, but in my case I just needed the leading zeros, sans
> any sign:
>
> 900 to be displayed as "00900" (vs " 900").

In my job we make extensive use of the image functions from PragmARC.Images.
These have optional Width, Base, and Zero_Filled parameters. So we'd use

function Image is new PragmARC.Images.Signed_Image (Your_Signed_Integer_Type_Here);

Image (V, Width => 5, Zero_Filled => True)

to get your "00900". (There's also Modular_Image for modular integer types.) We
use them a lot just to avoid the leading blank from 'Image, but also for this.

The PragmARCs are Ada 95, and many of the packages won't compile with a compiler
for the current language, but this one will.

http://pragmada.x10hosting.com/

--
Jeff Carter
"I soiled my armor, I was so scared."
Monty Python & the Holy Grail
71
From: Yannick Duchêne (Hibou57) on
Le Fri, 07 May 2010 00:33:00 +0200, Jeffrey R. Carter
<spam.jrcarter.not(a)spam.acm.org> a écrit:
> The PragmARCs are Ada 95, and many of the packages won't compile with a
> compiler for the current language, but this one will.
>
> http://pragmada.x10hosting.com/
>
Although the style is not compatible with mine, so I will not use this for
my stuff, I wanted to say these sources are nice reading.

Just a question : why the Assert procedure (in PragmARC.Assertion_Handler)
? What was the intent as there is already the Assert pragma ? As far as I
know, the Assert pragma was already there with Ada 95. Am I wrong with
this point ?

--
No-no, this isn't an oops ...or I hope (TM) - Don't blame me... I'm just
not lucky
From: Randy Brukardt on
"Adam Beneschan" <adam(a)irvine.com> wrote in message
news:2318cabb-080c-42a0-8219-21c347abe172(a)o11g2000yqj.googlegroups.com...
On May 6, 10:10 am, Warren <ve3...(a)gmail.com> wrote:
....
>Broadly, you can't use a FOR attribute specification on every
>attribute, just a few select ones that the language specifically says
>you can. 'Image isn't one of those.
>
>I think it's been mentioned a few times on this newsgroup that it
>might be nice to have this ability, but I don't see that anyone has
>submitted an actual language change proposal.

I believe we looked at it semi-seriously back during the Ada 2005, but we
ran into some problems (I don't recall the details - might have been
visibility) and decided it wasn't worth the headache.

It would probably be possible with some work.

Randy.


From: Randy Brukardt on
"Yannick Duch�ne (Hibou57)" <yannick_duchene(a)yahoo.fr> wrote in message
news:op.vca4jlxbxmjfy8(a)garhos...
....
>Just a question : why the Assert procedure (in PragmARC.Assertion_Handler)
>? What was the intent as there is already the Assert pragma ? As far as I
>know, the Assert pragma was already there with Ada 95. Am I wrong with
>this point ?

A lot of Ada 95 implementations had an Assert pragma, but it was not part of
the language until Ada 2005. So if you wanted to be 100% portable, you
didn't use it. (I've still never written an Assert pragma.)

I actually don't buy the need for the Assert pragma in the first place: such
checks are rarely expensive and thus should simply be part of the code
always. (And the ones that are expensive need a lot more control than simply
on or off: Janus/Ada uses trace switches that can be controlled on a
per-unit basis.)

But it is so simple that it is harmless even if not very valuable. Thus I
didn't oppose adding it to the language.

Randy.


From: Randy Brukardt on
"Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> wrote in message
news:1ojboulapml8w$.1w5gfpk45kh72.dlg(a)40tude.net...
> On Thu, 06 May 2010 16:22:03 -0400, Robert A Duff wrote:
>
>> Warren <ve3wwg(a)gmail.com> writes:
>>
>>> I agree that it is indeed clumsier. It's just that
>>> I tend to use it a lot in debug output, rather than
>>> chasing down the package prefix for the To_String()
>>> function. I know I can always get away with:
>>>
>>> Put_Line("The value V=" & T'Image(V));
>>
>> I don't understand that. You need to chase down the package
>> in which T is declared, which is the same package in which
>> To_String (or better, Image) is declared.
>
> I always declare I/O/formatting stuff in a child package. So, T'Image has
> some minor advantages. (The argument would really work if it were V'Image
> or V.Image)

Except that you can't specify an attribute of a type after it is frozen. So
if you could specify T'Image, you couldn't define the Image function that
you specified in a child package. Thus Bob is right: the type and the
function has to be in the same package.

(Well, I guess you could use some other subtype that is declared somewhere
else as the prefix. Not sure that helps much.)

Randy.