comp.lang.ada
 help / color / mirror / Atom feed
* reverse Integer'image(someString);
@ 2005-04-23 19:59 Doker
  2005-04-25  9:16 ` Adrien Plisson
  2005-04-25  9:18 ` Martin Krischik
  0 siblings, 2 replies; 17+ messages in thread
From: Doker @ 2005-04-23 19:59 UTC (permalink / raw)


when i want String from Integer i do 
reverse Integer'image(someString);

and what if i need integer from a string?



Thanks for reply.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-23 19:59 reverse Integer'image(someString); Doker
@ 2005-04-25  9:16 ` Adrien Plisson
  2005-04-25 11:10   ` Jeff C
  2005-04-25  9:18 ` Martin Krischik
  1 sibling, 1 reply; 17+ messages in thread
From: Adrien Plisson @ 2005-04-25  9:16 UTC (permalink / raw)


Doker wrote:
 > when i want String from Integer i do reverse Integer'image(someString);

isn't this wrong ? it should be:
someString := Integer'Image( someInteger );

 > and what if i need integer from a string?

someInteger := Integer'Value( someString );

 > Thanks for reply.

you're welcome !

-- 
rien



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-23 19:59 reverse Integer'image(someString); Doker
  2005-04-25  9:16 ` Adrien Plisson
@ 2005-04-25  9:18 ` Martin Krischik
  1 sibling, 0 replies; 17+ messages in thread
From: Martin Krischik @ 2005-04-25  9:18 UTC (permalink / raw)


Doker wrote:

> when i want String from Integer i do
> reverse Integer'image(someString);
> 
> and what if i need integer from a string?

Integer'Value for simple convertions. Ada.Text_IO.Integer_IO for more
complex processing.

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25  9:16 ` Adrien Plisson
@ 2005-04-25 11:10   ` Jeff C
  2005-04-25 11:40     ` David C. Hoos, Sr.
  0 siblings, 1 reply; 17+ messages in thread
From: Jeff C @ 2005-04-25 11:10 UTC (permalink / raw)


Adrien Plisson wrote:
> Doker wrote:
>  > when i want String from Integer i do reverse Integer'image(someString);
> 
> isn't this wrong ? it should be:
> someString := Integer'Image( someInteger );

Actually, new people get into trouble all of the time with
that construct and end up with constraint errors.
When used in this form, someString needs to be extactly the
same length as the return length of Integer'image(someInteger).


What does work fine are:

