comp.lang.ada
 help / color / mirror / Atom feed
* Is there an easier way for this?
@ 2015-06-21 18:38 Laurent
  2015-06-21 19:15 ` Niklas Holsti
                   ` (3 more replies)
  0 siblings, 4 replies; 71+ messages in thread
From: Laurent @ 2015-06-21 18:38 UTC (permalink / raw)


Hi

I need a function which generates some specific file names:

VITEK2-BCI_yymmdd_hhmmss_x.txt

where yymmdd is the current date, hhmmss the current time and x the number of txt files. No idea if x 
actually important.

I have tinkered this together but I find it quite horrible. Is there a more elegant way to do it?

   function Make_File_Name (How_Many : in Positive) return V_String.Bounded_String is
      
      use V_String;
      
      File_Name : V_String.Bounded_String:= (+"VITEK2-BCI_");
      Temp      : V_String.Bounded_String;
      
      Right_Now : Ada.Calendar.Time := Ada.Calendar.Clock;
      Y         : Positive := Ada.Calendar.Year (Right_Now) rem 100;
      M         : Positive := Ada.Calendar.Month (Right_Now);
      D         : Positive := Ada.Calendar.Day (Right_Now);
      
      Secs_Past_Midnight : Natural;
      Mins_Past_Midnight : Natural;
      Secs          : Natural;
      Mins          : Natural;                                    
      Hrs           : Natural;

   begin
      
      Secs_Past_Midnight := Natural (Ada.Calendar.Seconds (Right_Now));
      Mins_Past_Midnight := Secs_Past_Midnight / 60;
      Secs          := Secs_Past_Midnight rem 60;
      Mins          := Mins_Past_Midnight rem 60;
      Hrs           := Mins_Past_Midnight / 60;
      
      if Y < 10 then
         Temp := (+"0" & Trim(Y'Img));
         File_Name := File_Name & Temp;
      else
         Temp := Trim (Y'Img);
         File_Name := File_Name & Temp;
      end if;
      
      if M < 10 then
         Temp := (+"0" & Trim(M'Img));
         File_Name := File_Name & Temp;
      else
         Temp := Trim (M'Img);
         File_Name := File_Name & Temp;
      end if;
      
      if D < 10 then
         Temp := (+"0" & Trim(D'Img));
         File_Name := File_Name & Temp;
      else
         Temp := Trim (D'Img);
         File_Name := File_Name & Temp;
      end if;
      
      File_Name := File_Name & "_";
      
            if Hrs < 10 then
         Temp := (+"0" & Trim(Hrs'Img));
         File_Name := File_Name & Temp;
      else
         Temp := Trim (Hrs'Img);
         File_Name := File_Name & Temp;
      end if;
      
      if Mins < 10 then
         Temp := (+"0" & Trim(Mins'Img));
         File_Name := File_Name & Temp;
      else
         Temp := Trim (Mins'Img);
         File_Name := File_Name & Temp;
      end if;
      
      if Secs < 10 then
         Temp := (+"0" & Trim(Secs'Img));
         File_Name := File_Name & Temp;
      else
         Temp := Trim (Secs'Img);
         File_Name := File_Name & Temp;
      end if;
     
      File_Name := File_Name & "_";
      File_Name := File_Name & Trim (How_Many'Img) & ".txt";      
      
      return File_Name;
      
   end Make_File_Name;

Thanks

Laurent


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

* Re: Is there an easier way for this?
  2015-06-21 18:38 Is there an easier way for this? Laurent
@ 2015-06-21 19:15 ` Niklas Holsti
  2015-06-21 19:41   ` Laurent
  2015-06-21 19:25 ` Jeffrey R. Carter
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 71+ messages in thread
From: Niklas Holsti @ 2015-06-21 19:15 UTC (permalink / raw)


On 15-06-21 21:38 , Laurent wrote:
> Hi
>
> I need a function which generates some specific file names:
>
> VITEK2-BCI_yymmdd_hhmmss_x.txt
>
> where yymmdd is the current date, hhmmss the current time and x the number of txt files. No idea if x
> actually important.
>
> I have tinkered this together but I find it quite horrible. Is there a more elegant way to do it?
>
>     function Make_File_Name (How_Many : in Positive) return V_String.Bounded_String is
>
>        use V_String;
>
>        File_Name : V_String.Bounded_String:= (+"VITEK2-BCI_");
>        Temp      : V_String.Bounded_String;
>
>        Right_Now : Ada.Calendar.Time := Ada.Calendar.Clock;
>        Y         : Positive := Ada.Calendar.Year (Right_Now) rem 100;
>        M         : Positive := Ada.Calendar.Month (Right_Now);
>        D         : Positive := Ada.Calendar.Day (Right_Now);

(rest of code snipped)

Have you looked at Ada.Calendar.Formatting?

http://www.ada-auth.org/standards/12rm/html/RM-9-6-1.html#I4152

There is an Image function there which shows an Ada.Calendar.Time as 
yyyy-mm-dd hh:mm:ss; you could construct your file name by taking 
suitable substrings.

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

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

* Re: Is there an easier way for this?
  2015-06-21 18:38 Is there an easier way for this? Laurent
  2015-06-21 19:15 ` Niklas Holsti
@ 2015-06-21 19:25 ` Jeffrey R. Carter
  2015-06-21 19:42   ` Laurent
                     ` (2 more replies)
  2015-06-21 19:38 ` Is there an easier way for this? Pascal Obry
  2015-06-24  7:14 ` gautier_niouzes
  3 siblings, 3 replies; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-21 19:25 UTC (permalink / raw)


On 06/21/2015 11:38 AM, Laurent wrote:
> 
> I need a function which generates some specific file names:
> 
> VITEK2-BCI_yymmdd_hhmmss_x.txt
> 
> where yymmdd is the current date, hhmmss the current time and x the number of txt files. No idea if x 
> actually important.

You could do

Year    : Ada.Calendar.Year_Number;
Month   : Ada.Calendar.Month_Number;
Day     : Ada.Calendar.Day_Number;
Hour    : PragmARC.Date_Handler.Hour_Number;
Minute  : PragmARC.Date_Handler.Minute_Number;
Seconds : PragmARC.Date_Handler.Minute_Duration;

PragmARC.Date_Handler.Split (Year    => Year,
                             Month   => Month,
                             Day     => Day,
                             Hour    => Hour,
                             Minute  => Minute,
                             Seconds => Seconds);

"VITEK2-BCI_" &
PragmARC.Date_Handler.Year_Image_Short (Year) &
PragmARC.Date_Handler.Month_Image_Numeric (Month) &
PragmARC.Date_Handler.Day_Image (Day) &
'_' &
PragmARC.Date_Handler.Hour_Image_24 (Hour) &
PragmARC.Date_Handler.Minute_Image (Minute) &
PragmARC.Date_Handler.Seconds_Image (Seconds) &
'_' &
PragmARC.Images.Image (How_Many) &
".txt";

The PragmAda Reusable Components are at

https://pragmada.x10hosting.com/pragmarc.htm

-- 
Jeff Carter
"Brave Sir Robin ran away."
Monty Python and the Holy Grail
59


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

* Re: Is there an easier way for this?
  2015-06-21 18:38 Is there an easier way for this? Laurent
  2015-06-21 19:15 ` Niklas Holsti
  2015-06-21 19:25 ` Jeffrey R. Carter
@ 2015-06-21 19:38 ` Pascal Obry
  2015-06-21 19:54   ` Laurent
  2015-06-24  7:14 ` gautier_niouzes
  3 siblings, 1 reply; 71+ messages in thread
From: Pascal Obry @ 2015-06-21 19:38 UTC (permalink / raw)


Laurent,

> I need a function which generates some specific file names:
> 
> VITEK2-BCI_yymmdd_hhmmss_x.txt

Should be easier with GNAT.Formatted_String.

-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://v2p.fr.eu.org
  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B

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

* Re: Is there an easier way for this?
  2015-06-21 19:15 ` Niklas Holsti
@ 2015-06-21 19:41   ` Laurent
  0 siblings, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-21 19:41 UTC (permalink / raw)


On Sunday, 21 June 2015 21:15:30 UTC+2, Niklas Holsti  wrote:

> Have you looked at Ada.Calendar.Formatting?
> 
> http://www.ada-auth.org/standards/12rm/html/RM-9-6-1.html#I4152
> 
> There is an Image function there which shows an Ada.Calendar.Time as 
> yyyy-mm-dd hh:mm:ss; you could construct your file name by taking 
> suitable substrings.

Yes I have seen this one but I don't know why I didn't follow it further. Tunnel vision I suppose.

Thanks

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

* Re: Is there an easier way for this?
  2015-06-21 19:25 ` Jeffrey R. Carter
@ 2015-06-21 19:42   ` Laurent
  2015-06-22 12:23   ` Laurent
  2015-06-22 16:41   ` Laurent
  2 siblings, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-21 19:42 UTC (permalink / raw)


On Sunday, 21 June 2015 21:25:39 UTC+2, Jeffrey R. Carter  wrote:
> You could do
> 
> Year    : Ada.Calendar.Year_Number;
> Month   : Ada.Calendar.Month_Number;
> Day     : Ada.Calendar.Day_Number;
> Hour    : PragmARC.Date_Handler.Hour_Number;
> Minute  : PragmARC.Date_Handler.Minute_Number;
> Seconds : PragmARC.Date_Handler.Minute_Duration;
> 
> PragmARC.Date_Handler.Split (Year    => Year,
>                              Month   => Month,
>                              Day     => Day,
>                              Hour    => Hour,
>                              Minute  => Minute,
>                              Seconds => Seconds);
> 
> "VITEK2-BCI_" &
> PragmARC.Date_Handler.Year_Image_Short (Year) &
> PragmARC.Date_Handler.Month_Image_Numeric (Month) &
> PragmARC.Date_Handler.Day_Image (Day) &
> '_' &
> PragmARC.Date_Handler.Hour_Image_24 (Hour) &
> PragmARC.Date_Handler.Minute_Image (Minute) &
> PragmARC.Date_Handler.Seconds_Image (Seconds) &
> '_' &
> PragmARC.Images.Image (How_Many) &
> ".txt";

Thanks that would be a reason to finally take a look at this package.


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

* Re: Is there an easier way for this?
  2015-06-21 19:38 ` Is there an easier way for this? Pascal Obry
@ 2015-06-21 19:54   ` Laurent
  2015-06-21 20:39     ` Pascal Obry
  0 siblings, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-21 19:54 UTC (permalink / raw)


On Sunday, 21 June 2015 21:38:39 UTC+2, Pascal Obry  wrote:

> Should be easier with GNAT.Formatted_String.


Google found that one https://en.wikibooks.org/wiki/Ada_Programming/Libraries/GNAT.Calendar.Time_IO
while I tried to find an example on how to use the formatted Strings.

Looks like it has once been part of gnat and then later removed or fusioned with something else?

Thanks


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

* Re: Is there an easier way for this?
  2015-06-21 19:54   ` Laurent
@ 2015-06-21 20:39     ` Pascal Obry
  0 siblings, 0 replies; 71+ messages in thread
From: Pascal Obry @ 2015-06-21 20:39 UTC (permalink / raw)


Le dimanche 21 juin 2015 à 12:54 -0700, Laurent a écrit :
> Google found that one https://en.wikibooks.org/wiki/Ada_Programming/L> ibraries/GNAT.Calendar.Time_IO
> while I tried to find an example on how to use the formatted Strings.
> 
> Looks like it has once been part of gnat and then later removed or 
> fusioned with something else?

No, it should be part of GNAT GPL 2015 as implemented on 2014 April
2nd.

-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://v2p.fr.eu.org
  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B

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

* Re: Is there an easier way for this?
  2015-06-21 19:25 ` Jeffrey R. Carter
  2015-06-21 19:42   ` Laurent
@ 2015-06-22 12:23   ` Laurent
  2015-06-22 15:01     ` G.B.
  2015-06-22 16:47     ` Jeffrey R. Carter
  2015-06-22 16:41   ` Laurent
  2 siblings, 2 replies; 71+ messages in thread
From: Laurent @ 2015-06-22 12:23 UTC (permalink / raw)


On Sunday, 21 June 2015 21:25:39 UTC+2, Jeffrey R. Carter  wrote:
> The PragmAda Reusable Components are at
> 
> https://pragmada.x10hosting.com/pragmarc.htm

Hi

I tried to compile your package using the compile_all.adb

GPS throws a few errors.

Builder results
    /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-list_bounded_unprotected.adb
        279:36 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
    /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-list_unbounded_unprotected.adb
        205:21 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
    /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-min_max.adb
        13:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
        15:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
        23:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
        25:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
    /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-monitor_handler.adb
        20:17 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))

Laurent


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

* Re: Is there an easier way for this?
  2015-06-22 12:23   ` Laurent
@ 2015-06-22 15:01     ` G.B.
  2015-06-22 15:40       ` Laurent
  2015-06-22 16:47     ` Jeffrey R. Carter
  1 sibling, 1 reply; 71+ messages in thread
From: G.B. @ 2015-06-22 15:01 UTC (permalink / raw)


On 22.06.15 14:23, Laurent wrote:
> On Sunday, 21 June 2015 21:25:39 UTC+2, Jeffrey R. Carter  wrote:
>> The PragmAda Reusable Components are at
>>
>> https://pragmada.x10hosting.com/pragmarc.htm

If I may,
   "The PragmARCs are pure Ada 95"

Back then, Ada had return-by-reference.

> GPS throws a few errors.

Try GNAT's switch -gnat95



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

* Re: Is there an easier way for this?
  2015-06-22 15:01     ` G.B.
@ 2015-06-22 15:40       ` Laurent
  0 siblings, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-22 15:40 UTC (permalink / raw)


On Monday, 22 June 2015 17:01:32 UTC+2, G.B.  wrote:
> On 22.06.15 14:23, Laurent wrote:
> > On Sunday, 21 June 2015 21:25:39 UTC+2, Jeffrey R. Carter  wrote:
> >> The PragmAda Reusable Components are at
> >>
> >> https://pragmada.x10hosting.com/pragmarc.htm
> 
> If I may,
>    "The PragmARCs are pure Ada 95"
> 
> Back then, Ada had return-by-reference.
> 
> > GPS throws a few errors.
> 
> Try GNAT's switch -gnat95

Ok that works. 

Thanks

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

* Re: Is there an easier way for this?
  2015-06-21 19:25 ` Jeffrey R. Carter
  2015-06-21 19:42   ` Laurent
  2015-06-22 12:23   ` Laurent
@ 2015-06-22 16:41   ` Laurent
  2015-06-22 16:47     ` Jeffrey R. Carter
  2 siblings, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-22 16:41 UTC (permalink / raw)


On Sunday, 21 June 2015 21:25:39 UTC+2, Jeffrey R. Carter  wrote:

> PragmARC.Images.Image (How_Many) &

Ok now that took me some time to figure out. Image doesn't exist. So I had to instantiate the generic signed_image function to get it to work. Is that correct or did I miss something?

Thanks

Laurent


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

* Re: Is there an easier way for this?
  2015-06-22 16:41   ` Laurent
@ 2015-06-22 16:47     ` Jeffrey R. Carter
  2015-06-22 17:18       ` Laurent
  0 siblings, 1 reply; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-22 16:47 UTC (permalink / raw)


On 06/22/2015 09:41 AM, Laurent wrote:
> On Sunday, 21 June 2015 21:25:39 UTC+2, Jeffrey R. Carter  wrote:
> 
>> PragmARC.Images.Image (How_Many) &
> 
> Ok now that took me some time to figure out. Image doesn't exist. So I had to instantiate the generic signed_image function to get it to work. Is that correct or did I miss something?

PragmARC.Images.Image is a child instantiation of PragmARC.Images.Signed_Image
for Integer.

-- 
Jeff Carter
"Sons of a silly person."
Monty Python & the Holy Grail
02


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

* Re: Is there an easier way for this?
  2015-06-22 12:23   ` Laurent
  2015-06-22 15:01     ` G.B.
@ 2015-06-22 16:47     ` Jeffrey R. Carter
  1 sibling, 0 replies; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-22 16:47 UTC (permalink / raw)


On 06/22/2015 05:23 AM, Laurent wrote:
> 
> Builder results
>     /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-list_bounded_unprotected.adb
>         279:36 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
>     /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-list_unbounded_unprotected.adb
>         205:21 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
>     /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-min_max.adb
>         13:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
>         15:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
>         23:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
>         25:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
>     /Volumes/Kingston/GPS/Library/pragmarc/pragmarc-monitor_handler.adb
>         20:17 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))

You have the Ada-95 version of the components. You can either compile with an
Ada-95 compiler, or download the beta version for ISO/IEC 8652:2007.

-- 
Jeff Carter
"Sons of a silly person."
Monty Python & the Holy Grail
02

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

* Re: Is there an easier way for this?
  2015-06-22 16:47     ` Jeffrey R. Carter
@ 2015-06-22 17:18       ` Laurent
  2015-06-22 18:04         ` What do you think about this? Laurent
  0 siblings, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-22 17:18 UTC (permalink / raw)


On Monday, 22 June 2015 18:47:30 UTC+2, Jeffrey R. Carter  wrote:
 
> PragmARC.Images.Image is a child instantiation of PragmARC.Images.Signed_Image
> for Integer.

Ok I have to with PragmARC.Images.Image and not only PragmARC.Images

Thanks

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

* What do you think about this?
  2015-06-22 17:18       ` Laurent
@ 2015-06-22 18:04         ` Laurent
  2015-06-23 14:21           ` Stephen Leake
  0 siblings, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-22 18:04 UTC (permalink / raw)


I have finally finished my program. Now I would like to know what the professionals think about my creation. It is far from perfect. If possible treat it like a students work. 

What could I have done better. What is ok and what I shouldn't do at all. If something is crap then please tell me.

I know that I am asking a lot but only like that I can find out if I am making some progress.

I have uploaded the files to git,

https://github.com/Chutulu/Generateur_Trame_Vitek2.git

Awaiting your comments.

Laurent

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

* Re: What do you think about this?
  2015-06-22 18:04         ` What do you think about this? Laurent
@ 2015-06-23 14:21           ` Stephen Leake
  2015-06-23 19:51             ` Laurent
  0 siblings, 1 reply; 71+ messages in thread
From: Stephen Leake @ 2015-06-23 14:21 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> I have uploaded the files to git,
>
> https://github.com/Chutulu/Generateur_Trame_Vitek2.git

I did not download and compile it, but I did browse around it a bit.

The code looks clean and well-organized, but it lacks comments.

What is a "biogramme"? What is a "dossier"? etc. What is the whole
thing supposed to do?

There are cases where a function returns a V_String but could return a
plain String; in general, unless the result _must_ be a V_String for
some reason, it is better to return a String; then the caller can just
use it without conversion, or declare a local variable to hold it.

-- 
-- Stephe


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

* Re: What do you think about this?
  2015-06-23 14:21           ` Stephen Leake
@ 2015-06-23 19:51             ` Laurent
  2015-06-23 20:20               ` Anh Vo
  2015-06-24 10:17               ` Stephen Leake
  0 siblings, 2 replies; 71+ messages in thread
From: Laurent @ 2015-06-23 19:51 UTC (permalink / raw)


On Tuesday, 23 June 2015 16:21:17 UTC+2, Stephen Leake  wrote:
> I did not download and compile it, but I did browse around it a bit.

That's why I like git.

> The code looks clean and well-organized,

Ok that is already a good thing to hear.

>What is the whole thing supposed to do?

It is supposed to generate something like this:

mtrsl|pi12345678910|p2164|pp907088|p5907088|si|s040330|ssPLAIES|s5PLAIES|ci501502240387|c040330|ctAERO|ta|rtAST-N264|rr10335191|t12|o1esccol|ra|a1tem|a3<=4|a4S|ra|a1am|a34|a4S|ra|a1amc|a34|a4S|ra|a1tzp|a3<=4|a4S|ra|a1rox|a34|a4S|ra|a1tax|a3<=1|a4S|ra|a1taz|a3<=1|a4S|ra|a1fep|a3<=1|a4S|ra|a1etp|a3<=0,5|a4S|ra|a1mem|a3<=0,25|a4S|ra|a1an|a3<=2|a4S|ra|a1gm|a3<=1|a4S|ra|a1cip|a3<=0,25|a4S|ra|a1lev|a3<=0,12|a4S|ra|a1tgc|a3<=0,5|a4S|ra|a1fos|a3<=16|a4S|ra|a1ftn|a3<=16|a4S|ra|a1sxt|a3<=20|a4S|zz|

And then write it in a text file. 

The hospital I work for has acquired a new software for epidemical surveillance. I work in the lab in the microbiology department and I have been asked to verify the transmission of the results from the analyzer to the software used by the nurses/docters. 

I have 3 possibilities to do that:

1) launch tests but that takes 24hrs and I have no influence on the result
2) use existing tests and rename them. Which means I have to tinker around with results of actual patients. Is bad because of the iso certification which requires everything to be traceable. No influence on the result
3) write a program which generates textfiles with random results which I can copy into the transfer folder on the analyzer. 

> What is a "antibiogramme"?

The analyzer is testing the susceptibility of a bacteria against a number of antibiotics. The whole result is called an antibiogramme. 

The CMI (MIC in english) is the "minimum inhibitory concentration" that is the lowest concentration of the antibiotic required to kill 99.9% of the bacteria. 

There are breakpoints for every antibiotic which define if it is S = sensible, I = intermediate (could work) or R = resistant. That is called the susceptibility.

> What is a "dossier"?

medical file in this case. I am used to the french names of the whole stuff so I used them everywhere.

>but it lacks comments

Yup something I have to improve. In this case the program is only used by me and quite probable only once. As well as a todo list so that I remember where I left in the case I don't work on a project for longer time.

> There are cases where a function returns a V_String but could return a
> plain String; in general, unless the result _must_ be a V_String for
> some reason, it is better to return a String; then the caller can just
> use it without conversion, or declare a local variable to hold it.

I have quite often problems with different string types and their behavior. So I followed  Bruce B's
recommendation (some earlier post: "Annoying behavior") to make a package:

with Ada.Strings.Bounded;
with Ada.Strings.Fixed;

package Common_Defs_BCI is

   V_String_Length  : constant :=  64;

   package V_String is new
     Ada.Strings.Bounded.Generic_Bounded_Length (V_String_Length);

   function "+" (Right : V_String.Bounded_String) return String
                 renames
     V_String.To_String;

   function "+" (Right : String) return V_String.Bounded_String
   is (V_String.To_Bounded_String (Right));

   function Trim (Right : String) return V_String.Bounded_String is
     (V_String.To_Bounded_String (Ada.Strings.Fixed.Trim (Right, Ada.Strings.Both)));

end Common_Defs_BCI;

So no more confusion with different string types. 

>... it is better to return a String; then the caller can just use it without conversion, or declare a >local variable to hold it.

Well without the "+" conversion function I would agree because the To_Bound... thing is annoying.
For the last part I don't understand what you mean. In the main file I have the function Make_File_Name where File_Name is local variable. If it is of type String or the custom V_String, where is the difference? Ok I have to convert it later in procedure Generate. Requires an additional "+". I find it is a quite good tradeoff for the flexibility it offers me. 

If you have an example where you think that it is not recommended I'd like to see. I have of course no idea how expensive that is in terms of computation power.

   function Make_File_Name (How_Many : in Positive) return V_String.Bounded_String is

      File_Name : V_String.Bounded_String;

      Right_Now : Ada.Calendar.Time := Ada.Calendar.Clock;...

   begin
     ...
      File_Name := +("VITEK2-BCI_" &...;
      return File_Name;
   end Make_File_Name;

 procedure Generate (How_Many : in Positive) is

      File : Ada.Text_IO.File_Type;
   begin -- Generate
      for Counter in 1 .. How_Many loop

         declare
--  removed the declaration of the different objects
         begin -- declare
            Ada.Text_IO.Create (File => File,
                                Mode => Ada.Text_IO.Out_File,
                                Name => +Make_File_Name (Counter)); <---

            BCI_Messages.IO.To_BCI (Item => Test_Message, File => File);
            Ada.Text_IO.Close (File);
         end; -- declare
      end loop;
   end Generate;

For the CMI I would have preferred to use enumerations but that doesn't seem to be possible:

CMI_Type is ("<=1","0,004","3"); or CMI_Type is ("1","2","3"); 

but that works CMI_Type is ('1','2','3'); ?

For the SIR I have used an enumeration at the beginning but I had some problems getting the result written to the text file. So the V_String solved most of the problems.

I have to wait for the person which takes care of the informatics in the lab before I inject the text files into the analyzer. Would be stupid to blow up the online connections with an ill formatted result and no one there to restore them.

Thanks Stephen for your time and comments.

Laurent


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

* Re: What do you think about this?
  2015-06-23 19:51             ` Laurent
@ 2015-06-23 20:20               ` Anh Vo
  2015-06-23 21:03                 ` Laurent
  2015-06-24 10:17               ` Stephen Leake
  1 sibling, 1 reply; 71+ messages in thread
From: Anh Vo @ 2015-06-23 20:20 UTC (permalink / raw)


On Tuesday, June 23, 2015 at 12:51:08 PM UTC-7, Laurent wrote:
> On Tuesday, 23 June 2015 16:21:17 UTC+2, Stephen Leake  wrote:
> > I did not download and compile it, but I did browse around it a bit.
> 
> That's why I like git.
> 
> with Ada.Strings.Bounded;
> with Ada.Strings.Fixed;
> 
> package Common_Defs_BCI is
> 
>    V_String_Length  : constant :=  64;
> 
>    package V_String is new
>      Ada.Strings.Bounded.Generic_Bounded_Length (V_String_Length);
> 
>    function "+" (Right : V_String.Bounded_String) return String
>                  renames
>      V_String.To_String;
> 
>    function "+" (Right : String) return V_String.Bounded_String
>    is (V_String.To_Bounded_String (Right));
> 
>    function Trim (Right : String) return V_String.Bounded_String is
>      (V_String.To_Bounded_String (Ada.Strings.Fixed.Trim (Right, Ada.Strings.Both)));
> 
> end Common_Defs_BCI;

I would suggest to improve the last two functions with the following preconditions. That means any attempt to pass an String whose length is longer than 40 characters will be slapped by the run time.

   --...
   with pre => Right <= V_String_Length;

Anh Vo
 

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

* Re: What do you think about this?
  2015-06-23 20:20               ` Anh Vo
@ 2015-06-23 21:03                 ` Laurent
  2015-06-23 22:17                   ` Shark8
  0 siblings, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-23 21:03 UTC (permalink / raw)


On Tuesday, 23 June 2015 22:20:37 UTC+2, Anh Vo  wrote:

> I would suggest to improve the last two functions with the following preconditions. That means any attempt to pass an String whose length is longer than 40 characters will be slapped by the run time.
> 
>    --...
>    with pre => Right <= V_String_Length;
> 
> Anh Vo

You mean like this? Sry no idea on how to use pre/post conditions.

   function "+" (Right : String) return V_String.Bounded_String
   is (V_String.To_Bounded_String (Right))
   with pre => Right <= V_String_Length;

This doesn't compile. 

Builder results
    /Volumes/Kingston/GPS/Generateur_Trame_Vitek/common_defs_bci.ads
        16:16 expected type universal integer
        16:16 found type "Standard.String"

Either it is normal or I put the with... at the wrong place.

If I change to with pre => V_String.Length(V_String.To_Bounded_String(Right)) <=V_String_Length;
than it compiles but I don't see a difference in behavior. If I try to convert a string longer than max_lenght of V_String then my program dies with raised ADA.STRINGS.LENGTH_ERROR : a-strsup.adb:1926. That happens without the precondition but also with it?

The switch -gnata is enabled (found in the ada gems? that is required for the evaluation of the Pre/post conditions).

Thanks

Laurent

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

* Re: What do you think about this?
  2015-06-23 21:03                 ` Laurent
@ 2015-06-23 22:17                   ` Shark8
  2015-06-24  5:57                     ` Anh Vo
  0 siblings, 1 reply; 71+ messages in thread
From: Shark8 @ 2015-06-23 22:17 UTC (permalink / raw)


On Tuesday, June 23, 2015 at 3:03:21 PM UTC-6, Laurent wrote:
> You mean like this? Sry no idea on how to use pre/post conditions.
> 
>    function "+" (Right : String) return V_String.Bounded_String
>    is (V_String.To_Bounded_String (Right))
>    with pre => Right <= V_String_Length;

You want Right'Length, not Right.
(The error message is the compiler saying it wants a Universal_Integer, but instead got a string.)


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

* Re: What do you think about this?
  2015-06-23 22:17                   ` Shark8
@ 2015-06-24  5:57                     ` Anh Vo
  2015-06-24  7:58                       ` Laurent
  2015-06-24 21:06                       ` Laurent
  0 siblings, 2 replies; 71+ messages in thread
From: Anh Vo @ 2015-06-24  5:57 UTC (permalink / raw)


On Tuesday, June 23, 2015 at 3:17:52 PM UTC-7, Shark8 wrote:
> On Tuesday, June 23, 2015 at 3:03:21 PM UTC-6, Laurent wrote:
> > You mean like this? Sry no idea on how to use pre/post conditions.
> > 
> >    function "+" (Right : String) return V_String.Bounded_String
> >    is (V_String.To_Bounded_String (Right))
> >    with pre => Right <= V_String_Length;
> 
> You want Right'Length, not Right.

You are right. I meant string length, Right'Length, as stated.

In addition, "pragma Assertion_Policy (Check);" should be added at the top of the package. This pragma has the same effect as switch -gnata under GNAT. Of course, all compiler must comply with pragma Assertion_Policy.





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

* Re: Is there an easier way for this?
  2015-06-21 18:38 Is there an easier way for this? Laurent
                   ` (2 preceding siblings ...)
  2015-06-21 19:38 ` Is there an easier way for this? Pascal Obry
@ 2015-06-24  7:14 ` gautier_niouzes
  2015-06-24 21:08   ` Laurent
  3 siblings, 1 reply; 71+ messages in thread
From: gautier_niouzes @ 2015-06-24  7:14 UTC (permalink / raw)


Here from my toolbox - feel free to customize...

--  Time_display returns date & time, current or given.
--  E.g.: "2013/08/01  05:49:51"
--  Useful for a log file or a display of a lengthy operation.
--  This is Ada 83 compatible. Format accepted by SQL queries.
--
--  Test program in following comment:
--
--   with Text_IO,Time_display;
--   procedure Test is begin Text_IO.Put(Time_display);end;

with Calendar;

function Time_display(
  T        : Calendar.Time:= Calendar.Clock;
  Seconds  : Boolean      := True;
  Intra_day: Boolean      := True
)
  return String
is
  use Calendar;
  subtype Sec_int is Long_Integer; -- must contain 86_400
  s : constant Sec_int:= Sec_int( Calendar.Seconds(T) );
  m : constant Sec_int:= s / 60;
  -- + 100: trick for obtaining 0x
  sY : constant String:= Integer'Image( Year(T));
  sM : constant String:= Integer'Image( Month(T) + 100);
  sD : constant String:= Integer'Image(  Day(T)  + 100);
  shr: constant String:= Sec_int'Image( m  /  60 + 100);
  smn: constant String:= Sec_int'Image( m mod 60 + 100);
  ssc: constant String:= Sec_int'Image( s mod 60 + 100);
  --
  function Optional_seconds return String is
  begin
    if Seconds then
      return ':' & ssc( ssc'Last-1 .. ssc'Last );
    else
      return "";
    end if;
  end Optional_seconds;
  --
  function Optional_intra_day return String is
  begin
    if Intra_day then
      return
        "  " &
        shr( shr'Last-1 .. shr'Last ) & ':' &
        smn( smn'Last-1 .. smn'Last ) & Optional_seconds;
    else
      return "";
    end if;
  end Optional_intra_day;

begin
  return
    sY( sY'Last-3 .. sY'Last ) & '/' &  -- not Year 10'000 compliant.
    sM( sM'Last-1 .. sM'Last ) & '/' &
    sD( sD'Last-1 .. sD'Last ) &
    Optional_intra_day;
end Time_display;

_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 


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

* Re: What do you think about this?
  2015-06-24  5:57                     ` Anh Vo
@ 2015-06-24  7:58                       ` Laurent
  2015-06-24 21:06                       ` Laurent
  1 sibling, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-24  7:58 UTC (permalink / raw)


Ah ok 'Length. I was looking for something like that but at the wrong place.


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

* Re: What do you think about this?
  2015-06-23 19:51             ` Laurent
  2015-06-23 20:20               ` Anh Vo
@ 2015-06-24 10:17               ` Stephen Leake
  2015-06-24 17:20                 ` Jeffrey R. Carter
  2015-06-24 20:21                 ` Laurent
  1 sibling, 2 replies; 71+ messages in thread
From: Stephen Leake @ 2015-06-24 10:17 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> On Tuesday, 23 June 2015 16:21:17 UTC+2, Stephen Leake  wrote:
>> I did not download and compile it, but I did browse around it a bit.
>
> That's why I like git.

More precisely, the web front-end to git. Many other source code
management systems have similar web front-ends.

>>What is the whole thing supposed to do?
>
> It is supposed to generate something like this:
>

This should be included in a document in the git repository.

The first step in building a software system is having a clear
description of what it is supposed to do. These are formally called
"requirements"; it is a mantra at NASA that "an engineer does not have a
job until s/he has requirements".

> <snip packet>
> And then write it in a text file.

That's not what you state below.

>
>
> The hospital I work for has acquired a new software for epidemical
> surveillance. I work in the lab in the microbiology department and I
> have been asked to verify the transmission of the results from the
> analyzer to the software used by the nurses/docters.
>
> I have 3 possibilities to do that:
>
> 1) launch tests but that takes 24hrs and I have no influence on the result
> 2) use existing tests and rename them. Which means I have to tinker
> around with results of actual patients. Is bad because of the iso
> certification which requires everything to be traceable. No influence
> on the result
> 3) write a program which generates textfiles with random results which
> I can copy into the transfer folder on the analyzer.

If your requirement is to verify only the transmission of the data, not
the generation of the data from actual patients, then 3 is clearly the
correct choice.

But above you stated your requirement as "generate a text file with a
particular format". Perhaps you have divided up your task into subtasks,
and were talking about a subtask above.

How are you going to compare the test text file to the data recieved by
the "software used by the nurses/doctors"?

>>but it lacks comments
>
> Yup something I have to improve. In this case the program is only used
> by me and quite probable only once.

No program that is paid for will ever be used "only once". In your case,
the analyzer will be upgraded, and the nurse/doctor software will be
upgraded (or either will be replaced). That will require this test to be
done again.

Even if it turns out to be used "only once", writing good comments is
still a good idea. You might get run over by a bus, and someone else
will have to take over. You might be interrupted for a longish time, and
forget the design details.

Good comments are also an extension of the requirements documentation;
they help clarify the design of the software, so you understand it better.

At a minimum, there should be a reference to the analyzer document that
defines the text file format.

>>... it is better to return a String; then the caller can just use it
>> without conversion, or declare a >local variable to hold it.
>
> Well without the "+" conversion function I would agree because the
> To_Bound... thing is annoying.

Yes, but the use of "+" can hide inefficiencies.

> For the last part I don't understand what you mean. In the main file I
> have the function Make_File_Name where File_Name is local variable. If
> it is of type String or the custom V_String, where is the difference?
> Ok I have to convert it later in procedure Generate. Requires an
> additional "+". I find it is a quite good tradeoff for the flexibility
> it offers me.

I'm probably arguing for premature optimization. On the other hand, your
V_String package has an upper bound on string length, which you might
hit at some point.

Learning how to use plain Ada String properly is a useful tool; it helps
avoid many pitfalls.

> For the CMI I would have preferred to use enumerations but that
> doesn't seem to be possible:
>
> CMI_Type is ("<=1","0,004","3"); or CMI_Type is ("1","2","3");

This is not an enumeration; it is an aggregate of strings. In Ada you
can do this as:

type CMI_Type is array (Integer range <>) of access constant String;

CMI_1 : constant CMI_Type := (+"<=", +"0,004", +"3");

where "+" is:

function "+" (Item : in String) return (new String'Item);


> but that works CMI_Type is ('1','2','3'); ?

This defines a new character type.

An enumeration type would be:

type CMI_Type is (One, Two, Three);

There are probably better names for these. And you probably need
something other than CMI_Type'Image (foo) in the output text file. You
can define an array:

type CMI_Image_Type is array (CMI_Type) of access constant String;
CMI_1 : constant CMI_Image_Type := (+"<=", +"0,004", +"3");

or a function:

function Image (Item : in CMI_Type) return String is return
(case Item is
 when One => "<=1",
 when Two => "0,004",
 when Three => "3");


--
-- Stephe


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

* Re: What do you think about this?
  2015-06-24 10:17               ` Stephen Leake
@ 2015-06-24 17:20                 ` Jeffrey R. Carter
  2015-06-24 20:50                   ` Laurent
  2015-06-25 13:16                   ` Stephen Leake
  2015-06-24 20:21                 ` Laurent
  1 sibling, 2 replies; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-24 17:20 UTC (permalink / raw)


On 06/24/2015 03:17 AM, Stephen Leake wrote:
> Laurent <lutgenl@icloud.com> writes:
> 
>> CMI_Type is ("<=1","0,004","3"); or CMI_Type is ("1","2","3");
> 
> This is not an enumeration; it is an aggregate of strings. In Ada you
> can do this as:

Actually, it's invalid.

> type CMI_Type is array (Integer range <>) of access constant String;
> 
> CMI_1 : constant CMI_Type := (+"<=", +"0,004", +"3");

This is a terrible idea. As compiler writer, ARG member, and ARM editor Brukardt
said recently in another thread, anonymous access types are evil. I would even
argue against a named access type for this, since unbounded strings are
available. In this case, the OP has an instance of bounded strings available and
would probably want to use that.

>> but that works CMI_Type is ('1','2','3'); ?
> 
> This defines a new character type.
> 
> An enumeration type would be:
> 
> type CMI_Type is (One, Two, Three);

A character type is an enumeration type. Type Character is an enumeration type,
though one a normal user can't duplicate.

I only looked at the main-program procedure, but my comments are

* Inconsistent use of blank lines
* Inconsistent indentation

There's a function named Make_File_Name. A good guideline is to give procedures
names that are verb phrases (such as Make_File_Name); boolean functions,
predicates (Empty or Is_Empty); and other functions, noun phrases (File_Name).
File_Name would be a better name for this function.

The function returns a bounded string, but the only place it's used takes
String, and so involves a conversion of the result. The function itself creates
its result as a String, then converts it to a bounded string before returning
it. This may be confusing to the reader; I looked around a bit for other uses,
trying to figure out why it was returning a bounded string rather than String.
For this reason (not efficiency), I'd recommend that the function return String.

-- 
Jeff Carter
"Well, a gala day is enough for me. I don't think
I can handle any more."
Duck Soup
93


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

* Re: What do you think about this?
  2015-06-24 10:17               ` Stephen Leake
  2015-06-24 17:20                 ` Jeffrey R. Carter
@ 2015-06-24 20:21                 ` Laurent
  1 sibling, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-24 20:21 UTC (permalink / raw)


On Wednesday, 24 June 2015 12:17:08 UTC+2, Stephen Leake  wrote:

> This should be included in a document in the git repository.
> The first step in building a software system is having a clear
> description of what it is supposed to do. These are formally called
> "requirements"; it is a mantra at NASA that "an engineer does not have a
> job until s/he has requirements".

It is my first real project and I am a noob and I am doing this for fun or doing something more useful than being a couch potato. So no background on how to do things the correct way. That's also the reason why I asked what you think about it. 

I will try to improve the next time.

The problem is that I have only a printout of the formatted text file from the analyzer. I have absolutely no clue if I am allowed to reverse engineer something from that. So I won't mention the name of the company or whatever.

> > <snip packet>
> > And then write it in a text file.
> 
> That's not what you state below.
> 
> >
> > The hospital I work for has acquired a new software for epidemical
> > surveillance. I work in the lab in the microbiology department and I
> > have been asked to verify the transmission of the results from the
> > analyzer to the software used by the nurses/docters.
> >
> > I have 3 possibilities to do that:
> >
> > 1) launch tests but that takes 24hrs and I have no influence on the result
> > 2) use existing tests and rename them. Which means I have to tinker
> > around with results of actual patients. Is bad because of the iso
> > certification which requires everything to be traceable. No influence
> > on the result
> > 3) write a program which generates textfiles with random results which
> > I can copy into the transfer folder on the analyzer.
> 
> If your requirement is to verify only the transmission of the data, not
> the generation of the data from actual patients, then 3 is clearly the
> correct choice.

If I didn't know how to write a program than I would stick to 1) and/or 2). Or handcrafting random text files. Well that would be option 4) and sucks even more. Would have taken as much time as getting my program together.

> But above you stated your requirement as "generate a text file with a
> particular format". Perhaps you have divided up your task into subtasks,
> and were talking about a subtask above.

Not sure if I understand what you mean. In the main program I define the different objects I need. Every type has its own IO package with a procedure which writes only the part it is responsible for. I have been daisy chaining the different components together and at the end I get the desired file.

Then I only have to copy it into the upload folder on the analyzer and if I am lucky I gets treated and finds it way through the different layers of the middleware/LIS and I don't know what else.

So the 2 different things you mentioned actually are the same I think or I didn't understand what you mean.

> How are you going to compare the test text file to the data recieved by
> the "software used by the nurses/doctors"?

For the moment not at all because I don't have access to this particular application. But that's an other problem. 

The IO-packages have the procedure To_BCI which write the different fields and the separators and there is also a Display procedure which shows the content of the message on screen. But more readable. 

I have "just" to add it in the Generate procedure in the main file and perhaps modify it (Display procedure) to write to a text file, would be easier to compare later, instead of scrolling around the terminal window.

> >>but it lacks comments
> >
> > Yup something I have to improve. In this case the program is only used
> > by me and quite probable only once.
> 
> No program that is paid for will ever be used "only once". In your case,
> the analyzer will be upgraded, and the nurse/doctor software will be
> upgraded (or either will be replaced). That will require this test to be
> done again.

Eh who said that I am paid for writing this thing. I am paid for cultivating bacteria on agar plates. 
The verification task is an additional bonus because I couldn't shut my fucking mouth.

I am interested in understanding how the whole online works because I can get some problems solved easier because I know the cause. I have then "just" to kiss the ass of the person who has access to program/integrator/configuration... So the problem gets solved in 5 min instead of hour/days and I get actually do my job. So I got the reputation of being "competent in informatics"
Falls in the category: The one eyed is king among the blind. So far about shutting my mouth.

> Even if it turns out to be used "only once", writing good comments is
> still a good idea. You might get run over by a bus, and someone else
> will have to take over. 

Well in that case I hope the bus doesn't brake and I get a swift death.
Take over? Who?

>You might be interrupted for a longish time, and
> forget the design details.

Yep forget once that I hadn't finished something and whined here why it doesn't work. Cf one of my Stupid problem threats.

> Good comments are also an extension of the requirements documentation;
> they help clarify the design of the software, so you understand it better.
> 
> At a minimum, there should be a reference to the analyzer document that
> defines the text file format.

Yes Google found the specification of the BCI protocol.
 
> >>... it is better to return a String; then the caller can just use it
> >> without conversion, or declare a >local variable to hold it.
> >
> > Well without the "+" conversion function I would agree because the
> > To_Bound... thing is annoying.
> 
> Yes, but the use of "+" can hide inefficiencies.
> 
> > For the last part I don't understand what you mean. In the main file I
> > have the function Make_File_Name where File_Name is local variable. If
> > it is of type String or the custom V_String, where is the difference?
> > Ok I have to convert it later in procedure Generate. Requires an
> > additional "+". I find it is a quite good tradeoff for the flexibility
> > it offers me.
> 
> I'm probably arguing for premature optimization. On the other hand, your
> V_String package has an upper bound on string length, which you might
> hit at some point.
>
> Learning how to use plain Ada String properly is a useful tool; it helps
> avoid many pitfalls.

<rant>
That's which one? Standard.Strings; Ada.Fixed; Bounded, Unbouded or the Gnat.Formatted? Or some other I have forgotten.

If there would be one for all String it would be ok but so I find it very confusing. IMO using Strings in Ada is nearly as complicated than master accesses. Especially because I am a noob and I don't have loaded all the different specifications, the RM and I don't know what else continuously in my brain. <rant/>

> > For the CMI I would have preferred to use enumerations but that
> > doesn't seem to be possible:
> >
> > CMI_Type is ("<=1","0,004","3"); or CMI_Type is ("1","2","3");
> 
> This is not an enumeration; it is an aggregate of strings. In Ada you
> can do this as:
> 
> type CMI_Type is array (Integer range <>) of access constant String;
> 
> CMI_1 : constant CMI_Type := (+"<=", +"0,004", +"3");
> 
> where "+" is:
> 
> function "+" (Item : in String) return (new String'Item);
> 
> 
> > but that works CMI_Type is ('1','2','3'); ?
> 
> This defines a new character type.

Yes and because they are characters the compiler accepts. A character is string with only one element. Why not have the possibility to use strings?

> An enumeration type would be:
> 
> type CMI_Type is (One, Two, Three);
> 
> There are probably better names for these. And you probably need
> something other than CMI_Type'Image (foo) in the output text file. You
> can define an array:
> 
> type CMI_Image_Type is array (CMI_Type) of access constant String;
> CMI_1 : constant CMI_Image_Type := (+"<=", +"0,004", +"3");
> 
> or a function:
> 
> function Image (Item : in CMI_Type) return String is return
> (case Item is
>  when One => "<=1",
>  when Two => "0,004",
>  when Three => "3");

Too complicated for a beginner. Too much risk to make a mess and too few possibilities to find the cause because I can't see the result via Text_IO. And until now I didn't touch the debugger. Not even sure that I can figure out what it tries to tell me.

Have done it like this:

   subtype CMI_Type is V_String.Bounded_String;
   subtype SIR_Type is V_String.Bounded_String;

   Max_Nbr_CMI : constant Positive := 10; -- max number of different CMI

   CMI_1       : constant CMI_Type := (+"0,001"); -- '+' = Common_Defs.To_Bound_String
   CMI_2       : constant CMI_Type := (+ "<=2");
   CMI_3       : constant CMI_Type := (+"4");
   CMI_4       : constant CMI_Type := (+"16");
   CMI_5       : constant CMI_Type := (+">=32");
   CMI_6       : constant CMI_Type := (+"320");
   CMI_7       : constant CMI_Type := (+"SYN-S");
   CMI_8       : constant CMI_Type := (+"SYN-R");
   CMI_9       : constant CMI_Type := (+"Neg");
   CMI_10      : constant CMI_Type := (+"Pos");

 Max_Nbr_SIR : constant Positive := 5; -- max number of different SIR

   SIR_1       : constant SIR_Type := (+"S");
   SIR_2       : constant SIR_Type := (+"I");
   SIR_3       : constant SIR_Type := (+"R");
   SIR_4       : constant SIR_Type := (+"-");
   SIR_5       : constant SIR_Type := (+"+");

   Max_Antibiotiques : constant Natural := 100; -- max number of antibiotics in configuration

   subtype Antibiotiques_Index is Positive range 1 .. Max_Antibiotiques;
   subtype CMI_Index is Positive range 1 .. Max_Nbr_CMI;
   subtype SIR_Index is Positive range 1.. Max_Nbr_SIR;

   type Antibiotique is private;

   type Antibiotiques_Array is array (Antibiotiques_Index) of Antibiotique;
   type CMI_Array is array (CMI_Index) of CMI_Type;
   type SIR_Array is array (SIR_Index) of SIR_Type;

   type Configuration_Array is private;


private

   type Antibiotique is record
      Name     : Name_Type:=(+"null");
      Code_SIL : Code_Type:=(+"null");
      CMI      : CMI_Type:=(+"null");
      SIR      : SIR_Type:=(+"null");
   end record;

   type Configuration_Array is record
      Anti_Config : Antibiotiques_Array;
      CMI_Config  : CMI_Array := (CMI_1, CMI_2, CMI_3, CMI_4, CMI_5,
                                  CMI_6, CMI_7, CMI_8, CMI_9, CMI_10);

      SIR_Config  : SIR_Array := (SIR_1, SIR_2, SIR_3, SIR_4, SIR_5);
      Anti_Counter : Natural := 0;
   end record;

Thanks for the comments. Still have a lot to learn

Laurent


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

* Re: What do you think about this?
  2015-06-24 17:20                 ` Jeffrey R. Carter
@ 2015-06-24 20:50                   ` Laurent
  2015-06-24 22:30                     ` Jeffrey R. Carter
  2015-06-25 13:16                   ` Stephen Leake
  1 sibling, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-24 20:50 UTC (permalink / raw)


On Wednesday, 24 June 2015 19:20:28 UTC+2, Jeffrey R. Carter  wrote:

> I only looked at the main-program procedure, but my comments are
> 
> * Inconsistent use of blank lines

Where? What would be a consistent use? I remember reading some online text about the correct formatting and whatever but I have already forgotten where and what. If you a referring to the declaration of the different objects inside the Generate procedure, well those I would like to hide beneath the carpet because it looks awful. Not sure if the compiler will find them there.

> * Inconsistent indentation

Where? Why? I don't pay special attention to the indentation. Type something, select it and Tab. GPS makes the rest. Sometimes that fails completely.

> There's a function named Make_File_Name. A good guideline is to give procedures
> names that are verb phrases (such as Make_File_Name); boolean functions,
> predicates (Empty or Is_Empty); and other functions, noun phrases (File_Name).
> File_Name would be a better name for this function.

Hm yes I thought already about that. Because Test_Antibiotique: Antibiotiques.Antibiotique := Antibiotique.Antibiotique.Make_Antibiotique (is a function) looks terrible, is too long and somehow redundant. Antibiotique.Make would be clear enough.

So thanks for confirming that point.

> The function returns a bounded string, but the only place it's used takes
> String, and so involves a conversion of the result. The function itself creates
> its result as a String, then converts it to a bounded string before returning
> it. This may be confusing to the reader; I looked around a bit for other uses,
> trying to figure out why it was returning a bounded string rather than String.
> For this reason (not efficiency), I'd recommend that the function return String.

It is returning a bounded String because I have problems with types of Strings and I am quite pissed because of that. The bounded one is doing the things automagically, like I think it should be. But thats only my opinion. The only thing which is missing is an automagical adaption of the length. 

Sort of a dynamical allocating:

So Example_A : Bound_String := "123" so the Example_A'Length = 3
Example_B: Bound_string:= "Only a test"  Example_B'Length = 11

Without having to define a maximum length in an instantiation before you can actually use it. But it should be possible to modify it later on.(IIRC in Java it is different) And being the same type so that no conversion at all is required.

Perhaps Standard.Strings is doing that? No idea. 

But that is probably not possible because of the flame/whine/rant that will start. I know that the automagic belongs to the realm of fantasy.  

Thanks

Laurent


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

* Re: What do you think about this?
  2015-06-24  5:57                     ` Anh Vo
  2015-06-24  7:58                       ` Laurent
@ 2015-06-24 21:06                       ` Laurent
  2015-06-24 21:45                         ` Anh Vo
  1 sibling, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-24 21:06 UTC (permalink / raw)


On Wednesday, 24 June 2015 07:57:51 UTC+2, Anh Vo  wrote:
 
> In addition, "pragma Assertion_Policy (Check);" should be added at the top of the package. This >pragma has the same effect as switch -gnata under GNAT. Of course, all compiler must comply with >pragma Assertion_Policy.

Ah ok now I can see a difference. At least now I get additional info where the problem comes from. Instead of "Oops error"

Thanks.



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

* Re: Is there an easier way for this?
  2015-06-24  7:14 ` gautier_niouzes
@ 2015-06-24 21:08   ` Laurent
  0 siblings, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-24 21:08 UTC (permalink / raw)


On Wednesday, 24 June 2015 09:14:18 UTC+2, gautier...@hotmail.com  wrote:
> Here from my toolbox - feel free to customize...

Thanks. Have added it to my collection of murdoched code.

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

* Re: What do you think about this?
  2015-06-24 21:06                       ` Laurent
@ 2015-06-24 21:45                         ` Anh Vo
  2015-06-24 21:59                           ` Laurent
  2015-06-24 22:35                           ` Simon Wright
  0 siblings, 2 replies; 71+ messages in thread
From: Anh Vo @ 2015-06-24 21:45 UTC (permalink / raw)


On Wednesday, June 24, 2015 at 2:06:05 PM UTC-7, Laurent wrote:
> On Wednesday, 24 June 2015 07:57:51 UTC+2, Anh Vo  wrote:
>  
> > In addition, "pragma Assertion_Policy (Check);" should be added at the top of the package. This >pragma has the same effect as switch -gnata under GNAT. Of course, all compiler must comply with >pragma Assertion_Policy.
> 
> Ah ok now I can see a difference. At least now I get additional info where the problem comes from. Instead of "Oops error"

That is exactly the intention. Here is another beauty. With GNAT, add the following exception handler to your main procedure. Make sure to pass switch -E to your build option. Thus, debugger is rarely needed.

with Gnat.Traceback.Symbolic; use Gnat;
--...
exception
   when Err : others =>
      Put_Line ("Houston we have a problem: " &
                                        Exceptions.Exception_Information(Err));
      Put_Line (Traceback.Symbolic.Symbolic_Traceback(Err));

 
> Thanks.

You are quite welcome.

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

* Re: What do you think about this?
  2015-06-24 21:45                         ` Anh Vo
@ 2015-06-24 21:59                           ` Laurent
  2015-06-24 22:35                           ` Simon Wright
  1 sibling, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-24 21:59 UTC (permalink / raw)


On Wednesday, 24 June 2015 23:45:38 UTC+2, Anh Vo  wrote:
> That is exactly the intention. Here is another beauty. With GNAT, add the following exception >handler to your main procedure. Make sure to pass switch -E to your build option. Thus, debugger >is rarely needed.

Hm switch -E:

gprbuild -d -P/Volumes/Kingston/GPS/Generateur_Trame_Vitek/generateur_trame_vitek.gpr generateur_trame_vt2.adb -E -gnata -gnato -g -O0 -j4
gprbuild: illegal option "-E" on the command line

Is it possible that gprbuild doesn't like that one?

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

* Re: What do you think about this?
  2015-06-24 20:50                   ` Laurent
@ 2015-06-24 22:30                     ` Jeffrey R. Carter
  2015-06-24 22:52                       ` Laurent
  2015-06-27 17:12                       ` Laurent
  0 siblings, 2 replies; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-24 22:30 UTC (permalink / raw)


On 06/24/2015 01:50 PM, Laurent wrote:
> On Wednesday, 24 June 2015 19:20:28 UTC+2, Jeffrey R. Carter  wrote:
> 
>> I only looked at the main-program procedure, but my comments are
>> 
>> * Inconsistent use of blank lines
> 
> Where? What would be a consistent use? I remember reading some online text
> about the correct formatting and whatever but I have already forgotten where
> and what. If you a referring to the declaration of the different objects
> inside the Generate procedure, well those I would like to hide beneath the
> carpet because it looks awful. Not sure if the compiler will find them
> there.

You have to decide for yourself why you use blank lines, and then use them for
that purpose. Blank lines have no meaning to the compiler, so you use them to
help the reader. When should you have a blank line? When should you have 2 blank
lines?

I personally use blank lines to separate compound statements from adjacent lines
with the same indentation level.

>> * Inconsistent indentation
> 
> Where? Why? I don't pay special attention to the indentation. Type something,
> select it and Tab. GPS makes the rest. Sometimes that fails completely.

If you don't care about indentation, why do you have any? Again, indentation is
to help the reader. Usually the indentation level should reflect the nesting
level of the statement.

At the Ada Launch, Ichbiah talked about what he called "comb structures", and
how statements are indented to show that they are nested in such structures.
Examples of comb structures are

procedure George is
|
|
begin
|
|
exception
|
|
end George;

if C1 then
|
|
elsif C2 then
|
|
elsif C3 then\
|
|
else
|
|
end if;

Some combs only have 2 teeth:

Forever : loop
|
|
end loop;

The '|' lines are replaced in real code with declarations or statements nested
inside the comb structure, and indented

> It is returning a bounded String because I have problems with types of
> Strings and I am quite pissed because of that. The bounded one is doing the
> things automagically, like I think it should be. But thats only my opinion.
> The only thing which is missing is an automagical adaption of the length.
> 
> Sort of a dynamical allocating:
> 
> So Example_A : Bound_String := "123" so the Example_A'Length = 3
> Example_B: Bound_string:= "Only a test"  Example_B'Length = 11

Note your inconsistent use of whitespace here. Example_A has spaces on both
sides of ':' and ":="; Example_B on on the right.

> Without having to define a maximum length in an instantiation before you can
> actually use it. But it should be possible to modify it later on.(IIRC in
> Java it is different) And being the same type so that no conversion at all is
> required.
> 
> Perhaps Standard.Strings is doing that? No idea.

String is declared as

type String is array (Positive range <>) of Character;

It's an unconstrained type just like any other unconstrained type. Some
languages have strings that are special, and users cannot declare a type like
them, but in Ada they are just the same as any other array. Your confusion is
likely from expecting String to have special properties; if you can stop
thinking that way then String will probably make more sense.

Of course, String objects have to be constrained:

S1 : String (7 .. 9);
S2 : String := "Only a test";

S1 is explicitly constrained, while S2 gets the constraints of its
initialization value (1 .. 11). Once constrained, the bounds of String object
cannot change. You can change the contents, but not the length, so you can say

S2 (1 .. 4) := "Just"; -- S2 is now "Just a test"

because the array value on the right has the same length as the array object on
the left (4). You can't say

S2 := "123";

because the array value on the right has a length of 3, which is not the same as
the object on the left (11);

In your case you have a function sort of like

function F return Bounded_String is
   R : Bounded_String;
begin -- F
   R := +(A & B & C);

   return R;
end F;

where A, B, and C are of type String. You could eliminate R and just say

   return +(A & B & C);

You use this in a call to a file operation such as Create:

Create (Name => +F, ...);

The parameter Name is of type String. What you could have done is

function F return String is
   -- No declarations
begin -- F
   return A & B & C;
end F;

and then

Create (Name => F, ...);

I hope that helps make things clearer.

-- 
Jeff Carter
"Well, a gala day is enough for me. I don't think
I can handle any more."
Duck Soup
93

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

* Re: What do you think about this?
  2015-06-24 21:45                         ` Anh Vo
  2015-06-24 21:59                           ` Laurent
@ 2015-06-24 22:35                           ` Simon Wright
  2015-06-24 22:59                             ` Laurent
  2015-06-24 23:10                             ` Anh Vo
  1 sibling, 2 replies; 71+ messages in thread
From: Simon Wright @ 2015-06-24 22:35 UTC (permalink / raw)


Anh Vo <anhvofrcaus@gmail.com> writes:

> Make sure to pass switch -E to your build option.

This -E is a gnatbind option.

Either, on the command line

  $ gprbuild <existing arguments> -bargs -E

(-bargs introduces arguments to gnatbind) or in your GPR

   package Binder is
      for Default_Switches ("ada") use ("-E");
   end Binder;

I'm pretty sure you need to have compiled for debug (-g) as well.

(What machine are you building on? getting and interpreting stack dumps
is less straightforward on Macs than on Linux or Windows)

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

* Re: What do you think about this?
  2015-06-24 22:30                     ` Jeffrey R. Carter
@ 2015-06-24 22:52                       ` Laurent
  2015-06-27 17:12                       ` Laurent
  1 sibling, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-24 22:52 UTC (permalink / raw)


On Thursday, 25 June 2015 00:30:32 UTC+2, Jeffrey R. Carter  wrote:

> > So Example_A : Bound_String := "123" so the Example_A'Length = 3
> > Example_B: Bound_string:= "Only a test"  Example_B'Length = 11
> 
> Note your inconsistent use of whitespace here. Example_A has spaces on both
> sides of ':' and ":="; Example_B on on the right.

GPS would have corrected that after typing enter. This is unfortunately not GPS. 

> type String is array (Positive range <>) of Character;
> 
> It's an unconstrained type just like any other unconstrained type. Some
> languages have strings that are special, and users cannot declare a type like
> them, but in Ada they are just the same as any other array. Your confusion is
> likely from expecting String to have special properties; if you can stop
> thinking that way then String will probably make more sense.
> 
> Of course, String objects have to be constrained:
> 
> S1 : String (7 .. 9);
> S2 : String := "Only a test";
> 
> S1 is explicitly constrained, while S2 gets the constraints of its
> initialization value (1 .. 11). Once constrained, the bounds of String object
> cannot change. You can change the contents, but not the length, so you can say
> 
> S2 (1 .. 4) := "Just"; -- S2 is now "Just a test"
> 
> because the array value on the right has the same length as the array object on
> the left (4). You can't say
> 
> S2 := "123";
> 
> because the array value on the right has a length of 3, which is not the same as
> the object on the left (11);
> 
> In your case you have a function sort of like
> 
> function F return Bounded_String is
>    R : Bounded_String;
> begin -- F
>    R := +(A & B & C);
> 
>    return R;
> end F;
> 
> where A, B, and C are of type String. You could eliminate R and just say
> 
>    return +(A & B & C);
> 
> You use this in a call to a file operation such as Create:
> 
> Create (Name => +F, ...);
> 
> The parameter Name is of type String. What you could have done is
> 
> function F return String is
>    -- No declarations
> begin -- F
>    return A & B & C;
> end F;
> 
> and then
> 
> Create (Name => F, ...);
> 
> I hope that helps make things clearer.
> 
> -- 
> Jeff Carter
> "Well, a gala day is enough for me. I don't think
> I can handle any more."
> Duck Soup
> 93

Has to wait until this evening. I will only have 4 hrs of sleep. Great!

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

* Re: What do you think about this?
  2015-06-24 22:35                           ` Simon Wright
@ 2015-06-24 22:59                             ` Laurent
  2015-06-25  2:56                               ` Anh Vo
  2015-06-25  7:29                               ` Simon Wright
  2015-06-24 23:10                             ` Anh Vo
  1 sibling, 2 replies; 71+ messages in thread
From: Laurent @ 2015-06-24 22:59 UTC (permalink / raw)


On Thursday, 25 June 2015 00:35:44 UTC+2, Simon Wright  wrote:
> Anh Vo <anhvofrcausatgmail.com> writes:
> 
> > Make sure to pass switch -E to your build option.
> 
> This -E is a gnatbind option.
> 
> Either, on the command line
> 
>   $ gprbuild <existing arguments> -bargs -E
> 
> (-bargs introduces arguments to gnatbind) or in your GPR
> 
>    package Binder is
>       for Default_Switches ("ada") use ("-E");
>    end Binder;
> 
> I'm pretty sure you need to have compiled for debug (-g) as well.
> 
> (What machine are you building on? getting and interpreting stack dumps
> is less straightforward on Macs than on Linux or Windows)

ok added to gpr . -g is active. Of course I am building on Mac. On Linux would be too easy and windows the temptation is too big to launch a game instead of GPS.

Houston we have a problem: Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE
Message: failed precondition from common_defs_bci.ads:19
Load address: 0x1070dc000
Call stack traceback locations:
0x107111931 0x1070e35f1 0x1070ddf8c 0x1070de763 0x1070de147 0x1070df063

0x0000000107111931
0x00000001070E35F1
0x00000001070DDF8C
0x00000001070DE763
0x00000001070DE147
0x00000001070DF063

I can interpret the 3 first lines. For the rest I will ask my cat(s).

Good night


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

* Re: What do you think about this?
  2015-06-24 22:35                           ` Simon Wright
  2015-06-24 22:59                             ` Laurent
@ 2015-06-24 23:10                             ` Anh Vo
  1 sibling, 0 replies; 71+ messages in thread
From: Anh Vo @ 2015-06-24 23:10 UTC (permalink / raw)


On Wednesday, June 24, 2015 at 3:35:44 PM UTC-7, Simon Wright wrote:
> Anh Vo <anhvofrcaus@gmail.com> writes:
> 
> > Make sure to pass switch -E to your build option.
> 
> This -E is a gnatbind option.
> 
> Either, on the command line
> 
>   $ gprbuild <existing arguments> -bargs -E
> 
> (-bargs introduces arguments to gnatbind) or in your GPR
> 
>    package Binder is
>       for Default_Switches ("ada") use ("-E");
>    end Binder;
> 
> I'm pretty sure you need to have compiled for debug (-g) as well.

You are absolutely correct. Sorry, my fingers do not match with my brain.

> (What machine are you building on? getting and interpreting stack dumps
> is less straightforward on Macs than on Linux or Windows)

It also works on Power PC running VxWorks beside Linux and Windows.

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

* Re: What do you think about this?
  2015-06-24 22:59                             ` Laurent
@ 2015-06-25  2:56                               ` Anh Vo
  2015-06-25  7:29                               ` Simon Wright
  1 sibling, 0 replies; 71+ messages in thread
From: Anh Vo @ 2015-06-25  2:56 UTC (permalink / raw)


On Wednesday, June 24, 2015 at 3:59:43 PM UTC-7, Laurent wrote:
> On Thursday, 25 June 2015 00:35:44 UTC+2, Simon Wright  wrote:
> > Anh Vo <anhvofrcausatgmail.com> writes:
> > 
> > > Make sure to pass switch -E to your build option.
> > 
> > This -E is a gnatbind option.
> > 
> > Either, on the command line
> > 
> >   $ gprbuild <existing arguments> -bargs -E
> > 
> > (-bargs introduces arguments to gnatbind) or in your GPR
> > 
> >    package Binder is
> >       for Default_Switches ("ada") use ("-E");
> >    end Binder;
> > 
> > I'm pretty sure you need to have compiled for debug (-g) as well.
> > 
> > (What machine are you building on? getting and interpreting stack dumps
> > is less straightforward on Macs than on Linux or Windows)
> 
> ok added to gpr . -g is active. Of course I am building on Mac. On Linux would be too easy and windows the temptation is too big to launch a game instead of GPS.
> 
> Houston we have a problem: Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE
> Message: failed precondition from common_defs_bci.ads:19
> Load address: 0x1070dc000
> Call stack traceback locations:
> 0x107111931 0x1070e35f1 0x1070ddf8c 0x1070de763 0x1070de147 0x1070df063
> 
> 0x0000000107111931
> 0x00000001070E35F1
> 0x00000001070DDF8C
> 0x00000001070DE763
> 0x00000001070DE147
> 0x00000001070DF063

I could see that addr2line tool was not bundled with GNAT for MAC OS. Does this tool exist in MAC OS itself at all? I am afraid that the answer is no.


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

* Re: What do you think about this?
  2015-06-24 22:59                             ` Laurent
  2015-06-25  2:56                               ` Anh Vo
@ 2015-06-25  7:29                               ` Simon Wright
  2015-06-25 16:55                                 ` Anh Vo
  2015-06-25 18:13                                 ` Laurent
  1 sibling, 2 replies; 71+ messages in thread
From: Simon Wright @ 2015-06-25  7:29 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> Houston we have a problem: Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE
> Message: failed precondition from common_defs_bci.ads:19
> Load address: 0x1070dc000
> Call stack traceback locations:
> 0x107111931 0x1070e35f1 0x1070ddf8c 0x1070de763 0x1070de147 0x1070df063
>
> 0x0000000107111931
> 0x00000001070E35F1
> 0x00000001070DDF8C
> 0x00000001070DE763
> 0x00000001070DE147
> 0x00000001070DF063
>
> I can interpret the 3 first lines. For the rest I will ask my cat(s).

GNAT.Traceback.Symbolic isn't useful on Mac OS X; all it does is report
the absolute addresses of the stack trace without interpretation. The
fact it does so on multiple lines addes to the inconvenience.

My little example (written for another purpose) is:

   with Ada.Exceptions;
   with Ada.Text_IO; use Ada.Text_IO;
   procedure Raiser is
   begin
      begin
         raise Constraint_Error;
      exception
         when E : Constraint_Error =>
            Put_Line ("CE raised.");
            Put_Line (Ada.Exceptions.Exception_Information (E));
            raise;
      end;
   end Raiser;

and when I run it I get (GNAT GPL 201[4,5], FSF GCC)

   $ ./raiser 
   CE raised.
   Exception name: CONSTRAINT_ERROR
   Message: raiser.adb:6 explicit raise
   Load address: 0x101819000
   Call stack traceback locations:
   0x10181a987 0x10181a925


   Execution terminated by unhandled exception
   Exception name: CONSTRAINT_ERROR
   Message: raiser.adb:6 explicit raise
   Load address: 0x101819000
   Call stack traceback locations:
   0x10181a987 0x10181a925

The first set of messages is from Exception_Information, the last
because of dropping out of the main program.

The linker, by default, generates position-independent executables
(protection against viruses); the Load address line is where we happened
to get loaded this time.

To decode the stack traceback, use atos

   $ atos -d -o raiser -l 0x101819000 0x10181a987 0x10181a925
   got symbolicator for raiser, base address 100000000
   _ada_raiser (in raiser) (raiser.adb:6)
   main (in raiser) (b~raiser.adb:197)

(run atos without -d to see why it's there!)


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

* Re: What do you think about this?
  2015-06-24 17:20                 ` Jeffrey R. Carter
  2015-06-24 20:50                   ` Laurent
@ 2015-06-25 13:16                   ` Stephen Leake
  2015-06-25 17:20                     ` Jeffrey R. Carter
  1 sibling, 1 reply; 71+ messages in thread
From: Stephen Leake @ 2015-06-25 13:16 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:

> On 06/24/2015 03:17 AM, Stephen Leake wrote:
>> Laurent <lutgenl@icloud.com> writes:
>> 
>>> CMI_Type is ("<=1","0,004","3"); or CMI_Type is ("1","2","3");
>> 
>> This is not an enumeration; it is an aggregate of strings. In Ada you
>> can do this as:
>
> Actually, it's invalid.
>
>> type CMI_Type is array (Integer range <>) of access constant String;
>> 
>> CMI_1 : constant CMI_Type := (+"<=", +"0,004", +"3");
>
> This is a terrible idea. As compiler writer, ARG member, and ARM editor Brukardt
> said recently in another thread, anonymous access types are evil. 

This is one place they are very useful.

> I would even
> argue against a named access type for this, since unbounded strings are
> available. In this case, the OP has an instance of bounded strings available and
> would probably want to use that.

That makes them non-constant, which is certainly _not_ the intent!


-- 
-- Stephe


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

* Re: What do you think about this?
  2015-06-25  7:29                               ` Simon Wright
@ 2015-06-25 16:55                                 ` Anh Vo
  2015-06-25 17:27                                   ` Simon Wright
  2015-06-25 18:13                                 ` Laurent
  1 sibling, 1 reply; 71+ messages in thread
From: Anh Vo @ 2015-06-25 16:55 UTC (permalink / raw)


On Thursday, June 25, 2015 at 12:29:45 AM UTC-7, Simon Wright wrote:
> Laurent <lutgenl@icloud.com> writes:
> 
> > Houston we have a problem: Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE
> > Message: failed precondition from common_defs_bci.ads:19
> > Load address: 0x1070dc000
> > Call stack traceback locations:
> > 0x107111931 0x1070e35f1 0x1070ddf8c 0x1070de763 0x1070de147 0x1070df063
> >
> > 0x0000000107111931
> > 0x00000001070E35F1
> > 0x00000001070DDF8C
> > 0x00000001070DE763
> > 0x00000001070DE147
> > 0x00000001070DF063
> >
> > I can interpret the 3 first lines. For the rest I will ask my cat(s).
> 
> GNAT.Traceback.Symbolic isn't useful on Mac OS X; all it does is report
> the absolute addresses of the stack trace without interpretation. The
> fact it does so on multiple lines addes to the inconvenience.
> 
> My little example (written for another purpose) is:
> 
>    with Ada.Exceptions;
>    with Ada.Text_IO; use Ada.Text_IO;
>    procedure Raiser is
>    begin
>       begin
>          raise Constraint_Error;
>       exception
>          when E : Constraint_Error =>
>             Put_Line ("CE raised.");
>             Put_Line (Ada.Exceptions.Exception_Information (E));
>             raise;
>       end;
>    end Raiser;
> 
> and when I run it I get (GNAT GPL 201[4,5], FSF GCC)
> 
>    $ ./raiser 
>    CE raised.
>    Exception name: CONSTRAINT_ERROR
>    Message: raiser.adb:6 explicit raise
>    Load address: 0x101819000
>    Call stack traceback locations:
>    0x10181a987 0x10181a925
> 
> 
>    Execution terminated by unhandled exception
>    Exception name: CONSTRAINT_ERROR
>    Message: raiser.adb:6 explicit raise
>    Load address: 0x101819000
>    Call stack traceback locations:
>    0x10181a987 0x10181a925
> 
> The first set of messages is from Exception_Information, the last
> because of dropping out of the main program.
> 
> The linker, by default, generates position-independent executables
> (protection against viruses); the Load address line is where we happened
> to get loaded this time.
> 
> To decode the stack traceback, use atos
> 
>    $ atos -d -o raiser -l 0x101819000 0x10181a987 0x10181a925
>    got symbolicator for raiser, base address 100000000
>    _ada_raiser (in raiser) (raiser.adb:6)
>    main (in raiser) (b~raiser.adb:197)
 
What happens if you insert the below line before raise statement?

      Put_Line (Traceback.Symbolic.Symbolic_Traceback(Err));




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

* Re: What do you think about this?
  2015-06-25 13:16                   ` Stephen Leake
@ 2015-06-25 17:20                     ` Jeffrey R. Carter
  2015-07-02 21:51                       ` Randy Brukardt
  0 siblings, 1 reply; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-25 17:20 UTC (permalink / raw)


On 06/25/2015 06:16 AM, Stephen Leake wrote:
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
> 
>> This is a terrible idea. As compiler writer, ARG member, and ARM editor Brukardt
>> said recently in another thread, anonymous access types are evil. 
> 
> This is one place they are very useful.

Still evil and to be avoided, even here.

>> I would even
>> argue against a named access type for this, since unbounded strings are
>> available. In this case, the OP has an instance of bounded strings available and
>> would probably want to use that.
> 
> That makes them non-constant, which is certainly _not_ the intent!

Declaring the array constant deals with that.

-- 
Jeff Carter
"I unclog my nose towards you."
Monty Python & the Holy Grail
11


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

* Re: What do you think about this?
  2015-06-25 16:55                                 ` Anh Vo
@ 2015-06-25 17:27                                   ` Simon Wright
  0 siblings, 0 replies; 71+ messages in thread
From: Simon Wright @ 2015-06-25 17:27 UTC (permalink / raw)


Anh Vo <anhvofrcaus@gmail.com> writes:

> What happens if you insert the below line before raise statement?
>
>       Put_Line (Traceback.Symbolic.Symbolic_Traceback(Err));

You get what Laurent described:

>> > Message: failed precondition from common_defs_bci.ads:19
>> > Load address: 0x1070dc000
>> > Call stack traceback locations:
>> > 0x107111931 0x1070e35f1 0x1070ddf8c 0x1070de763 0x1070de147 0x1070df063
>> >
>> > 0x0000000107111931
>> > 0x00000001070E35F1
>> > 0x00000001070DDF8C
>> > 0x00000001070DE763
>> > 0x00000001070DE147
>> > 0x00000001070DF063

and given that you need to use atos to get the decode it is hugely more
convenient to have the hex values in one line rather than in separate
lines.

It's possible that I was responsible for getting AdaCore to produce the
multiline output on Macs, on the grounds that it's better than nothing.

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

* Re: What do you think about this?
  2015-06-25  7:29                               ` Simon Wright
  2015-06-25 16:55                                 ` Anh Vo
@ 2015-06-25 18:13                                 ` Laurent
  2015-06-25 18:36                                   ` Simon Wright
  1 sibling, 1 reply; 71+ messages in thread
From: Laurent @ 2015-06-25 18:13 UTC (permalink / raw)


On Thursday, 25 June 2015 09:29:45 UTC+2, Simon Wright  wrote:
> 
> > Houston we have a problem: Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE
> > Message: failed precondition from common_defs_bci.ads:19
> > Load address: 0x1070dc000
> > Call stack traceback locations:
> > 0x107111931 0x1070e35f1 0x1070ddf8c 0x1070de763 0x1070de147 0x1070df063
> >
> > 0x0000000107111931
> > 0x00000001070E35F1
> > 0x00000001070DDF8C
> > 0x00000001070DE763
> > 0x00000001070DE147
> > 0x00000001070DF063
> >
> > I can interpret the 3 first lines. For the rest I will ask my cat(s).
> 
> GNAT.Traceback.Symbolic isn't useful on Mac OS X; all it does is report
> the absolute addresses of the stack trace without interpretation. The
> fact it does so on multiple lines addes to the inconvenience.
> 
> My little example (written for another purpose) is:
> 
>    with Ada.Exceptions;
>    with Ada.Text_IO; use Ada.Text_IO;
>    procedure Raiser is
>    begin
>       begin
>          raise Constraint_Error;
>       exception
>          when E : Constraint_Error =>
>             Put_Line ("CE raised.");
>             Put_Line (Ada.Exceptions.Exception_Information (E));
>             raise;
>       end;
>    end Raiser;
> 
> and when I run it I get (GNAT GPL 201[4,5], FSF GCC)
> 
>    $ ./raiser 
>    CE raised.
>    Exception name: CONSTRAINT_ERROR
>    Message: raiser.adb:6 explicit raise
>    Load address: 0x101819000
>    Call stack traceback locations:
>    0x10181a987 0x10181a925
> 
> 
>    Execution terminated by unhandled exception
>    Exception name: CONSTRAINT_ERROR
>    Message: raiser.adb:6 explicit raise
>    Load address: 0x101819000
>    Call stack traceback locations:
>    0x10181a987 0x10181a925
> 
> The first set of messages is from Exception_Information, the last
> because of dropping out of the main program.
> 
> The linker, by default, generates position-independent executables
> (protection against viruses); the Load address line is where we happened
> to get loaded this time.
> 
> To decode the stack traceback, use atos
> 
>    $ atos -d -o raiser -l 0x101819000 0x10181a987 0x10181a925
>    got symbolicator for raiser, base address 100000000
>    _ada_raiser (in raiser) (raiser.adb:6)
>    main (in raiser) (b~raiser.adb:197)
> 
> (run atos without -d to see why it's there!)

Hm I checked the man pages for atos on Yosemite. No -d option. The whole thing is just providing some clues where to look for the error. In my case I have assigned a string which is longer than max length. I know where to find the error because it was intentional. But if not and the program is much larger, well good luck then to find it.


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

* Re: What do you think about this?
  2015-06-25 18:13                                 ` Laurent
@ 2015-06-25 18:36                                   ` Simon Wright
  0 siblings, 0 replies; 71+ messages in thread
From: Simon Wright @ 2015-06-25 18:36 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> Hm I checked the man pages for atos on Yosemite. No -d option.

Oh.

Here (Mavericks), if I run without -d, atos shows

 -- 
Warning: /usr/bin/atos is moving and will be removed from a future OS X release.
It is now available in the Xcode developer tools to be invoked via: `xcrun atos`
To silence this warning, pass the '-d' command-line flag to this tool.
 -- 

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

* Re: What do you think about this?
  2015-06-24 22:30                     ` Jeffrey R. Carter
  2015-06-24 22:52                       ` Laurent
@ 2015-06-27 17:12                       ` Laurent
  2015-06-27 17:43                         ` Jeffrey R. Carter
                                           ` (3 more replies)
  1 sibling, 4 replies; 71+ messages in thread
From: Laurent @ 2015-06-27 17:12 UTC (permalink / raw)


On Thursday, 25 June 2015 00:30:32 UTC+2, Jeffrey R. Carter  wrote:

> The parameter Name is of type String. What you could have done is
> 
> function F return String is
>    -- No declarations
> begin -- F
>    return A & B & C;
> end F;
> 
> and then
> 
> Create (Name => F, ...);
> 
> I hope that helps make things clearer.

How is that the compiler accepts that part "return A & B & C;"? Or is that some sort of shortcut which has been introduced at some point. I have seen it been used quite often in JB Ada 2005 and it even works with more complex types but I didn't find an detailed explanation.

>> There's a function named Make_File_Name. A good guideline is to give procedures 
>> names that are verb phrases (such as Make_File_Name); boolean functions, 
>> predicates (Empty or Is_Empty); and other functions, noun phrases (File_Name). 
>> File_Name would be a better name for this function. 

>Hm yes I thought already about that. Because Test_Antibiotique: Antibiotiques.Antibiotique := >Antibiotique.Antibiotique.Make_Antibiotique (is a function) looks terrible, is too long and >somehow redundant. Antibiotique.Make would be clear enough. 

It sucks that renaming function Make_Antibiotique... to function Antibiotique ... doesn't work because I get conflicts between the Type Antibiotique and the function. So what is the recommendation for naming in this case.

package Antibiotiques...

type Antibiotique is private;

function Make_Antibiotique... return Antibiotique;

end Antibiotiques;

Thanks


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

* Re: What do you think about this?
  2015-06-27 17:12                       ` Laurent
@ 2015-06-27 17:43                         ` Jeffrey R. Carter
  2015-06-27 17:47                         ` J-P. Rosen
                                           ` (2 subsequent siblings)
  3 siblings, 0 replies; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-27 17:43 UTC (permalink / raw)


On 06/27/2015 10:12 AM, Laurent wrote:
> 
> How is that the compiler accepts that part "return A & B & C;"? Or is that
> some sort of shortcut which has been introduced at some point. I have seen it
> been used quite often in JB Ada 2005 and it even works with more complex
> types but I didn't find an detailed explanation.

The syntax for a function return is

return <expression>;

where <expression> has the correct type. Here the correct type is String, and
the expression has type String.

> It sucks that renaming function Make_Antibiotique... to function Antibiotique
> ... doesn't work because I get conflicts between the Type Antibiotique and
> the function. So what is the recommendation for naming in this case.
> 
> package Antibiotiques...
> 
> type Antibiotique is private;
> 
> function Make_Antibiotique... return Antibiotique;
> 
> end Antibiotiques;

First I would recommend against mixing languages. Since Ada reserved words are
almost entirely English words, this implies using English identifiers.

I would do

package Antibiotics is
   type Antibiotic_Info is private;

   function Antibiotic ... return Antibiotic_Info;
end Antibiotics;

-- 
Jeff Carter
"My brain hurts!"
Monty Python's Flying Circus
21


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

* Re: What do you think about this?
  2015-06-27 17:12                       ` Laurent
  2015-06-27 17:43                         ` Jeffrey R. Carter
@ 2015-06-27 17:47                         ` J-P. Rosen
  2015-06-27 18:54                         ` Simon Wright
  2015-06-28 14:08                         ` Stephen Leake
  3 siblings, 0 replies; 71+ messages in thread
From: J-P. Rosen @ 2015-06-27 17:47 UTC (permalink / raw)


Le 27/06/2015 19:12, Laurent a écrit :
> It sucks that renaming function Make_Antibiotique... to function Antibiotique ... doesn't work because I get conflicts between the Type Antibiotique and the function. So what is the recommendation for naming in this case.
> 
> package Antibiotiques...
> 
> type Antibiotique is private;
> 
> function Make_Antibiotique... return Antibiotique;
> 
> end Antibiotiques;

I don't like mixing languages either... I would suggest:

package Antibiotiques is
   type Antibiotique is private;
   function Nouvel_Antibiotique return Antibiotique;
end Antibiotiques;

This way the function name (=New_Antibiotic) expresses the value returned.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


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

* Re: What do you think about this?
  2015-06-27 17:12                       ` Laurent
  2015-06-27 17:43                         ` Jeffrey R. Carter
  2015-06-27 17:47                         ` J-P. Rosen
@ 2015-06-27 18:54                         ` Simon Wright
  2015-06-27 19:37                           ` Laurent
  2015-06-28 14:08                         ` Stephen Leake
  3 siblings, 1 reply; 71+ messages in thread
From: Simon Wright @ 2015-06-27 18:54 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> It sucks that renaming function Make_Antibiotique... to function
> Antibiotique ... doesn't work because I get conflicts between the Type
> Antibiotique and the function. So what is the recommendation for
> naming in this case.
>
> package Antibiotiques...
>
> type Antibiotique is private;
>
> function Make_Antibiotique... return Antibiotique;
>
> end Antibiotiques;

I'd just call it Make. The package name disambiguates.

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

* Re: What do you think about this?
  2015-06-27 18:54                         ` Simon Wright
@ 2015-06-27 19:37                           ` Laurent
  2015-06-27 19:47                             ` Jeffrey R. Carter
                                               ` (2 more replies)
  0 siblings, 3 replies; 71+ messages in thread
From: Laurent @ 2015-06-27 19:37 UTC (permalink / raw)


On Saturday, 27 June 2015 20:54:26 UTC+2, Simon Wright  wrote:
> Laurent <lutgenlaticloud.com> writes:
> 
> > It sucks that renaming function Make_Antibiotique... to function
> > Antibiotique ... doesn't work because I get conflicts between the Type
> > Antibiotique and the function. So what is the recommendation for
> > naming in this case.
> >
> > package Antibiotiques...
> >
> > type Antibiotique is private;
> >
> > function Make_Antibiotique... return Antibiotique;
> >
> > end Antibiotiques;
> 
> I'd just call it Make. The package name disambiguates.

Hm the opposite of the messages before. Who is right then? Or just a matter of taste?


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

* Re: What do you think about this?
  2015-06-27 19:37                           ` Laurent
@ 2015-06-27 19:47                             ` Jeffrey R. Carter
  2015-06-27 20:39                             ` Simon Wright
  2015-06-28  4:45                             ` J-P. Rosen
  2 siblings, 0 replies; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-06-27 19:47 UTC (permalink / raw)


On 06/27/2015 12:37 PM, Laurent wrote:
> 
> Who is right then?

I am, by definition :)

-- 
Jeff Carter
"My brain hurts!"
Monty Python's Flying Circus
21

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

* Re: What do you think about this?
  2015-06-27 19:37                           ` Laurent
  2015-06-27 19:47                             ` Jeffrey R. Carter
@ 2015-06-27 20:39                             ` Simon Wright
  2015-06-28  4:45                             ` J-P. Rosen
  2 siblings, 0 replies; 71+ messages in thread
From: Simon Wright @ 2015-06-27 20:39 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> On Saturday, 27 June 2015 20:54:26 UTC+2, Simon Wright  wrote:
>> Laurent <lutgenlaticloud.com> writes:
>> 
>> > It sucks that renaming function Make_Antibiotique... to function
>> > Antibiotique ... doesn't work because I get conflicts between the
>> > Type Antibiotique and the function. So what is the recommendation
>> > for naming in this case.
>> >
>> > package Antibiotiques...
>> >
>> > type Antibiotique is private;
>> >
>> > function Make_Antibiotique... return Antibiotique;
>> >
>> > end Antibiotiques;
>> 
>> I'd just call it Make. The package name disambiguates.
>
> Hm the opposite of the messages before. Who is right then? Or just a
> matter of taste?

A matter of taste, really.

I had a colleague who was writing a package something like

   package Communication is
      type Communication_Message is private;
      procedure Send_Communication_Message
        (Communication_Message_To_Be_Sent : Communication_Message;
         ...);

only the names were longer (so long that the spec couldn't possibly be
fitted into 79 columns, which gave style warnings, which he disabled by
pragma Warnings (Off), so that other significant warnings were disabled
too).

I would have written

   package Communication is
      type Message is private;
      procedure Send (M : Message; ...);

which is, I think, much clearer.

Grady Booch would have named the parameter The_Message.


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

* Re: What do you think about this?
  2015-06-27 19:37                           ` Laurent
  2015-06-27 19:47                             ` Jeffrey R. Carter
  2015-06-27 20:39                             ` Simon Wright
@ 2015-06-28  4:45                             ` J-P. Rosen
  2 siblings, 0 replies; 71+ messages in thread
From: J-P. Rosen @ 2015-06-28  4:45 UTC (permalink / raw)


Le 27/06/2015 21:37, Laurent a écrit :
>>> package Antibiotiques...
>>>
>>> type Antibiotique is private;
>>>
>>> function Make_Antibiotique... return Antibiotique;
>>>
>>> end Antibiotiques;
>>
>> I'd just call it Make. The package name disambiguates.
> 
> Hm the opposite of the messages before. Who is right then? Or just a matter of taste?
> 
Naming conventions are really a matter of taste. It's also influenced by
whether you are use-allergic or not. There is only one important advice:
whatever convention you use, be consistant!

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

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

* Re: What do you think about this?
  2015-06-27 17:12                       ` Laurent
                                           ` (2 preceding siblings ...)
  2015-06-27 18:54                         ` Simon Wright
@ 2015-06-28 14:08                         ` Stephen Leake
  2015-06-28 16:10                           ` Laurent
  3 siblings, 1 reply; 71+ messages in thread
From: Stephen Leake @ 2015-06-28 14:08 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> On Thursday, 25 June 2015 00:30:32 UTC+2, Jeffrey R. Carter  wrote:
>
> It sucks that renaming function Make_Antibiotique... to function
> Antibiotique ... doesn't work because I get conflicts between the Type
> Antibiotique and the function. So what is the recommendation for
> naming in this case.
>
> package Antibiotiques...
>
> type Antibiotique is private;
>
> function Make_Antibiotique... return Antibiotique;
>
> end Antibiotiques;

On option, that is often (but not always) used in the Ada Reference
Manual, is to append "_Type" to the type name whenever you run into this
problem.

That way, you don't have to waste time thinking of a "better" name;
you've already found the best name, but Ada won't let you use it, so you
need to add some noise. Make the noise extremely consistent, so it is
easy to ignore.

However, in this particular case, I agree with Simon; just use "Make" as
the name of the function; there is no need to repeat the name of the
package in the function name.

For that matter, there is no need to repeat the name of the package in
the type either:

package Antibiotiques is
   type Object is private;

   function Make () return Object;

...

-- 
-- Stephe

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

* Re: What do you think about this?
  2015-06-28 14:08                         ` Stephen Leake
@ 2015-06-28 16:10                           ` Laurent
  0 siblings, 0 replies; 71+ messages in thread
From: Laurent @ 2015-06-28 16:10 UTC (permalink / raw)


Thanks to all for this useful advices.

Laurent

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

* Re: What do you think about this?
  2015-06-25 17:20                     ` Jeffrey R. Carter
@ 2015-07-02 21:51                       ` Randy Brukardt
  2015-07-03 12:31                         ` Stephen Leake
  0 siblings, 1 reply; 71+ messages in thread
From: Randy Brukardt @ 2015-07-02 21:51 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:mmhd5h$qef$1@dont-email.me...
> On 06/25/2015 06:16 AM, Stephen Leake wrote:
>> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
>>
>>> This is a terrible idea. As compiler writer, ARG member, and ARM editor 
>>> Brukardt
>>> said recently in another thread, anonymous access types are evil.
>>
>> This is one place they are very useful.
>
> Still evil and to be avoided, even here.
>
>>> I would even
>>> argue against a named access type for this, since unbounded strings are
>>> available. In this case, the OP has an instance of bounded strings 
>>> available and
>>> would probably want to use that.
>>
>> That makes them non-constant, which is certainly _not_ the intent!
>
> Declaring the array constant deals with that.

Exactly. Why make things more complex than necessary? There's a place for 
the access-to-constant solution (although I'd use a named type), but it 
isn't here since the OP is using an bounded string type for all of his 
strings.

                      Randy.




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

* Re: What do you think about this?
  2015-07-02 21:51                       ` Randy Brukardt
@ 2015-07-03 12:31                         ` Stephen Leake
  2015-07-03 17:11                           ` Laurent
  2015-07-03 17:35                           ` Randy Brukardt
  0 siblings, 2 replies; 71+ messages in thread
From: Stephen Leake @ 2015-07-03 12:31 UTC (permalink / raw)


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

> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
> news:mmhd5h$qef$1@dont-email.me...
>> On 06/25/2015 06:16 AM, Stephen Leake wrote:
>>> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
>>>
>>>> This is a terrible idea. As compiler writer, ARG member, and ARM editor 
>>>> Brukardt
>>>> said recently in another thread, anonymous access types are evil.
>>>
>>> This is one place they are very useful.
>>
>> Still evil and to be avoided, even here.
>>
>>>> I would even
>>>> argue against a named access type for this, since unbounded strings are
>>>> available. In this case, the OP has an instance of bounded strings 
>>>> available and
>>>> would probably want to use that.
>>>
>>> That makes them non-constant, which is certainly _not_ the intent!
>>
>> Declaring the array constant deals with that.
>
> Exactly. Why make things more complex than necessary? There's a place for 
> the access-to-constant solution (although I'd use a named type), but it 
> isn't here since the OP is using an bounded string type for all of his 
> strings.

He should not be using a bounded string type; that's the point.

Using a bounded string always involves a hidden length limit; if it's
too small, you'll hit it sometime, if it's too big, you're wasting storage.

-- 
-- Stephe


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

* Re: What do you think about this?
  2015-07-03 12:31                         ` Stephen Leake
@ 2015-07-03 17:11                           ` Laurent
  2015-07-03 17:46                             ` Jeffrey R. Carter
  2015-07-03 19:17                             ` Simon Wright
  2015-07-03 17:35                           ` Randy Brukardt
  1 sibling, 2 replies; 71+ messages in thread
From: Laurent @ 2015-07-03 17:11 UTC (permalink / raw)


On Friday, 3 July 2015 14:31:05 UTC+2, Stephen Leake  wrote:

> He should not be using a bounded string type; that's the point.
> 
> Using a bounded string always involves a hidden length limit; if it's
> too small, you'll hit it sometime, if it's too big, you're wasting storage.
> 
> -- 
> -- Stephe

So you mean that I should do it using something like this? Is an example from my Ada 95 book.

with Ada.Text_IO;
procedure General_Access_Types is
   type String_Pointer is access all String;
   -- all makes String_Pointer a "general access type" as opposed
   -- to a "pool-specific access type". String_Pointer values can
   -- designate declared variables and constants, as well as
   -- dynamically allocated (new) values

   Prompt_1 : aliased String := "Enter a command >";
   Prompt_2 : aliased String := "Thank you.";
   Prompt_3 : aliased String := "Invalid; try again.";
   Prompt_4 : aliased String := "Bye now.";
   -- aliased means "able to be designated by a general access value"

   Prompt_Table : array (1 .. 4)of String_Pointer :=
                    (Prompt_1'Access, Prompt_2'Access,
                     Prompt_3'Access, Prompt_4'Access);
   -- we fill the array with access values: for example, Prompt_1'Access
   -- returns an access value designating Prompt_1

begin -- General_Access_Types

   -- display all the prompts in the table
   for Which in Prompt_Table'Range loop
      Ada.Text_IO.Put (Item => Prompt_Table (Which).all); -- dereference
      Ada.Text_IO.New_Line;
   end loop;
end General_Access_Types;

Thanks

Laurent


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

* Re: What do you think about this?
  2015-07-03 12:31                         ` Stephen Leake
  2015-07-03 17:11                           ` Laurent
@ 2015-07-03 17:35                           ` Randy Brukardt
  2015-07-05 13:55                             ` Stephen Leake
  1 sibling, 1 reply; 71+ messages in thread
From: Randy Brukardt @ 2015-07-03 17:35 UTC (permalink / raw)


"Stephen Leake" <stephen_leake@stephe-leake.org> wrote in message 
news:864mllqv7c.fsf@stephe-leake.org...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message
>> news:mmhd5h$qef$1@dont-email.me...
>>> On 06/25/2015 06:16 AM, Stephen Leake wrote:
>>>> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
>>>>
>>>>> This is a terrible idea. As compiler writer, ARG member, and ARM 
>>>>> editor
>>>>> Brukardt
>>>>> said recently in another thread, anonymous access types are evil.
>>>>
>>>> This is one place they are very useful.
>>>
>>> Still evil and to be avoided, even here.
>>>
>>>>> I would even
>>>>> argue against a named access type for this, since unbounded strings 
>>>>> are
>>>>> available. In this case, the OP has an instance of bounded strings
>>>>> available and
>>>>> would probably want to use that.
>>>>
>>>> That makes them non-constant, which is certainly _not_ the intent!
>>>
>>> Declaring the array constant deals with that.
>>
>> Exactly. Why make things more complex than necessary? There's a place for
>> the access-to-constant solution (although I'd use a named type), but it
>> isn't here since the OP is using an bounded string type for all of his
>> strings.
>
> He should not be using a bounded string type; that's the point.
>
> Using a bounded string always involves a hidden length limit; if it's
> too small, you'll hit it sometime, if it's too big, you're wasting 
> storage.

Agreed, but in that case he probably should be using an unbounded string. 
Let the compiler do the work, don't write memory management code yourself 
(you'll always get it wrong).

                            Randy.




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

* Re: What do you think about this?
  2015-07-03 17:11                           ` Laurent
@ 2015-07-03 17:46                             ` Jeffrey R. Carter
  2015-07-03 18:49                               ` Laurent
  2015-07-03 19:17                             ` Simon Wright
  1 sibling, 1 reply; 71+ messages in thread
From: Jeffrey R. Carter @ 2015-07-03 17:46 UTC (permalink / raw)


On 07/03/2015 10:11 AM, Laurent wrote:
> On Friday, 3 July 2015 14:31:05 UTC+2, Stephen Leake  wrote:
> 
>> He should not be using a bounded string type; that's the point.
>>
>> Using a bounded string always involves a hidden length limit; if it's
>> too small, you'll hit it sometime, if it's too big, you're wasting storage.
>>
>> -- 
>> -- Stephe
> 
> So you mean that I should do it using something like this? Is an example from my Ada 95 book.

No, he means he doesn't like bounded strings. There are times when bounded
strings are appropriate. If you're happy with your use of them, then there's no
reason not to use them. If you're not happy, use
Ada.Strings.Unbounded.Unbounded_String.

-- 
Jeff Carter
"I feel as though somebody stepped on my tongue
with muddy feet."
Never Give a Sucker an Even Break
112


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

* Re: What do you think about this?
  2015-07-03 17:46                             ` Jeffrey R. Carter
@ 2015-07-03 18:49                               ` Laurent
  2015-07-04  3:26                                 ` Randy Brukardt
  0 siblings, 1 reply; 71+ messages in thread
From: Laurent @ 2015-07-03 18:49 UTC (permalink / raw)


On Friday, 3 July 2015 19:46:29 UTC+2, Jeffrey R. Carter  wrote:
> On 07/03/2015 10:11 AM, Laurent wrote:
> > On Friday, 3 July 2015 14:31:05 UTC+2, Stephen Leake  wrote:

> >> Using a bounded string always involves a hidden length limit; if it's
> >> too small, you'll hit it sometime, if it's too big, you're wasting storage.

> No, he means he doesn't like bounded strings.

No offense meant but that falls in the category "Sh*t happens". You can't do it right for everyone and if you do nothing it is also wrong.

> If you're not happy, use Ada.Strings.Unbounded.Unbounded_String.

Aren't Unbounded_Strings wasting memory too? 

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

* Re: What do you think about this?
  2015-07-03 17:11                           ` Laurent
  2015-07-03 17:46                             ` Jeffrey R. Carter
@ 2015-07-03 19:17                             ` Simon Wright
  2015-07-04  3:30                               ` Randy Brukardt
  1 sibling, 1 reply; 71+ messages in thread
From: Simon Wright @ 2015-07-03 19:17 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

>    type String_Pointer is access all String;

Or you could make this 'access constant String' (not sure this is Ada
95, though)

>    Prompt_1 : aliased String := "Enter a command >";

and this would be 'aliased constant String'

>    Prompt_Table : array (1 .. 4) of String_Pointer :=
>                     (Prompt_1'Access, Prompt_2'Access,
>                      Prompt_3'Access, Prompt_4'Access);

or you could say 'array (1 .. 4) of access constant String' and do away
with type String_Pointer.

In any case Prompt_Table can be 'constant array'.

I believe that GNAT has special circuitry to place all these strings and
Prompt_Table in ROM (i.e. no need for elaboration).


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

* Re: What do you think about this?
  2015-07-03 18:49                               ` Laurent
@ 2015-07-04  3:26                                 ` Randy Brukardt
  0 siblings, 0 replies; 71+ messages in thread
From: Randy Brukardt @ 2015-07-04  3:26 UTC (permalink / raw)


"Laurent" <lutgenl@icloud.com> wrote in message 
news:0d266aaa-25f6-49a3-ae0d-e55150182efe@googlegroups.com...
> On Friday, 3 July 2015 19:46:29 UTC+2, Jeffrey R. Carter  wrote:
...
>> If you're not happy, use Ada.Strings.Unbounded.Unbounded_String.
>
> Aren't Unbounded_Strings wasting memory too?

Typical implementations of unbounded string allocate the data either to 
exact size or at most a small increment larger. So unless your bound is very 
small, the amount of waste is likely to be smaller. How much smaller of 
course depends on your data.

                                          Randy.


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

* Re: What do you think about this?
  2015-07-03 19:17                             ` Simon Wright
@ 2015-07-04  3:30                               ` Randy Brukardt
  2015-07-04  4:19                                 ` Laurent
  2015-07-04  7:42                                 ` Simon Wright
  0 siblings, 2 replies; 71+ messages in thread
From: Randy Brukardt @ 2015-07-04  3:30 UTC (permalink / raw)


"Simon Wright" <simon@pushface.org> wrote in message 
news:lyk2uhyrrt.fsf@pushface.org...
> Laurent <lutgenl@icloud.com> writes:
>
>>    type String_Pointer is access all String;
>
> Or you could make this 'access constant String' (not sure this is Ada
> 95, though)

It is. It's not allowed in anonymous access in Ada 95, but it is allowed in 
type declarations.

>>    Prompt_1 : aliased String := "Enter a command >";
>
> and this would be 'aliased constant String'
>
>>    Prompt_Table : array (1 .. 4) of String_Pointer :=
>>                     (Prompt_1'Access, Prompt_2'Access,
>>                      Prompt_3'Access, Prompt_4'Access);
>
> or you could say 'array (1 .. 4) of access constant String' and do away
> with type String_Pointer.

That's not Ada 95 (that was introduced [mistakenly, in hindsight] in Ada 
2005).

>
> In any case Prompt_Table can be 'constant array'.
>
> I believe that GNAT has special circuitry to place all these strings and
> Prompt_Table in ROM (i.e. no need for elaboration).

Probably, but not all Ada compilers will do that. OTOH, it really doesn't 
matter unless you need to burn a ROM (the time elaboration takes is usually 
small enough to ignore).

                         Randy.


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

* Re: What do you think about this?
  2015-07-04  3:30                               ` Randy Brukardt
@ 2015-07-04  4:19                                 ` Laurent
  2015-07-04  7:43                                   ` Simon Wright
  2015-07-04  7:42                                 ` Simon Wright
  1 sibling, 1 reply; 71+ messages in thread
From: Laurent @ 2015-07-04  4:19 UTC (permalink / raw)


Hm can't it be Ada 95? Ada 95 Problem Solving And Program Design  3rd edition. Copyright 1999? How can it be Ada 2005?


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

* Re: What do you think about this?
  2015-07-04  3:30                               ` Randy Brukardt
  2015-07-04  4:19                                 ` Laurent
@ 2015-07-04  7:42                                 ` Simon Wright
  2015-07-05  0:56                                   ` Randy Brukardt
  1 sibling, 1 reply; 71+ messages in thread
From: Simon Wright @ 2015-07-04  7:42 UTC (permalink / raw)


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

> Probably, but not all Ada compilers will do that. OTOH, it really
> doesn't matter unless you need to burn a ROM (the time elaboration
> takes is usually small enough to ignore).

The Cortex-M series have much larger ROM (well, Flash) than RAM; for
example, the Arduino Due has 512K Flash, 96K SRAM. So you are much
better off having constant data that can stay in the Flash.


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

* Re: What do you think about this?
  2015-07-04  4:19                                 ` Laurent
@ 2015-07-04  7:43                                   ` Simon Wright
  2015-07-04  9:07                                     ` Laurent
  0 siblings, 1 reply; 71+ messages in thread
From: Simon Wright @ 2015-07-04  7:43 UTC (permalink / raw)


Laurent <lutgenl@icloud.com> writes:

> Hm can't it be Ada 95? Ada 95 Problem Solving And Program Design 3rd
> edition. Copyright 1999? How can it be Ada 2005?

"it" was my amended version with an array of access constant string.


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

* Re: What do you think about this?
  2015-07-04  7:43                                   ` Simon Wright
@ 2015-07-04  9:07                                     ` Laurent
  0 siblings, 0 replies; 71+ messages in thread
From: Laurent @ 2015-07-04  9:07 UTC (permalink / raw)


Yes after rereading your post and having actually some time to think about it is clear what you meant. Sorry for the whine.

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

* Re: What do you think about this?
  2015-07-04  7:42                                 ` Simon Wright
@ 2015-07-05  0:56                                   ` Randy Brukardt
  0 siblings, 0 replies; 71+ messages in thread
From: Randy Brukardt @ 2015-07-05  0:56 UTC (permalink / raw)


"Simon Wright" <simon@pushface.org> wrote in message 
news:ly7fqgz7vh.fsf@pushface.org...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> Probably, but not all Ada compilers will do that. OTOH, it really
>> doesn't matter unless you need to burn a ROM (the time elaboration
>> takes is usually small enough to ignore).
>
> The Cortex-M series have much larger ROM (well, Flash) than RAM; for
> example, the Arduino Due has 512K Flash, 96K SRAM. So you are much
> better off having constant data that can stay in the Flash.

That's what I said (or meant) -- you're burning a ROM (or doing something 
similar). If you're targeting Windows or Linux, that doesn't apply.

                               Randy.




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

* Re: What do you think about this?
  2015-07-03 17:35                           ` Randy Brukardt
@ 2015-07-05 13:55                             ` Stephen Leake
  2015-07-06 20:07                               ` Randy Brukardt
  0 siblings, 1 reply; 71+ messages in thread
From: Stephen Leake @ 2015-07-05 13:55 UTC (permalink / raw)


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

> "Stephen Leake" <stephen_leake@stephe-leake.org> wrote in message 
> news:864mllqv7c.fsf@stephe-leake.org...

>> Using a bounded string always involves a hidden length limit; if it's
>> too small, you'll hit it sometime, if it's too big, you're wasting 
>> storage.
>
> Agreed, but in that case he probably should be using an unbounded string. 
> Let the compiler do the work, don't write memory management code yourself 
> (you'll always get it wrong).

The use case is declaring arrays of constant strings; no memory
management involved.

-- 
-- Stephe


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

* Re: What do you think about this?
  2015-07-05 13:55                             ` Stephen Leake
@ 2015-07-06 20:07                               ` Randy Brukardt
  0 siblings, 0 replies; 71+ messages in thread
From: Randy Brukardt @ 2015-07-06 20:07 UTC (permalink / raw)


"Stephen Leake" <stephen_leake@stephe-leake.org> wrote in message 
news:864mli3e0k.fsf@stephe-leake.org...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> "Stephen Leake" <stephen_leake@stephe-leake.org> wrote in message
>> news:864mllqv7c.fsf@stephe-leake.org...
>
>>> Using a bounded string always involves a hidden length limit; if it's
>>> too small, you'll hit it sometime, if it's too big, you're wasting
>>> storage.
>>
>> Agreed, but in that case he probably should be using an unbounded string.
>> Let the compiler do the work, don't write memory management code yourself
>> (you'll always get it wrong).
>
> The use case is declaring arrays of constant strings; no memory
> management involved.

There's *always* memory management involved (speaking from the perspective 
of a compiler author), especially as Ada doesn't support arrays of constant 
strings of different lengths. The memory that holds them comes from 
somewhere...and you don't want to be writing that code yourself.

                                                  Randy.



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

end of thread, other threads:[~2015-07-06 20:07 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-21 18:38 Is there an easier way for this? Laurent
2015-06-21 19:15 ` Niklas Holsti
2015-06-21 19:41   ` Laurent
2015-06-21 19:25 ` Jeffrey R. Carter
2015-06-21 19:42   ` Laurent
2015-06-22 12:23   ` Laurent
2015-06-22 15:01     ` G.B.
2015-06-22 15:40       ` Laurent
2015-06-22 16:47     ` Jeffrey R. Carter
2015-06-22 16:41   ` Laurent
2015-06-22 16:47     ` Jeffrey R. Carter
2015-06-22 17:18       ` Laurent
2015-06-22 18:04         ` What do you think about this? Laurent
2015-06-23 14:21           ` Stephen Leake
2015-06-23 19:51             ` Laurent
2015-06-23 20:20               ` Anh Vo
2015-06-23 21:03                 ` Laurent
2015-06-23 22:17                   ` Shark8
2015-06-24  5:57                     ` Anh Vo
2015-06-24  7:58                       ` Laurent
2015-06-24 21:06                       ` Laurent
2015-06-24 21:45                         ` Anh Vo
2015-06-24 21:59                           ` Laurent
2015-06-24 22:35                           ` Simon Wright
2015-06-24 22:59                             ` Laurent
2015-06-25  2:56                               ` Anh Vo
2015-06-25  7:29                               ` Simon Wright
2015-06-25 16:55                                 ` Anh Vo
2015-06-25 17:27                                   ` Simon Wright
2015-06-25 18:13                                 ` Laurent
2015-06-25 18:36                                   ` Simon Wright
2015-06-24 23:10                             ` Anh Vo
2015-06-24 10:17               ` Stephen Leake
2015-06-24 17:20                 ` Jeffrey R. Carter
2015-06-24 20:50                   ` Laurent
2015-06-24 22:30                     ` Jeffrey R. Carter
2015-06-24 22:52                       ` Laurent
2015-06-27 17:12                       ` Laurent
2015-06-27 17:43                         ` Jeffrey R. Carter
2015-06-27 17:47                         ` J-P. Rosen
2015-06-27 18:54                         ` Simon Wright
2015-06-27 19:37                           ` Laurent
2015-06-27 19:47                             ` Jeffrey R. Carter
2015-06-27 20:39                             ` Simon Wright
2015-06-28  4:45                             ` J-P. Rosen
2015-06-28 14:08                         ` Stephen Leake
2015-06-28 16:10                           ` Laurent
2015-06-25 13:16                   ` Stephen Leake
2015-06-25 17:20                     ` Jeffrey R. Carter
2015-07-02 21:51                       ` Randy Brukardt
2015-07-03 12:31                         ` Stephen Leake
2015-07-03 17:11                           ` Laurent
2015-07-03 17:46                             ` Jeffrey R. Carter
2015-07-03 18:49                               ` Laurent
2015-07-04  3:26                                 ` Randy Brukardt
2015-07-03 19:17                             ` Simon Wright
2015-07-04  3:30                               ` Randy Brukardt
2015-07-04  4:19                                 ` Laurent
2015-07-04  7:43                                   ` Simon Wright
2015-07-04  9:07                                     ` Laurent
2015-07-04  7:42                                 ` Simon Wright
2015-07-05  0:56                                   ` Randy Brukardt
2015-07-03 17:35                           ` Randy Brukardt
2015-07-05 13:55                             ` Stephen Leake
2015-07-06 20:07                               ` Randy Brukardt
2015-06-24 20:21                 ` Laurent
2015-06-21 19:38 ` Is there an easier way for this? Pascal Obry
2015-06-21 19:54   ` Laurent
2015-06-21 20:39     ` Pascal Obry
2015-06-24  7:14 ` gautier_niouzes
2015-06-24 21:08   ` Laurent

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