comp.lang.ada
 help / color / mirror / Atom feed
* enumeration_io: get error
@ 2002-06-15 21:06 Gino POLIDO
  2002-06-15 22:26 ` R. Tim Coslet
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Gino POLIDO @ 2002-06-15 21:06 UTC (permalink / raw)


Look at this. If you get "*" or another no alpha numeric character, there is
a loop and it raises a storagr_error.
How to do?

Thks

---------------------------------
package Mytype is

type Tmytype is (a,b,c);

end Mytype;

with Mytype;
with ada.text_io;

package Enumeration_Tmytype is new
ada.text_io.enumeration_io(Mytype.Tmytype);

with Mytype;
with Enumeration_Tmytype;
with ada.text_io;

procedure tests is
 input:Mytype.Tmytype;
begin
 for i in 1..4 loop
  ada.text_io.put("Choose(a,b, or c):");
  enumeration_Tmytype.get(input);
 end loop;

exception
 when others =>
  tests;
end tests;






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

* Re: enumeration_io: get error
  2002-06-15 21:06 enumeration_io: get error Gino POLIDO
@ 2002-06-15 22:26 ` R. Tim Coslet
  2002-06-15 23:10   ` Gino POLIDO
  2002-06-15 23:54 ` sk
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: R. Tim Coslet @ 2002-06-15 22:26 UTC (permalink / raw)


You are getting Storage_Error, because your exception handler (which is
handling the Data_Error exception raised by the get when something outside
the type is entered) is recursively calling tests. When you have done this
enough the stack overflows...

One way to handle this would be to use the "goto" in the handler, so that
the program iterates rather than recurses. However many people consider
"goto" as bad style. A "loop" can also be used, but I'll leave it up to you
to figure it out.

-- 
        R. Tim Coslet
        r_tim_coslet@pacbell.net

Technology, n. Domesticated natural phenomena.


> From: "Gino POLIDO" <gino.polido@wanadoo.fr>
> Organization: Wanadoo, l'internet avec France Telecom
> Newsgroups: comp.lang.ada
> Date: Sat, 15 Jun 2002 23:06:16 +0200
> Subject: enumeration_io: get error
> 
> Look at this. If you get "*" or another no alpha numeric character, there is
> a loop and it raises a storagr_error.
> How to do?
> 
> Thks
> 
> ---------------------------------
> package Mytype is
> 
> type Tmytype is (a,b,c);
> 
> end Mytype;
> 
> with Mytype;
> with ada.text_io;
> 
> package Enumeration_Tmytype is new
> ada.text_io.enumeration_io(Mytype.Tmytype);
> 
> with Mytype;
> with Enumeration_Tmytype;
> with ada.text_io;
> 
> procedure tests is
> input:Mytype.Tmytype;
> begin
> for i in 1..4 loop
> ada.text_io.put("Choose(a,b, or c):");
> enumeration_Tmytype.get(input);
> end loop;
> 
> exception
> when others =>
> tests;
> end tests;
> 
> 
> 




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

* Re: enumeration_io: get error
  2002-06-15 22:26 ` R. Tim Coslet
@ 2002-06-15 23:10   ` Gino POLIDO
  0 siblings, 0 replies; 7+ messages in thread
From: Gino POLIDO @ 2002-06-15 23:10 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2151 bytes --]

Ok.
But the problem is, if I enter something like 'm' or 'y' (it's outside de
type Mytype is (a,b,c)), the data_error exception is raised one time by the
get, then tests is recursively called. So  I have to enter again something.

But if I enter something like '*','%','/' instead of a letter like 'm', the
Data_Error is raised and tests is recursively called again and again until
storage_error and stack overflow. It doesn't stop!!!

Thks!

"R. Tim Coslet" <R_Tim_Coslet@pacbell.net> a �crit dans le message de news:
B9310B38.43F6%R_Tim_Coslet@pacbell.net...
> You are getting Storage_Error, because your exception handler (which is
> handling the Data_Error exception raised by the get when something outside
> the type is entered) is recursively calling tests. When you have done this
> enough the stack overflows...
>
> One way to handle this would be to use the "goto" in the handler, so that
> the program iterates rather than recurses. However many people consider
> "goto" as bad style. A "loop" can also be used, but I'll leave it up to
you
> to figure it out.
>
> --
>         R. Tim Coslet
>         r_tim_coslet@pacbell.net
>
> Technology, n. Domesticated natural phenomena.
>
>
> > From: "Gino POLIDO" <gino.polido@wanadoo.fr>
> > Organization: Wanadoo, l'internet avec France Telecom
> > Newsgroups: comp.lang.ada
> > Date: Sat, 15 Jun 2002 23:06:16 +0200
> > Subject: enumeration_io: get error
> >
> > Look at this. If you get "*" or another no alpha numeric character,
there is
> > a loop and it raises a storagr_error.
> > How to do?
> >
> > Thks
> >
> > ---------------------------------
> > package Mytype is
> >
> > type Tmytype is (a,b,c);
> >
> > end Mytype;
> >
> > with Mytype;
> > with ada.text_io;
> >
> > package Enumeration_Tmytype is new
> > ada.text_io.enumeration_io(Mytype.Tmytype);
> >
> > with Mytype;
> > with Enumeration_Tmytype;
> > with ada.text_io;
> >
> > procedure tests is
> > input:Mytype.Tmytype;
> > begin
> > for i in 1..4 loop
> > ada.text_io.put("Choose(a,b, or c):");
> > enumeration_Tmytype.get(input);
> > end loop;
> >
> > exception
> > when others =>
> > tests;
> > end tests;
> >
> >
> >
>





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