a)

   Text_IO.Put_Line(Integer'Image(Some_Integer));

b)

   declare
     Some_String : constant String := Integer'Image(Some_Integer);
   begin
     ...play with Some_String
   end;



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 11:10   ` Jeff C
@ 2005-04-25 11:40     ` David C. Hoos, Sr.
  2005-04-25 11:50       ` Larry Kilgallen
                         ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: David C. Hoos, Sr. @ 2005-04-25 11:40 UTC (permalink / raw)
  To: comp.lang.ada

Jeff C" <jcreem@yahoo.com> wrote in message 
news:KIednSCHV-GzTfHfRVn-qw@comcast.com...
> Adrien Plisson wrote:
snip
> What does work fine are:
>
> a)
>
>   Text_IO.Put_Line(Integer'Image(Some_Integer));
>
> b)
>
>   declare
>     Some_String : constant String := Integer'Image(Some_Integer);
>   begin
>     ...play with Some_String
>   end;

The "constant" in the declaration of Some_String is not only
unnecessary, but would prevent some types of "playing"
with Some_String.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 11:40     ` David C. Hoos, Sr.
@ 2005-04-25 11:50       ` Larry Kilgallen
  2005-04-25 17:13         ` Pascal Obry
  2005-04-25 17:38         ` Frank J. Lhota
  2005-04-25 17:14       ` Pascal Obry
                         ` (2 subsequent siblings)
  3 siblings, 2 replies; 17+ messages in thread
From: Larry Kilgallen @ 2005-04-25 11:50 UTC (permalink / raw)


In article <mailman.71.1114429295.24457.comp.lang.ada@ada-france.org>, "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:
> Jeff C" <jcreem@yahoo.com> wrote in message 
> news:KIednSCHV-GzTfHfRVn-qw@comcast.com...
>> Adrien Plisson wrote:
> snip
>> What does work fine are:
>>
>> a)
>>
>>   Text_IO.Put_Line(Integer'Image(Some_Integer));
>>
>> b)
>>
>>   declare
>>     Some_String : constant String := Integer'Image(Some_Integer);
>>   begin
>>     ...play with Some_String
>>   end;
> 
> The "constant" in the declaration of Some_String is not only
> unnecessary, but would prevent some types of "playing"
> with Some_String.

It is required with Ada 83.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 11:50       ` Larry Kilgallen
@ 2005-04-25 17:13         ` Pascal Obry
  2005-04-25 17:50           ` Björn Lundin
  2005-04-25 17:38         ` Frank J. Lhota
  1 sibling, 1 reply; 17+ messages in thread
From: Pascal Obry @ 2005-04-25 17:13 UTC (permalink / raw)



Kilgallen@SpamCop.net (Larry Kilgallen) writes:

> It is required with Ada 83.

No it is not. Probably a check done by your compiler. GNAT does check for
constant string not declared as constant.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 11:40     ` David C. Hoos, Sr.
  2005-04-25 11:50       ` Larry Kilgallen
@ 2005-04-25 17:14       ` Pascal Obry
  2005-04-26  1:53       ` Jeffrey Carter
  2005-04-28 20:31       ` Simon Wright
  3 siblings, 0 replies; 17+ messages in thread
From: Pascal Obry @ 2005-04-25 17:14 UTC (permalink / raw)



"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:

> The "constant" in the declaration of Some_String is not only
> unnecessary, 

Unnecessary ??? The compiler can certainly take this into account to
optimize the code.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 11:50       ` Larry Kilgallen
  2005-04-25 17:13         ` Pascal Obry
@ 2005-04-25 17:38         ` Frank J. Lhota
  1 sibling, 0 replies; 17+ messages in thread
From: Frank J. Lhota @ 2005-04-25 17:38 UTC (permalink / raw)


"Larry Kilgallen" <Kilgallen@SpamCop.net> wrote in message 
news:QU8dL4j3Ijoo@eisner.encompasserve.org...
> It is required with Ada 83.

Yes, but this restriction was removed in Ada 95. Moreover, even before Ada 
95 there was a work-around for this:

    declare
       Init_Some_String : constant String := Integer'Image(Some_Integer);
       Some_String : String(Init_Some_String'Range) := Init_Some_String;
   begin
     ...play with Some_String
   end; 





^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 17:13         ` Pascal Obry
@ 2005-04-25 17:50           ` Björn Lundin
  2005-04-25 18:39             ` Pascal Obry
  0 siblings, 1 reply; 17+ messages in thread
From: Björn Lundin @ 2005-04-25 17:50 UTC (permalink / raw)
  To: Pascal Obry; +Cc: comp.lang.ada


2005-04-25 kl. 19.13 skrev Pascal Obry:

>
> Kilgallen@SpamCop.net (Larry Kilgallen) writes:
>
>> It is required with Ada 83.
>
> No it is not. Probably a check done by your compiler. GNAT does check 
> for
> constant string not declared as constant.

My compiler also says it is required (Alsys Ada on Aix)
I think this actually was a constraint in Ada 83 but removed in Ada 95

Björn Lundin
bnl at spray dot se




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 17:50           ` Björn Lundin
@ 2005-04-25 18:39             ` Pascal Obry
  2005-04-25 19:43               ` Björn Lundin
  2005-04-26  4:12               ` Wes Groleau
  0 siblings, 2 replies; 17+ messages in thread
From: Pascal Obry @ 2005-04-25 18:39 UTC (permalink / raw)



