comp.lang.ada
 help / color / mirror / Atom feed
* Length of unbounded_string.
@ 2011-10-16  8:48 ldries46
  2011-10-16  9:59 ` Niklas Holsti
  2011-10-16 10:14 ` Vinzent Hoefler
  0 siblings, 2 replies; 33+ messages in thread
From: ldries46 @ 2011-10-16  8:48 UTC (permalink / raw)


In my program I use unbounded_string str

I want to change the last character of the string using the program lines

2205  len := Length(str);
2206  Replace_Slice(str, len, len, "G");

Then I get the following message printed in my exception part of the program

Error type    : CONSTRAINT_ERROR
In phase      : Step 1
in function   : Continuation
Error info    : trans2ada.adb:2206 range check failed

file line nr  :  1
Original line : /* GtkPrintJob
Next line     :  * Copyright (C) 2006 John (J5) Palmieri  <johnp@redhat.com>

In this print out the Original line represents "str".

Is there a problem with the Length function or do I interpret something 
wrong?

I use the GNAT GPS environment :
GPS 5.0.1 (20110113) hosted on i686-pc-mingw32
GNAT GPL 2011 (20110428)

L. Dries 




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

* Re: Length of unbounded_string.
  2011-10-16  8:48 ldries46
@ 2011-10-16  9:59 ` Niklas Holsti
  2011-10-16 12:06   ` ldries46
  2011-10-16 12:52   ` ldries46
  2011-10-16 10:14 ` Vinzent Hoefler
  1 sibling, 2 replies; 33+ messages in thread
From: Niklas Holsti @ 2011-10-16  9:59 UTC (permalink / raw)


On 11-10-16 10:48 , ldries46 wrote:
> In my program I use unbounded_string str
>
> I want to change the last character of the string using the program lines
>
> 2205 len := Length(str);
> 2206 Replace_Slice(str, len, len, "G");

Similar code works for me (debian, gnat).

It seems to me that code like the above can fail with Constraint_Error 
only if str is the null string, in which case len = 0, which causes a 
Constraint_Error in the call because the 2nd parameter of Replace_Slice 
is of subtype Positive.

> Then I get the following message printed in my exception part of the
> program
   ...
> Original line : /* GtkPrintJob
   ...
> In this print out the Original line represents "str".

Are you certain that your "str" is really that, and is not a null 
string? I would put a check in the code, before the call of 
Replace_Slice, and not trust the exception messages.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

* Re: Length of unbounded_string.
  2011-10-16  8:48 ldries46
  2011-10-16  9:59 ` Niklas Holsti
@ 2011-10-16 10:14 ` Vinzent Hoefler
  1 sibling, 0 replies; 33+ messages in thread
From: Vinzent Hoefler @ 2011-10-16 10:14 UTC (permalink / raw)


ldries46 wrote:

> In my program I use unbounded_string str
>
> I want to change the last character of the string using the program lines
>
> 2205  len := Length(str);
> 2206  Replace_Slice(str, len, len, "G");

This seems correct to me. Although I am not sure, where ARM A4.3(74.1/1) would
lead us here. ;)

> Then I get the following message printed in my exception part of the program
>
> Error type    : CONSTRAINT_ERROR
> In phase      : Step 1
> in function   : Continuation
> Error info    : trans2ada.adb:2206 range check failed
>
> file line nr  :  1
> Original line : /* GtkPrintJob
> Next line     :  * Copyright (C) 2006 John (J5) Palmieri  <johnp@redhat.com>
>
> In this print out the Original line represents "str".
>
> Is there a problem with the Length function or do I interpret something
> wrong?

Well, I can't reproduce the problem here. Test code was:

-- 8< --
     X := Ada.Strings.Unbounded.To_Unbounded_String ("ABCD");
     Y := Ada.Strings.Unbounded.Length (X);

     Ada.Strings.Unbounded.Replace_Slice (Source => X,
                                          Low    => Y,
                                          High   => Y,
                                          By     => "Z");
     Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.To_String (X));
-- 8< --

It correctly prints "ABCZ".

Same compiler version, so it seems something is wrong in your part of the
code.

First thing that comes to mind is that maybe the string in question does not
have a lower bound of 1, but that's close to impossible with Unbounded_String.

Another idea: Maybe, the string's last character is a null character and
somethings gets garbled on the way between the C- and the Ada-world?


Vinzent.

-- 
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.



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

* Re: Length of unbounded_string.
  2011-10-16  9:59 ` Niklas Holsti
@ 2011-10-16 12:06   ` ldries46
  2011-10-16 12:52   ` ldries46
  1 sibling, 0 replies; 33+ messages in thread
From: ldries46 @ 2011-10-16 12:06 UTC (permalink / raw)


Sorry I just thought to simplify the problem but did that the  wrong way
my real problem is in the following code:

ch := Element(str, len);
if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
   nr := nr + 1;
   str := str & " " & Next_Line;

where  in the first line
print str.reference.data
$24 = "static void gtk_print_job_set_property (GObject *object", ',' 
<repeats 11 times>, 
"["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
len = 56
ch =  ',' in fact the first
print str.reference.data
$386 = "static void gtk_print_job_set_property (GObject *object, guint", ' ' 
<repeats 18 times>, 
"prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
in the display option this shows as
"static void gtk_print_job_set_property (GObject *object guint", ' ' 
<repeats 18 times>, 
"prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
and when I save that line later on the , after object is also disapperared

L. Dries
"Niklas Holsti"  schreef in bericht news:9fvo6aF3d6U1@mid.individual.net...

On 11-10-16 10:48 , ldries46 wrote:
> In my program I use unbounded_string str
>
> I want to change the last character of the string using the program lines
>
> 2205 len := Length(str);
> 2206 Replace_Slice(str, len, len, "G");

Similar code works for me (debian, gnat).

It seems to me that code like the above can fail with Constraint_Error
only if str is the null string, in which case len = 0, which causes a
Constraint_Error in the call because the 2nd parameter of Replace_Slice
is of subtype Positive.

> Then I get the following message printed in my exception part of the
> program
   ...
> Original line : /* GtkPrintJob
   ...
> In this print out the Original line represents "str".

Are you certain that your "str" is really that, and is not a null
string? I would put a check in the code, before the call of
Replace_Slice, and not trust the exception messages.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       . 




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

* Re: Length of unbounded_string.
  2011-10-16  9:59 ` Niklas Holsti
  2011-10-16 12:06   ` ldries46
@ 2011-10-16 12:52   ` ldries46
  2011-10-16 13:00     ` Niklas Holsti
  1 sibling, 1 reply; 33+ messages in thread
From: ldries46 @ 2011-10-16 12:52 UTC (permalink / raw)


Sorry I just thought to simplify the problem but did that the  wrong way
my real problem is in the following code:

ch := Element(str, len);
if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
   nr := nr + 1;
   str := str & " " & Next_Line;

where  in the first line
print str.reference.data
$24 = "static void gtk_print_job_set_property (GObject *object", ','
<repeats 11 times>,
"["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
len = 56
ch =  ',' in fact the first
print str.reference.data
$386 = "static void gtk_print_job_set_property (GObject *object, guint", ' ' 
<repeats 18 times>,
"prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
in the display option instead of rhe print option this shows as
"static void gtk_print_job_set_property (GObject *object guint", ' ' 
<repeats 18 times>,
"prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
and when I save that line later on the comma after object is also 
disapperared

L. Dries

"Niklas Holsti"  schreef in bericht news:9fvo6aF3d6U1@mid.individual.net...

On 11-10-16 10:48 , ldries46 wrote:
> In my program I use unbounded_string str
>
> I want to change the last character of the string using the program lines
>
> 2205 len := Length(str);
> 2206 Replace_Slice(str, len, len, "G");

Similar code works for me (debian, gnat).

It seems to me that code like the above can fail with Constraint_Error
only if str is the null string, in which case len = 0, which causes a
Constraint_Error in the call because the 2nd parameter of Replace_Slice
is of subtype Positive.

> Then I get the following message printed in my exception part of the
> program
   ...
> Original line : /* GtkPrintJob
   ...
> In this print out the Original line represents "str".

Are you certain that your "str" is really that, and is not a null
string? I would put a check in the code, before the call of
Replace_Slice, and not trust the exception messages.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       . 




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

* Re: Length of unbounded_string.
  2011-10-16 12:52   ` ldries46
@ 2011-10-16 13:00     ` Niklas Holsti
  2011-10-17  7:39       ` ldries46
  0 siblings, 1 reply; 33+ messages in thread
From: Niklas Holsti @ 2011-10-16 13:00 UTC (permalink / raw)


On 11-10-16 14:52 , ldries46 wrote:
> Sorry I just thought to simplify the problem but did that the wrong way
> my real problem is in the following code:
>
> ch := Element(str, len);
> if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
> nr := nr + 1;
> str := str & " " & Next_Line;

And what *is* your problem with this code? I don't understand the gdb 
mess below, or what your are trying to show with it. Can you explain the 
problem in Ada terms, without digging into the internals of 
Unbounded_String?


>
> where in the first line
> print str.reference.data
> $24 = "static void gtk_print_job_set_property (GObject *object", ','
> <repeats 11 times>,
> "["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
>
> len = 56
> ch = ',' in fact the first
> print str.reference.data
> $386 = "static void gtk_print_job_set_property (GObject *object, guint",
> ' ' <repeats 18 times>,
> "prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
>
> in the display option instead of rhe print option this shows as
> "static void gtk_print_job_set_property (GObject *object guint", ' '
> <repeats 18 times>,
> "prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
>
> and when I save that line later on the comma after object is also
> disapperared
>
> L. Dries


-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

* Re: Length of unbounded_string.
  2011-10-16 13:00     ` Niklas Holsti
@ 2011-10-17  7:39       ` ldries46
  2011-10-17 19:49         ` Niklas Holsti
  0 siblings, 1 reply; 33+ messages in thread
From: ldries46 @ 2011-10-17  7:39 UTC (permalink / raw)


I have to strings I want to concatenate with a space in between. The first 
(str) ends with a ','.
The output seems to be a concatenation where the ',' is missing.
A can see with the debugging facilities that before the concatenation there 
is a ',' and after the concatenation depending on the type of facility I use 
the comma is present (debug\print) or is not (debug\display).
The last one is consistent with the display of the line in a gtk window.
For further use I need that comma, but I cannot add it explicitly because as 
can beseen in the code I can reach rhat code also in some other cases.

L. Dries
"Niklas Holsti"  schreef in bericht news:9g02plFrnlU1@mid.individual.net...

On 11-10-16 14:52 , ldries46 wrote:
> Sorry I just thought to simplify the problem but did that the wrong way
> my real problem is in the following code:
>
> ch := Element(str, len);
> if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
> nr := nr + 1;
> str := str & " " & Next_Line;

And what *is* your problem with this code? I don't understand the gdb
mess below, or what your are trying to show with it. Can you explain the
problem in Ada terms, without digging into the internals of
Unbounded_String?


>
> where in the first line
> print str.reference.data
> $24 = "static void gtk_print_job_set_property (GObject *object", ','
> <repeats 11 times>,
> "["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
>
> len = 56
> ch = ',' in fact the first
> print str.reference.data
> $386 = "static void gtk_print_job_set_property (GObject *object, guint",
> ' ' <repeats 18 times>,
> "prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
>
> in the display option instead of rhe print option this shows as
> "static void gtk_print_job_set_property (GObject *object guint", ' '
> <repeats 18 times>,
> "prop_id,["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]["0d"]["f0"]["ad"]["ba"]"
>
> and when I save that line later on the comma after object is also
> disapperared
>
> L. Dries


-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       . 




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

* Re: Length of unbounded_string.
  2011-10-17  7:39       ` ldries46
@ 2011-10-17 19:49         ` Niklas Holsti
  2011-10-18 11:47           ` ldries46
  0 siblings, 1 reply; 33+ messages in thread
From: Niklas Holsti @ 2011-10-17 19:49 UTC (permalink / raw)


On 11-10-17 09:39 , ldries46 wrote:
> I have to strings I want to concatenate with a space in between. The
> first (str) ends with a ','.
> The output seems to be a concatenation where the ',' is missing.
> A can see with the debugging facilities that before the concatenation
> there is a ',' and after the concatenation depending on the type of
> facility I use the comma is present (debug\print) or is not
> (debug\display).

And what happens if you simply print it with Ada.Text_IO?

In my experience, gdb sometimes (well, rather often) prints complex Ada 
structures incorrectly or incompletely.

> The last one is consistent with the display of the line in a gtk window.
> For further use I need that comma, but I cannot add it explicitly
> because as can beseen in the code I can reach rhat code also in some
> other cases.

Of course you could divide the code inte more cases, separating the 
comma case from the other cases.

>
> L. Dries
> "Niklas Holsti" schreef in bericht news:9g02plFrnlU1@mid.individual.net...
>
> On 11-10-16 14:52 , ldries46 wrote:
>> Sorry I just thought to simplify the problem but did that the wrong way
>> my real problem is in the following code:
>>
>> ch := Element(str, len);
>> if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
>> nr := nr + 1;
>> str := str & " " & Next_Line;

That code is incomplete. Where is the "end if"?

If you want more help, please try to make a small, self-contained 
example in which the problem occurs, and show the whole code.

>>
>> where in the first line
>> print str.reference.data
>> $24 = "static void gtk_print_job_set_property (GObject *object", ','

Why is gdb speaking of GObject? I tought "str" was mean to be 
Ada.Strings.Unbounded.Unbounded_String, not some Gtk type.


-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

* Re: Length of unbounded_string.
  2011-10-17 19:49         ` Niklas Holsti
@ 2011-10-18 11:47           ` ldries46
  2011-10-18 17:54             ` Niklas Holsti
  0 siblings, 1 reply; 33+ messages in thread
From: ldries46 @ 2011-10-18 11:47 UTC (permalink / raw)


The program I am writing is a window oriented program. I am using GTKADA for 
the windows. When I write the string to the window it also misses the comma.
Also further on in the program before writing to the window I check for the 
comma but the function I need to do is not performed so that is another 
reason why I think the comma is not present.

"Niklas Holsti"  schreef in bericht news:9g3f3kFfr7U1@mid.individual.net...

On 11-10-17 09:39 , ldries46 wrote:
> I have to strings I want to concatenate with a space in between. The
> first (str) ends with a ','.
> The output seems to be a concatenation where the ',' is missing.
> A can see with the debugging facilities that before the concatenation
> there is a ',' and after the concatenation depending on the type of
> facility I use the comma is present (debug\print) or is not
> (debug\display).

And what happens if you simply print it with Ada.Text_IO?

In my experience, gdb sometimes (well, rather often) prints complex Ada
structures incorrectly or incompletely.

> The last one is consistent with the display of the line in a gtk window.
> For further use I need that comma, but I cannot add it explicitly
> because as can beseen in the code I can reach rhat code also in some
> other cases.

Of course you could divide the code inte more cases, separating the
comma case from the other cases.

>
> L. Dries
> "Niklas Holsti" schreef in bericht news:9g02plFrnlU1@mid.individual.net...
>
> On 11-10-16 14:52 , ldries46 wrote:
>> Sorry I just thought to simplify the problem but did that the wrong way
>> my real problem is in the following code:
>>
>> ch := Element(str, len);
>> if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
>> nr := nr + 1;
>> str := str & " " & Next_Line;

That code is incomplete. Where is the "end if"?

If you want more help, please try to make a small, self-contained
example in which the problem occurs, and show the whole code.

>>
>> where in the first line
>> print str.reference.data
>> $24 = "static void gtk_print_job_set_property (GObject *object", ','

Why is gdb speaking of GObject? I tought "str" was mean to be
Ada.Strings.Unbounded.Unbounded_String, not some Gtk type.


-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       . 




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

* Re: Length of unbounded_string.
  2011-10-18 11:47           ` ldries46
@ 2011-10-18 17:54             ` Niklas Holsti
  2011-10-19  2:38               ` ldries46
  0 siblings, 1 reply; 33+ messages in thread
From: Niklas Holsti @ 2011-10-18 17:54 UTC (permalink / raw)


On 11-10-18 13:47 , ldries46 wrote:
> The program I am writing is a window oriented program. I am using GTKADA
> for the windows. When I write the string to the window it also misses
> the comma.
> Also further on in the program before writing to the window I check for
> the comma but the function I need to do is not performed so that is
> another reason why I think the comma is not present.

So, it is likely that the comma is absent. But I can't think about why 
it is absent, and whether this is a compiler/library erroror an error in 
your code, until you show the complete code that you think should make 
the comma present.

Sorry, but I can do nothing more.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

* Re: Length of unbounded_string.
  2011-10-18 17:54             ` Niklas Holsti
@ 2011-10-19  2:38               ` ldries46
  2011-10-19  6:07                 ` Niklas Holsti
                                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: ldries46 @ 2011-10-19  2:38 UTC (permalink / raw)


The complete code of which I would conclude that the comma should be present 
is:
--------------------------------------------------------------------------------
-- The procedure adds Lines together when a "," is the end of the line
-- statements or when the end of the line is not a ";" or "{" or "}"
--------------------------------------------------------------------------------
   procedure Continuation(str : in out Unbounded_String; nr : in out 
integer) is
      len : integer;
      ch  : character;
      ok  : boolean := false;
   begin
      Proc_Stack.Push(To_Unbounded_String("Continuation"));                  
                 -- a Stack procedure that is used for the error messages 
the program can produce
      while not ok loop
         len := Length(str);
         if len /= 0 then
            ch := Element(str, len);
            if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
               nr := nr + 1;
               ch := Element(Next_Line, 
    -- Next_LIne is a unbounded_string that can be connected to str
               while ch = ' ' or ch = ASCII.HT loop
                  Replace_Slice(Next_Line, 1, 1, "");
                  ch := Element(Next_Line, 1);
               end loop;
               str := str & " " & 
           -- After this statement the error is found by the display 
function of the GDB
               Original_Line := 
     -- Original Line is only meant for the error messges
               if nr < Buffer1.Length - 1 
     -- Buffer1 is a buffer of unbounded_atring's thatis the source for as 
well str as Next_Line
                  Next_Line := Buffer1.Get_Buffer( nr + 
     -- nr is the line nr in the buffer where str is located
               else
                  Next_Line := To_Unbounded_String("");
            end if;
            else
               ok := true;
            end if;
         else
            ok := true;
         end if;
      end loop;
      Proc_Stack.Remove;                                                     
                                           -- Removes "continuation" from 
the stack
   end Continuation;

The error is somewhere in this routine

"Niklas Holsti"  schreef in bericht news:9g5snkFlh0U1@mid.individual.net...

On 11-10-18 13:47 , ldries46 wrote:
> The program I am writing is a window oriented program. I am using GTKADA
> for the windows. When I write the string to the window it also misses
> the comma.
> Also further on in the program before writing to the window I check for
> the comma but the function I need to do is not performed so that is
> another reason why I think the comma is not present.

So, it is likely that the comma is absent. But I can't think about why
it is absent, and whether this is a compiler/library erroror an error in
your code, until you show the complete code that you think should make
the comma present.

Sorry, but I can do nothing more.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       . 




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

* Re: Length of unbounded_string.
  2011-10-19  2:38               ` ldries46
@ 2011-10-19  6:07                 ` Niklas Holsti
  2011-10-24 15:10                   ` ldries46
  2011-10-19  6:37                 ` Simon Wright
  2011-10-19 14:48                 ` Alex Mentis
  2 siblings, 1 reply; 33+ messages in thread
From: Niklas Holsti @ 2011-10-19  6:07 UTC (permalink / raw)


On 11-10-19 04:38 , ldries46 wrote:
> The complete code of which I would conclude that the comma should be
> present is:

    [ snip ]

 >    nr := nr + 1;
 >    ch := Element(Next_Line,    -- Next_LIne is a unbounded_string
 >          that can be connected to str

The assignment to ch is incomplete, there should be something after the 
comma. Looking at the loop below, I guess the statement is meant to be

    ch := Element(Next_Line, 1);

Also, at this point in the code, Next_Line has not been given any value, 
it has not even been declared. Is it a global variable? What does it 
contain when your problem occurs?

 >  while ch = ' ' or ch = ASCII.HT loop
 >     Replace_Slice(Next_Line, 1, 1, "");
 >     ch := Element(Next_Line, 1);
 >  end loop;

That loop will end badly if Next_Line contains only whitespace. You 
should exit the loop when the Replace_Slice makes Next_Line a null string.

> str := str & " " & -- After this statement the error is found by the
>        display function of the GDB
> Original_Line := -- Original Line is only meant for the error messges

Both those statements are syntactically incomplete. The first one ends 
with an operator "&"; there should be at least one more operand, and a 
terminating semicolon. The second one ends with ":=".

 >     Next_Line := To_Unbounded_String("");

You should exit the outer loop ("while not ok") at this point, I think, 
because otherwise you can loop back to the statement

    ch := Element(Next_Line, 1);

with Next_Line holding a null string, which is an indexing error.

I notice that you check for tab characters (HT). Can it happen that the 
string contains backspace characters? If the string has a comma, then a 
backspace, the comma is perhaps not visible on the screen when the 
string is displayed.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

* Re: Length of unbounded_string.
  2011-10-19  2:38               ` ldries46
  2011-10-19  6:07                 ` Niklas Holsti
@ 2011-10-19  6:37                 ` Simon Wright
  2011-10-19 14:48                 ` Alex Mentis
  2 siblings, 0 replies; 33+ messages in thread
From: Simon Wright @ 2011-10-19  6:37 UTC (permalink / raw)


"ldries46" <bertus.dries@planet.nl> writes:

> The complete code of which I would conclude that the comma should be
> present is:

... an incomplete procedure that won't compile! Why not post *the whole,
unedited* procedure? preferably with

  * a test data set,
  *  what you think it should produce,
  *  what it does produce.



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

* Re: Length of unbounded_string.
  2011-10-19  2:38               ` ldries46
  2011-10-19  6:07                 ` Niklas Holsti
  2011-10-19  6:37                 ` Simon Wright
@ 2011-10-19 14:48                 ` Alex Mentis
  2011-10-24 17:04                   ` ldries46
  2 siblings, 1 reply; 33+ messages in thread
From: Alex Mentis @ 2011-10-19 14:48 UTC (permalink / raw)


ldries46 wrote:

> The complete code of which I would conclude that the comma should be
> present is:
 . . . 
>            ch := Element(str, len);
>            if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
                . . .
>            end if;

The check to see if ch = ',' seems superfluous here. Since ',' is not a
semi-colon or a brace, the (ch /= ';' and ch /= '{' and ch /= '}')
condition will suffice to execute this branch when ch = ',' (or any
other non semi-colon, left-brace, or right-brace character for that
matter).

Could your problem possibly be that you are appending in more cases
than you expect?

Alex



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

* Re: Length of unbounded_string.
  2011-10-19  6:07                 ` Niklas Holsti
@ 2011-10-24 15:10                   ` ldries46
  0 siblings, 0 replies; 33+ messages in thread
From: ldries46 @ 2011-10-24 15:10 UTC (permalink / raw)


1. Indeed for some reason then the 1); is of the E-mail but the compiler 
would not have compiled the program without.
ch now has the value of the first character of Next_Line.
2. Next Line is a Global variable to be used in a lot of routines before and 
after this one.
3. You are right but I am sure the Next_Line has other characters in the 
line. If not the program would have never come in this routine.
4. I see that the message was not correctly received both statements also 
had correct syntax.
    str := str & " " & Next_Line;
    Original_Line := str;
5. The string should not have BackSpaces but I think that if so comma should 
be found with a next position statement searching for it, and it did not.

"Niklas Holsti"  schreef in bericht news:9g77mgFribU1@mid.individual.net...

On 11-10-19 04:38 , ldries46 wrote:
> The complete code of which I would conclude that the comma should be
> present is:

    [ snip ]

>    nr := nr + 1;
>    ch := Element(Next_Line,    -- Next_LIne is a unbounded_string
>          that can be connected to str

The assignment to ch is incomplete, there should be something after the
comma. Looking at the loop below, I guess the statement is meant to be

    ch := Element(Next_Line, 1);

Also, at this point in the code, Next_Line has not been given any value,
it has not even been declared. Is it a global variable? What does it
contain when your problem occurs?

>  while ch = ' ' or ch = ASCII.HT loop
>     Replace_Slice(Next_Line, 1, 1, "");
>     ch := Element(Next_Line, 1);
>  end loop;

That loop will end badly if Next_Line contains only whitespace. You
should exit the loop when the Replace_Slice makes Next_Line a null string.

> str := str & " " & -- After this statement the error is found by the
>        display function of the GDB
> Original_Line := -- Original Line is only meant for the error messges

Both those statements are syntactically incomplete. The first one ends
with an operator "&"; there should be at least one more operand, and a
terminating semicolon. The second one ends with ":=".

>     Next_Line := To_Unbounded_String("");

You should exit the outer loop ("while not ok") at this point, I think,
because otherwise you can loop back to the statement

    ch := Element(Next_Line, 1);

with Next_Line holding a null string, which is an indexing error.

I notice that you check for tab characters (HT). Can it happen that the
string contains backspace characters? If the string has a comma, then a
backspace, the comma is perhaps not visible on the screen when the
string is displayed.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       . 




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

* Re: Length of unbounded_string.
  2011-10-19 14:48                 ` Alex Mentis
@ 2011-10-24 17:04                   ` ldries46
  0 siblings, 0 replies; 33+ messages in thread
From: ldries46 @ 2011-10-24 17:04 UTC (permalink / raw)


No, while debugging I found tthat the first comma at the end of a line 
disappeared and concatenated to the following line.

The if statement may be not to logical but the different cases in which 
concatenation has to be done are al defined.
May be later on a better condition can be defined.

"Alex Mentis"  schreef in bericht news:j7mo0r$cfc$1@dont-email.me...

ldries46 wrote:

> The complete code of which I would conclude that the comma should be
> present is:
. . .
>            ch := Element(str, len);
>            if ch = ',' or (ch /= ';' and ch /= '{' and ch /= '}') then
                . . .
>            end if;

The check to see if ch = ',' seems superfluous here. Since ',' is not a
semi-colon or a brace, the (ch /= ';' and ch /= '{' and ch /= '}')
condition will suffice to execute this branch when ch = ',' (or any
other non semi-colon, left-brace, or right-brace character for that
matter).

Could your problem possibly be that you are appending in more cases
than you expect?

Alex 




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

* Re: Length of unbounded_string.
@ 2011-10-25  9:37 ldries46
  2011-10-25 17:57 ` Jeffrey Carter
  2011-10-25 20:23 ` Vadim Godunko
  0 siblings, 2 replies; 33+ messages in thread
From: ldries46 @ 2011-10-25  9:37 UTC (permalink / raw)


I just found the following  extra relevant points:
Instead of <Str := Str & " " & Next_Line;> I put in the line <Str := Str & 
"x " & Next_Line;>
This showed that  with Str := "str," en Next_Line := "Next" the output 
became  "str x Next"
When I changed Str to Str := "strx" the output changed  to "strxx Next"
This looks like the comma has a special meaning within an Unbounded String

ldries46




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

* Re: Length of unbounded_string.
  2011-10-25  9:37 Length of unbounded_string ldries46
@ 2011-10-25 17:57 ` Jeffrey Carter
  2011-10-28  2:54   ` ldries46
  2011-10-25 20:23 ` Vadim Godunko
  1 sibling, 1 reply; 33+ messages in thread
From: Jeffrey Carter @ 2011-10-25 17:57 UTC (permalink / raw)


On 10/25/2011 02:37 AM, ldries46 wrote:
> I just found the following extra relevant points:
> Instead of <Str := Str & " " & Next_Line;> I put in the line <Str := Str & "x "
> & Next_Line;>
> This showed that with Str := "str," en Next_Line := "Next" the output became
> "str x Next"
> When I changed Str to Str := "strx" the output changed to "strxx Next"
> This looks like the comma has a special meaning within an Unbounded String

No Character has a special meaning in a String or an Unbounded_String. This 
appears to be a problem with the way you're viewing the contents.

with Ada.Strings.Unbounded;
with Ada.Text_IO;

procedure US_Test is
    use Ada.Strings.Unbounded;

    Str_Start : constant Unbounded_String := To_Unbounded_String ("str,");
    Next_Line : constant Unbounded_String := To_Unbounded_String ("Next");

    Str : Unbounded_String := Str_Start;
begin -- US_Test
    Str := Str & " " & Next_Line;
    Ada.Text_IO.Put_Line (Item => '>' & To_String (Str) & '<');
    Str := Str_Start;
    Str := Str & "x " & Next_Line;
    Ada.Text_IO.Put_Line (Item => '>' & To_String (Str) & '<');
    Str := To_Unbounded_String ("strx");
    Str := Str & "x " & Next_Line;
    Ada.Text_IO.Put_Line (Item => '>' & To_String (Str) & '<');
end US_Test;

jrcarter@jrcarter-gateway-1:~/Code$ gnatmake -gnaton -O2 -j2 us_test.adb
gcc-4.4 -c -gnaton -O2 us_test.adb
gnatbind -x us_test.ali
gnatlink us_test.ali
jrcarter@jrcarter-gateway-1:~/Code$ ./us_test
 >str, Next<
 >str,x Next<
 >strxx Next<

This is GNAT 4.4.5 on Ubuntu 11.04. If this program gives different results on 
your system, let us know.

-- 
Jeff Carter
"Blessed are they who convert their neighbors'
oxen, for they shall inhibit their girth."
Monty Python's Life of Brian
83



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

* Re: Length of unbounded_string.
  2011-10-25  9:37 Length of unbounded_string ldries46
  2011-10-25 17:57 ` Jeffrey Carter
@ 2011-10-25 20:23 ` Vadim Godunko
  2011-10-25 21:28   ` Simon Wright
  1 sibling, 1 reply; 33+ messages in thread
From: Vadim Godunko @ 2011-10-25 20:23 UTC (permalink / raw)


On Oct 25, 11:37 am, "ldries46" <bertus.dr...@planet.nl> wrote:
> I just found the following  extra relevant points:
> Instead of <Str := Str & " " & Next_Line;> I put in the line <Str := Str &
> "x " & Next_Line;>
> This showed that  with Str := "str," en Next_Line := "Next" the output
> became  "str x Next"
> When I changed Str to Str := "strx" the output changed  to "strxx Next"
> This looks like the comma has a special meaning within an Unbounded String
>
No characters (even NUL) has special meaning in Unbounded_String, but
of course it can be bug. It would be nice to have small and compilable
reproducer, as well as information about your system and compiler.



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

* Re: Length of unbounded_string.
  2011-10-25 20:23 ` Vadim Godunko
@ 2011-10-25 21:28   ` Simon Wright
  2011-10-26  4:41     ` Simon Wright
  2011-10-26 22:47     ` Randy Brukardt
  0 siblings, 2 replies; 33+ messages in thread
From: Simon Wright @ 2011-10-25 21:28 UTC (permalink / raw)


Vadim Godunko <vgodunko@gmail.com> writes:

> It would be nice to have small and compilable reproducer, as well as
> information about your system and compiler.

I think this is the 4th time you've been asked for this! NB, 'small'
means also 'stand-alone'; just plain Ada, no Gtk etc. Write the
reproducer as a complete working program, make sure it demonstrates the
effect you're seeing, then attach it to a message (paste it into the
message if you must, or put it on Dropbox or pastebin), don't re-type
it. I don't think anyone has ever managed to re-type a program code into
Usenet without a mistake.



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

* Re: Length of unbounded_string.
  2011-10-25 21:28   ` Simon Wright
@ 2011-10-26  4:41     ` Simon Wright
  2011-10-26 22:47     ` Randy Brukardt
  1 sibling, 0 replies; 33+ messages in thread
From: Simon Wright @ 2011-10-26  4:41 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Vadim Godunko <vgodunko@gmail.com> writes:
>
>> It would be nice to have small and compilable reproducer, as well as
>> information about your system and compiler.
>
> I think this is the 4th time you've been asked for this!

Sorry, of course I meant ldries46, not Vadim.



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

* Re: Length of unbounded_string.
  2011-10-25 21:28   ` Simon Wright
  2011-10-26  4:41     ` Simon Wright
@ 2011-10-26 22:47     ` Randy Brukardt
  2011-10-27  8:05       ` AdaMagica
  2011-10-27  8:56       ` Simon Wright
  1 sibling, 2 replies; 33+ messages in thread
From: Randy Brukardt @ 2011-10-26 22:47 UTC (permalink / raw)


"Simon Wright" <simon@pushface.org> wrote in message 
news:m2zkgopxr2.fsf@pushface.org...
...
> I think this is the 4th time you've been asked for this! NB, 'small'
> means also 'stand-alone'; just plain Ada, no Gtk etc. Write the
> reproducer as a complete working program, make sure it demonstrates the
> effect you're seeing, then attach it to a message (paste it into the
> message if you must, or put it on Dropbox or pastebin), don't re-type
> it. I don't think anyone has ever managed to re-type a program code into
> Usenet without a mistake.

This is always a problem for any sort of help desk (even an informal one 
like this newsgroup). I can't count the number of times that I was called or 
e-mailed a problem with Janus/Ada where the program fragment was too small 
to figure out what the problem was. In cases like that, it is just a stab in 
the dark to try to help (and asking for more is often considered rude and 
not helpful - help desk is a nearly thankless job).

Even people who should know better do it (and I know I have, too). It's a 
pain to create a reproducing example, but a lot of time when I do that, it 
becomes clear what is wrong (and it often is "operator error"!).

                                   Randy.





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

* Re: Length of unbounded_string.
  2011-10-26 22:47     ` Randy Brukardt
@ 2011-10-27  8:05       ` AdaMagica
  2011-10-27  8:56       ` Simon Wright
  1 sibling, 0 replies; 33+ messages in thread
From: AdaMagica @ 2011-10-27  8:05 UTC (permalink / raw)


On 27 Okt., 00:47, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
> "Simon Wright" <si...@pushface.org> wrote in message
>
> > I think this is the 4th time you've been asked for this! NB, 'small'
> > means also 'stand-alone'; just plain Ada, no Gtk etc. Write the...
>
> This is always a problem for any sort of help desk (even an informal one
> like this newsgroup). I can't count the number of times that I was called or
> e-mailed a problem with Janus/Ada where the program fragment was too small
> to figure out what the problem was. In cases like that, it is just a stab in
> the dark to try to help (and asking for more is often considered rude and
> not helpful - help desk is a nearly thankless job).

There are some help desks (or hotlines), especially the one of the
German Telecom, which reply in a form which plainly shows that they
haven't even read the report.

So the problem with hotlines is often on both sides (but not in CLA).



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

* Re: Length of unbounded_string.
  2011-10-26 22:47     ` Randy Brukardt
  2011-10-27  8:05       ` AdaMagica
@ 2011-10-27  8:56       ` Simon Wright
  2011-10-27 11:05         ` Brian Drummond
  2011-10-27 11:28         ` Georg Bauhaus
  1 sibling, 2 replies; 33+ messages in thread
From: Simon Wright @ 2011-10-27  8:56 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> Even people who should know better do it (and I know I have,
> too). It's a pain to create a reproducing example, but a lot of time
> when I do that, it becomes clear what is wrong (and it often is
> "operator error"!).

Me too.



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

* Re: Length of unbounded_string.
  2011-10-27  8:56       ` Simon Wright
@ 2011-10-27 11:05         ` Brian Drummond
  2011-10-28  3:12           ` ldries46
       [not found]           ` <4eafc489$0$3081$703f8584@textnews.kpn.nl>
  2011-10-27 11:28         ` Georg Bauhaus
  1 sibling, 2 replies; 33+ messages in thread
From: Brian Drummond @ 2011-10-27 11:05 UTC (permalink / raw)


On Thu, 27 Oct 2011 09:56:50 +0100, Simon Wright wrote:

> "Randy Brukardt" <randy@rrsoftware.com> writes:
> 
>> Even people who should know better do it (and I know I have, too). It's
>> a pain to create a reproducing example, but a lot of time when I do
>> that, it becomes clear what is wrong (and it often is "operator
>> error"!).
> 
> Me too.

+1.

Though the other side is: making the reproducible test case can be 
significant work in itself,. By the time you have five of them open 
against a tool (all real bugs : clearly not written in Ada!) you begin to 
wish you could charge the helpdesk for your time... it's easier than 
justifying charging it to the project.

- Brian



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

* Re: Length of unbounded_string.
  2011-10-27  8:56       ` Simon Wright
  2011-10-27 11:05         ` Brian Drummond
@ 2011-10-27 11:28         ` Georg Bauhaus
  2011-10-27 12:17           ` Dmitry A. Kazakov
  1 sibling, 1 reply; 33+ messages in thread
From: Georg Bauhaus @ 2011-10-27 11:28 UTC (permalink / raw)


On 27.10.11 10:56, Simon Wright wrote:
> "Randy Brukardt" <randy@rrsoftware.com> writes:
> 
>> Even people who should know better do it (and I know I have,
>> too). It's a pain to create a reproducing example, but a lot of time
>> when I do that, it becomes clear what is wrong (and it often is
>> "operator error"!).
> 
> Me too.

A natural extension of this phenomenon into the workplace seems to
be writing tests. Whenever packages or types can be tested in
isolation, there will be additional benefits. Like pieces of source to
hand over to the help desk. The additional benefits are
without additional effort, since they flow naturally from the
design and development of tests.
(I'm partly forced to work in this way using Python, since even
pylint's results are not always close to the diagnostic powers
of an Ada compiler; however, there is even more incentive to do
the same when writing Ada. A win-win situation.)

Some additional benefits, I think, in no particular order:

*) test cases increase the likelihood of isolated pieces of
   software that can be forward to help desks

*) writing tests means documenting and verifying assumptions.
   This resembles the "detect early" argument associated with Ada:
   "Ouch, I had thought this type behaved such-and-such, and not
   that way ...!" Knowing what you are assuming seems better than
   the opposite, and the sooner you know it the better.

*) Thinking is needed to write tests, therefore doing so clarifies
   understanding during development. Even later, software is more
   clearly understood by readers, since test cases are manifestations
   of thinking.

*) done properly, I think test cases will improve decoupling of modules,
   because developing one test should neither impede nor be impeded
   by developing others. Perhaps even because testing forces to
   concentrate on separating things for testing.

It has taken a bit of patience and getting used to, but writing
tests early seems well worth it. With or without "formal methods".



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

* Re: Length of unbounded_string.
  2011-10-27 11:28         ` Georg Bauhaus
@ 2011-10-27 12:17           ` Dmitry A. Kazakov
  2011-10-27 13:31             ` Georg Bauhaus
  0 siblings, 1 reply; 33+ messages in thread
From: Dmitry A. Kazakov @ 2011-10-27 12:17 UTC (permalink / raw)


On Thu, 27 Oct 2011 13:28:39 +0200, Georg Bauhaus wrote:

> On 27.10.11 10:56, Simon Wright wrote:
>> "Randy Brukardt" <randy@rrsoftware.com> writes:
>> 
>>> Even people who should know better do it (and I know I have,
>>> too). It's a pain to create a reproducing example, but a lot of time
>>> when I do that, it becomes clear what is wrong (and it often is
>>> "operator error"!).
>> 
>> Me too.
> 
> A natural extension of this phenomenon into the workplace seems to
> be writing tests.

And the reasonable one is static checks.

> *) test cases increase the likelihood of isolated pieces of
>    software that can be forward to help desks

What is "the likelihood of isolated pieces"?

> *) writing tests means documenting and verifying assumptions.

It does not.

A proper statement should sound like: the software must be developed in a
way that would make it testable.

This has little to do with either documentation or understanding of a
*given* implementation, just a separate issue. Furthermore, I would argue
that the documentation developed on the basis of tests, or even of use
cases, would be rather poor.

> It has taken a bit of patience and getting used to, but writing
> tests early seems well worth it. With or without "formal methods".

One should complement another.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Length of unbounded_string.
  2011-10-27 12:17           ` Dmitry A. Kazakov
@ 2011-10-27 13:31             ` Georg Bauhaus
  2011-10-27 14:34               ` Dmitry A. Kazakov
  0 siblings, 1 reply; 33+ messages in thread
From: Georg Bauhaus @ 2011-10-27 13:31 UTC (permalink / raw)


On 27.10.11 14:17, Dmitry A. Kazakov wrote:

>> A natural extension of this phenomenon into the workplace seems to
>> be writing tests.
> 
> And the reasonable one is static checks.

Static checks are insufficient in my real world, since,
as you say, a complement is needed. This is because
my world escapes being static, among other things totally
out of control.

>> *) test cases increase the likelihood of isolated pieces of
>>    software that can be forward to help desks
> 
> What is "the likelihood of isolated pieces"?

OK, bad phrasing. Parts of a program that can be run in
isolation from the rest of the program, to see some effect,
 such that no other part of the program will be called
or referenced.

>> *) writing tests means documenting and verifying assumptions.
> 
> It does not.
> 
> A proper statement should sound like: the software must be developed in a
> way that would make it testable.

OK, but testable is another void. (What is the meaning of
"testable" without invoking more definitions, recursively,
to the point of reaching epistemological mud, remembering that
this is about the *process* of *writing* tests, not about boring
formal properties of tests?)

Example: The process of writing tests results in statements that
express the expected result of an operation.
They are thus documenting some of the (intended) properties of
a type.

     thing : T1;
     assert_equals (op (thing, data), T2'(...));

Since the type system cannot express all of these assumptions,
there is more information in these statements than in the type
system alone.  Since "formal methods" imply restrictions, some
test cases are not within reach of "formal methods".

I had not intended to say that writing tests is a substitute
for writing documentation.

> This has little to do with either documentation or understanding of a
> *given* implementation, just a separate issue.

Interesting, but I had not meant to say something about existing
software that wasn't developed with testing all along driving
the writing process.



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

* Re: Length of unbounded_string.
  2011-10-27 13:31             ` Georg Bauhaus
@ 2011-10-27 14:34               ` Dmitry A. Kazakov
  0 siblings, 0 replies; 33+ messages in thread
From: Dmitry A. Kazakov @ 2011-10-27 14:34 UTC (permalink / raw)


On Thu, 27 Oct 2011 15:31:03 +0200, Georg Bauhaus wrote:

> OK, bad phrasing. Parts of a program that can be run in
> isolation from the rest of the program, to see some effect,

That is modularity. The purpose of having it modular is not directly
testing.

Also the way components/modules are factored out may help testing or hinder
testing. E.g. you could develop modules in order to run the program in
parallel, which would make testing significantly more difficult.

>>> *) writing tests means documenting and verifying assumptions.
>> 
>> It does not.
>> 
>> A proper statement should sound like: the software must be developed in a
>> way that would make it testable.
> 
> OK, but testable is another void. (What is the meaning of
> "testable" without invoking more definitions, recursively,

It means that the design must allow testing for certain (specified upfront)
properties of the software. Modularity is just a part of this equation.
Think about integration tests.

>> This has little to do with either documentation or understanding of a
>> *given* implementation, just a separate issue.
> 
> Interesting, but I had not meant to say something about existing
> software that wasn't developed with testing all along driving
> the writing process.

Even so, the way software is used and understood differs from those while
testing. Compare testing a computer game and playing it, testing a music
record for defects and listening it etc.

If testing would improve understanding then only because more time is
invested in dealing with the program, not because testing helps it better
than, for example, core review.

BTW, 1. programmer, 2. tester, 3. technical writer classically are
different roles.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Length of unbounded_string.
  2011-10-25 17:57 ` Jeffrey Carter
@ 2011-10-28  2:54   ` ldries46
  2011-10-28  4:55     ` Jeffrey Carter
  0 siblings, 1 reply; 33+ messages in thread
From: ldries46 @ 2011-10-28  2:54 UTC (permalink / raw)


The output is the same in the command window of Windows 7

"Jeffrey Carter"  schreef in bericht 
news:j871dj$9td$1@tornado.tornevall.net...

On 10/25/2011 02:37 AM, ldries46 wrote:
> I just found the following extra relevant points:
> Instead of <Str := Str & " " & Next_Line;> I put in the line <Str := Str & 
> "x "
> & Next_Line;>
> This showed that with Str := "str," en Next_Line := "Next" the output 
> became
> "str x Next"
> When I changed Str to Str := "strx" the output changed to "strxx Next"
> This looks like the comma has a special meaning within an Unbounded String

No Character has a special meaning in a String or an Unbounded_String. This
appears to be a problem with the way you're viewing the contents.

with Ada.Strings.Unbounded;
with Ada.Text_IO;

procedure US_Test is
    use Ada.Strings.Unbounded;

    Str_Start : constant Unbounded_String := To_Unbounded_String ("str,");
    Next_Line : constant Unbounded_String := To_Unbounded_String ("Next");

    Str : Unbounded_String := Str_Start;
begin -- US_Test
    Str := Str & " " & Next_Line;
    Ada.Text_IO.Put_Line (Item => '>' & To_String (Str) & '<');
    Str := Str_Start;
    Str := Str & "x " & Next_Line;
    Ada.Text_IO.Put_Line (Item => '>' & To_String (Str) & '<');
    Str := To_Unbounded_String ("strx");
    Str := Str & "x " & Next_Line;
    Ada.Text_IO.Put_Line (Item => '>' & To_String (Str) & '<');
end US_Test;

jrcarter@jrcarter-gateway-1:~/Code$ gnatmake -gnaton -O2 -j2 us_test.adb
gcc-4.4 -c -gnaton -O2 us_test.adb
gnatbind -x us_test.ali
gnatlink us_test.ali
jrcarter@jrcarter-gateway-1:~/Code$ ./us_test
>str, Next<
>str,x Next<
>strxx Next<

This is GNAT 4.4.5 on Ubuntu 11.04. If this program gives different results 
on
your system, let us know.

-- 
Jeff Carter
"Blessed are they who convert their neighbors'
oxen, for they shall inhibit their girth."
Monty Python's Life of Brian
83 




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

* Re: Length of unbounded_string.
  2011-10-27 11:05         ` Brian Drummond
@ 2011-10-28  3:12           ` ldries46
       [not found]           ` <4eafc489$0$3081$703f8584@textnews.kpn.nl>
  1 sibling, 0 replies; 33+ messages in thread
From: ldries46 @ 2011-10-28  3:12 UTC (permalink / raw)


Normally I just write a short test case to try to reproduce the error, but 
in some cases the error can only be reproduced in a rather complicated 
situation. In this case the problem is found in such a complicated 
situation. In the Debugging session there seems to be a discrepancy between 
the output of the debug command and the print command. The debug command 
seems to give the same output as the program itself but the print command 
presents the expected output. This kind of problem is in general no 
reproducible in a simple program.
The problem with a small reproducible test case is just that the small 
version I wrote did not created the problem. So my question was more do I 
forget something or do I do something wrong or is there anything wrong 
somewhere in the "windows version" compiler or the "windows version" of the 
some of the packages

"Brian Drummond"  schreef in bericht news:j8bdtm$1hk$2@dont-email.me...

On Thu, 27 Oct 2011 09:56:50 +0100, Simon Wright wrote:

> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> Even people who should know better do it (and I know I have, too). It's
>> a pain to create a reproducing example, but a lot of time when I do
>> that, it becomes clear what is wrong (and it often is "operator
>> error"!).
>
> Me too.

+1.

Though the other side is: making the reproducible test case can be
significant work in itself,. By the time you have five of them open
against a tool (all real bugs : clearly not written in Ada!) you begin to
wish you could charge the helpdesk for your time... it's easier than
justifying charging it to the project.

- Brian 




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

* Re: Length of unbounded_string.
  2011-10-28  2:54   ` ldries46
@ 2011-10-28  4:55     ` Jeffrey Carter
  0 siblings, 0 replies; 33+ messages in thread
From: Jeffrey Carter @ 2011-10-28  4:55 UTC (permalink / raw)


On 10/27/2011 07:54 PM, ldries46 wrote:
> The output is the same in the command window of Windows 7

Then we can be reasonably sure that the problem is not in Unbounded_String.

-- 
Jeff Carter
"From this day on, the official language of San Marcos will be Swedish."
Bananas
28



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

* Re: Length of unbounded_string.
       [not found]           ` <4eafc489$0$3081$703f8584@textnews.kpn.nl>
@ 2011-11-01 18:22             ` Jeffrey Carter
  0 siblings, 0 replies; 33+ messages in thread
From: Jeffrey Carter @ 2011-11-01 18:22 UTC (permalink / raw)


On 11/01/2011 03:05 AM, ldries46 wrote:
> I finally have rewritten my routine continuation to try to make a work around .
> I believe that this has been succesfull.
> But The discrepancy between the display and the print facility with debugging
> stays as can be seen in the attachment. Also a strance behavior with the display
> of the character comma can be seen with lastch, that with an 'e' would have the
> output 109 'e' but for the comma gives 44 '
> I think I found a bug in the compiler so I will report this to AdaCore.

I don't see any evidence that this is a compiler error. It appears to be a 
debugger error.

17            nextlen := Length(Next_Line)	-- Next_Line is Global
18            ok1 := nextlen /= 0;

You seem to be missing a semicolon on line 17. Ok1 is never referenced.

You have two big if statements that are essentially

    if Condition then
       Do_This;
    else
       exit; -- Ok := True;
    end if;

which I would write

    exit when not Condition;

    Do_This;

The latter is clearer, especially given that small else parts tend to be 
overlooked after a large if part.

30                     while (nextch = ' ' or nextch = ASCII.HT) loop
31                        Replace_Slice(Next_Line, 1, 1, "");
32                        nextch := Element(Next_Line, 1);
33                     end loop;

Why do you use Replace_Slice with a null replacement rather than Delete?

If this loop reduces Next_Line to the null string, you'll get Constraint_Error 
from Element.

35                  str := To_Unbounded_String(Slice(str, 1, lenstr - 1));

Why do you use To_Unbounded_String (Slice (...) ) rather than Unbounded_Slice?

Cleaning this up, and removing everything not related to the processing, I came 
up with

procedure Continuation(Str : in out Unbounded_String; Nr : in out Integer) is
    Lenstr  : Integer;
    Nextlen : Integer;
    Lastch  : Character;
    Nextch  : Character;
begin
    All_Continuations : loop
       Lenstr := Length(Str);

       exit All_Continuations when Lenstr = 0;

       Lastch := Element(Str, Lenstr);
       Nextlen := Length(Next_Line);	-- Next_Line is Global

       exit All_Continuations when Lastch = ';' or Lastch = '{' or Lastch = '}' 
or Nextlen = 0;

       Nr := Nr + 1;

       Skip_Blanks : loop
       	Nextch := Element (Next_Line, 1);

         exit Skip_Blanks when Nextch /= ' ' and Nextch /= ASCII.HT;

         Delete (Source => Next_Line, From => 1, Through => 1);

         exit Skip_Blanks when Length (Next_Line) = 0;
       end loop Skip_Blanks;

       Str := Str & ' ' & Next_Line;
       -- I don't see any reason to slice the last character off and then
       -- concatenate it back on again.

       if Nr < Buffer1.Length - 1 then
          Next_Line := Buffer1.Get_Buffer( Nr + 1 );	-- Buffer1 is a global
       else
          Next_Line := Null_Unbounded_String;
       end if;
    end loop All_Continuations;
end Continuation;

-- 
Jeff Carter
"Sir Lancelot saves Sir Gallahad from almost certain temptation."
Monty Python & the Holy Grail
69



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

end of thread, other threads:[~2011-11-01 18:22 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-25  9:37 Length of unbounded_string ldries46
2011-10-25 17:57 ` Jeffrey Carter
2011-10-28  2:54   ` ldries46
2011-10-28  4:55     ` Jeffrey Carter
2011-10-25 20:23 ` Vadim Godunko
2011-10-25 21:28   ` Simon Wright
2011-10-26  4:41     ` Simon Wright
2011-10-26 22:47     ` Randy Brukardt
2011-10-27  8:05       ` AdaMagica
2011-10-27  8:56       ` Simon Wright
2011-10-27 11:05         ` Brian Drummond
2011-10-28  3:12           ` ldries46
     [not found]           ` <4eafc489$0$3081$703f8584@textnews.kpn.nl>
2011-11-01 18:22             ` Jeffrey Carter
2011-10-27 11:28         ` Georg Bauhaus
2011-10-27 12:17           ` Dmitry A. Kazakov
2011-10-27 13:31             ` Georg Bauhaus
2011-10-27 14:34               ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
2011-10-16  8:48 ldries46
2011-10-16  9:59 ` Niklas Holsti
2011-10-16 12:06   ` ldries46
2011-10-16 12:52   ` ldries46
2011-10-16 13:00     ` Niklas Holsti
2011-10-17  7:39       ` ldries46
2011-10-17 19:49         ` Niklas Holsti
2011-10-18 11:47           ` ldries46
2011-10-18 17:54             ` Niklas Holsti
2011-10-19  2:38               ` ldries46
2011-10-19  6:07                 ` Niklas Holsti
2011-10-24 15:10                   ` ldries46
2011-10-19  6:37                 ` Simon Wright
2011-10-19 14:48                 ` Alex Mentis
2011-10-24 17:04                   ` ldries46
2011-10-16 10:14 ` Vinzent Hoefler

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