* Re: enumeration_io: get error
  2002-06-15 21:06 enumeration_io: get error Gino POLIDO
  2002-06-15 22:26 ` R. Tim Coslet
@ 2002-06-15 23:54 ` sk
       [not found] ` <3D0BD39B.FED8A0E4@myob.com>
  2002-06-16  2:12 ` Jeffrey Carter
  3 siblings, 0 replies; 7+ messages in thread
From: sk @ 2002-06-15 23:54 UTC (permalink / raw)


Hi,

Does it stop if you enter 'a', 'b' or 'c' for each
of the four times that your code requires ?

If it does, then examine closely a solution 
"R. Tim Coslet" suggested to you and then
question your own decision to recursively
call a program from within its own exception 
handler.

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: enumeration_io: get error
       [not found] ` <3D0BD39B.FED8A0E4@myob.com>
@ 2002-06-16  0:00   ` sk
  0 siblings, 0 replies; 7+ messages in thread
From: sk @ 2002-06-16  0:00 UTC (permalink / raw)


Hi,

> Does it stop if you enter 'a', 'b' or 'c' for each
> of the four times that your code requires ?

That is in fact 4 times for each time the exception 
handler is invoked as well as the "root" function.

So 1 bad character will require 4 good characters 
before it falls back, and then 3 good characters 
for it to finish the primary loop.

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: enumeration_io: get error
  2002-06-15 21:06 enumeration_io: get error Gino POLIDO
                   ` (2 preceding siblings ...)
       [not found] ` <3D0BD39B.FED8A0E4@myob.com>
@ 2002-06-16  2:12 ` Jeffrey Carter
  2002-06-16 19:59   ` sk
  3 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Carter @ 2002-06-16  2:12 UTC (permalink / raw)


The quick answer is not to use an instantiation of Enumeration_IO to do
the input. Use Get_Line to obtain a String, then use 'Value or the
version of Get that takes the value from a String to convert the String
to a value of the enumeration type. Use a loop to handle the exception
that occurs if the String does not contain the representation of an
enumeration value.

The long answer is to carefully review the semantics of
Enumeration_IO.Get. Pay special attention to the cases in which the next
character in the input is consumed and those in which the next character
is looked at but not consumed. You will find that characters such as '*'
are looked at but not consumed, meaning the next call to Get sees the
same character. In this particular example, this causes infinite
recursion.

It is left as an exercise for the reader to figure out how to deal with
this.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail



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

* Re: enumeration_io: get error
  2002-06-16  2:12 ` Jeffrey Carter
@ 2002-06-16 19:59   ` sk
  0 siblings, 0 replies; 7+ messages in thread
From: sk @ 2002-06-16 19:59 UTC (permalink / raw)


Hi,

Firstly, I quickly compiled (gnat 3.13p) the example 
and found my predictions about 4 correct entries 
followed by more to be totally WRONG. It seems as if
4 correct entries in a row exit the loop no matter 
how many times the exception handler was invoked.

This would suggest that the ARM (gnat-3.13p-docs)
section on "Exception Handling" statement is in
effect 

    > Then, the sequence_of_statements of the handler 
    > is executed; this execution replaces the 
    > abandoned portion of the execution of the
    > sequence_of_statements

Which I believe is saying that the code is behaving
as follows 

    procedure Tests is
    begin
        ...
        <implicit system exit>
    exception
        when Others =>

            procedure Tests is
            begin
                ...
                <implicit system exit>
            exception
                when Others =>

                    procedure Tests is ...

                        ... Etc until memory overflows
                        ... or four correct values are entered
                        <implicit system exit>

            end Tests;

    end Tests;

Is that a reasonable interpretation of what is going on ? 

Doesn't this then become one of those "erroneous" programs
that the standard says are your own fault ?

--

Jeffrey Carter <jrcarter@acm.org>
> ... carefully review the semantics of Enumeration_IO.Get. ...

I understand your "looked at but not consumed" statement,
but I am not sure (ARM "Input-Output for Enumeration Types")
where there is justification for the different alphabet and 
symbol character treatment. Would you be willing to explain
a little further ?

--
It would seem that the OP has invoked a "two-for-one"
deal on unexpected behaviours :-)


-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

end of thread, other threads:[~2002-06-16 19:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-15 21:06 enumeration_io: get error Gino POLIDO
2002-06-15 22:26 ` R. Tim Coslet
2002-06-15 23:10   ` Gino POLIDO
2002-06-15 23:54 ` sk
     [not found] ` <3D0BD39B.FED8A0E4@myob.com>
2002-06-16  0:00   ` sk
2002-06-16  2:12 ` Jeffrey Carter
2002-06-16 19:59   ` sk

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