Bj�rn Lundin <bnl@spray.se> writes:

> My compiler also says it is required (Alsys Ada on Aix)
> I think this actually was a constraint in Ada 83 but removed in Ada 95

I see, it is not "constant" that is required. The problem was that Ada 83 was
not able to initialized unconstraint objects like strings.

There was 2 solutions:

   Str : constant String := "...";

or

   Str : String (1 .. 3) := "...";

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 18:39             ` Pascal Obry
@ 2005-04-25 19:43               ` Björn Lundin
  2005-04-26  8:41                 ` Jean-Pierre Rosen
  2005-04-26  4:12               ` Wes Groleau
  1 sibling, 1 reply; 17+ messages in thread
From: Björn Lundin @ 2005-04-25 19:43 UTC (permalink / raw)
  To: Pascal Obry; +Cc: comp.lang.ada


2005-04-25 kl. 20.39 skrev Pascal Obry:

>
> Björn Lundin <bnl@spray.se> writes:
>
>> My compiler also says it is required (Alsys Ada on Aix)
>> I think this actually was a constraint in Ada 83 but removed in Ada 95
>
> I see, it is not "constant" that is required. The problem was that Ada 
> 83 was
> not able to initialized unconstraint objects like strings.
>
> There was 2 solutions:
>
>    Str : constant String := "...";
>
> or
>
>    Str : String (1 .. 3) := "...";
>
> Pascal.

Correct, and when you don't know the length of the term to the right of 
the assignment, as
in the example (integer'image(An_Anteger)), then you are pretty much 
stuck with your first solution,
as Larry replied.

By the way Pascal,  I got AWS 1.4 running on Aix 4.3.3 on a production 
site.
(We did an extension to our warehouse management system for a customer 
with AWS)

I won't go to AWS 2.x for a while but to Aix 5.2 or 5,3 fairly shortly, 
but I expect no trouble.
( I did have some troubles building it, but anyway, I prefer to link it 
all statically, which wen't ok.
Only funny thing I saw was that the process hung on shutdown, which I 
traced to the syscalls
  close  and shutdown. I first got hung on shutdown, which i commented 
and then on close.
But when we shut the webserver program down, we want the process to go 
down as well
so this is no problem for me.)

We use gnat 3.16a on that machine, but we will use 5.03a later on.

>
>
Björn Lundin
bnl at spray dot se




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 11:40     ` David C. Hoos, Sr.
  2005-04-25 11:50       ` Larry Kilgallen
  2005-04-25 17:14       ` Pascal Obry
@ 2005-04-26  1:53       ` Jeffrey Carter
  2005-04-28 20:31       ` Simon Wright
  3 siblings, 0 replies; 17+ messages in thread
From: Jeffrey Carter @ 2005-04-26  1:53 UTC (permalink / raw)


David C. Hoos, Sr. wrote:
> Jeff C" <jcreem@yahoo.com> wrote in message 
> news:KIednSCHV-GzTfHfRVn-qw@comcast.com...
> 
>>   declare
>>     Some_String : constant String := Integer'Image(Some_Integer);
>>   begin
>>     ...play with Some_String
>>   end;
> 
> The "constant" in the declaration of Some_String is not only
> unnecessary, but would prevent some types of "playing"
> with Some_String.

It should be there, unless the "playing" modifies Some_String.

-- 
Jeff Carter
"I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
Mum! I'm a Red Sea pedestrian, and proud of it!"
Monty Python's Life of Brian
77



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 18:39             ` Pascal Obry
  2005-04-25 19:43               ` Björn Lundin
@ 2005-04-26  4:12               ` Wes Groleau
  2005-04-27  4:43                 ` Jeffrey Carter
  1 sibling, 1 reply; 17+ messages in thread
From: Wes Groleau @ 2005-04-26  4:12 UTC (permalink / raw)


Pascal Obry wrote:
> There was 2 solutions:
> 
>    Str : constant String := "...";
> 
> or
> 
>    Str : String (1 .. 3) := "...";

-- 3:
      Str     : constant String := Integer'Image(whatever);
      Str_Var : String (1 .. Str'Length) := Str;

but I am still scratching my head about the "reverse"
in the original question.

-- 
Wes Groleau

There are some ideas so wrong that only a
very intelligent person could believe in them.
                         -- George Orwell



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 19:43               ` Björn Lundin
@ 2005-04-26  8:41                 ` Jean-Pierre Rosen
  0 siblings, 0 replies; 17+ messages in thread
From: Jean-Pierre Rosen @ 2005-04-26  8:41 UTC (permalink / raw)


Bj�rn Lundin a �crit :
>> There was 2 solutions:
>>
>>    Str : constant String := "...";
>>
>> or
>>
>>    Str : String (1 .. 3) := "...";
>>
And the work-around was:
    Const_Str : constant String := "...";
    Str : String (Const_Str'Range) := Const_Str;

So the feature was, in fact, actually available.

I think the authors of Ada83 thought that they should avoid having to 
declare the bounds for:
    Mess: constant String (1..7) := "Message";

and didn't realize it was useful for variables too.

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-26  4:12               ` Wes Groleau
@ 2005-04-27  4:43                 ` Jeffrey Carter
  0 siblings, 0 replies; 17+ messages in thread
From: Jeffrey Carter @ 2005-04-27  4:43 UTC (permalink / raw)


Wes Groleau wrote:

> but I am still scratching my head about the "reverse"
> in the original question.

I think the OP used it to mean "inverse".

-- 
Jeff Carter
"What I wouldn't give for a large sock with horse manure in it."
Annie Hall
42



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: reverse Integer'image(someString);
  2005-04-25 11:40     ` David C. Hoos, Sr.
                         ` (2 preceding siblings ...)
  2005-04-26  1:53       ` Jeffrey Carter
@ 2005-04-28 20:31       ` Simon Wright
  3 siblings, 0 replies; 17+ messages in thread
From: Simon Wright @ 2005-04-28 20:31 UTC (permalink / raw)


"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:

> Jeff C" <jcreem@yahoo.com> wrote in message
> news:KIednSCHV-GzTfHfRVn-qw@comcast.com...
> > Adrien Plisson wrote:
> snip
> > What does work fine are:
> >
> > a)
> >
> >   Text_IO.Put_Line(Integer'Image(Some_Integer));
> >
> > b)
> >
> >   declare
> >     Some_String : constant String := Integer'Image(Some_Integer);
> >   begin
> >     ...play with Some_String
> >   end;
> 
> The "constant" in the declaration of Some_String is not only
> unnecessary, but would prevent some types of "playing"
> with Some_String.

I like the way GNAT (possibly with extra warnings, -gnatwaL) tells you
that something that is only initialized could have been declared
constant.

-- 
Simon Wright                               100% Ada, no bugs.



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2005-04-28 20:31 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-23 19:59 reverse Integer'image(someString); Doker
2005-04-25  9:16 ` Adrien Plisson
2005-04-25 11:10   ` Jeff C
2005-04-25 11:40     ` David C. Hoos, Sr.
2005-04-25 11:50       ` Larry Kilgallen
2005-04-25 17:13         ` Pascal Obry
2005-04-25 17:50           ` Björn Lundin
2005-04-25 18:39             ` Pascal Obry
2005-04-25 19:43               ` Björn Lundin
2005-04-26  8:41                 ` Jean-Pierre Rosen
2005-04-26  4:12               ` Wes Groleau
2005-04-27  4:43                 ` Jeffrey Carter
2005-04-25 17:38         ` Frank J. Lhota
2005-04-25 17:14       ` Pascal Obry
2005-04-26  1:53       ` Jeffrey Carter
2005-04-28 20:31       ` Simon Wright
2005-04-25  9:18 ` Martin Krischik

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