comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: Renaming primitives.
  2024-01-10 11:38  0% ` Jeffrey R.Carter
@ 2024-01-11 10:06  0%   ` Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2024-01-11 10:06 UTC (permalink / raw)


Le 10/01/2024 à 12:38, Jeffrey R.Carter a écrit :
> On 2024-01-10 11:37, Blady wrote:
>>     procedure My_Log_3 (Msg : String) renames My_Generic_Handler.Log;
> 
> My_Generic_Handler.Log is shorthand for My_Generic_Handler.all.Log. 
> According to AARM 8.5.4(5.e/5) 
> (http://www.ada-auth.org/standards/22aarm/html/AA-8-5-4.html), the 
> renaming also renames the prefixing object and passes it to calls to the 
> renamed subprogram: "The prefix in such a case is essentially renamed 
> and passed to any calls of the renamed subprogram."
> 
> So if I understand this correctly the renaming is roughly equivalent to
> 
> <anonymous> : Loggings.Logging renames My_Generic_Handler.all;
> procedure My_Log_3 (Handler : Loggings.Logging := <anonymous>; Msg : 
> String) renames Loggings.Logging.Log;
> 
> except that My_Log_3 is called with only a String parameter even when 
> using positional notation.
> 
> Another way to look at it is that
> 
>     My_Log_3 ("msg");
> 
> is implemented as
> 
>     <anonymous>.Log (Msg => "msg");

Thanks for your useful explanation.

>  > What is happening if My_Generic_Handler change?
>  >
>>        type Full_Logging is new Logging with null record;
>>        procedure Log (Handler : Full_Logging; Msg : String);
>> ...
>>     My_Full_Handler : aliased Loggings.Full_Logging := (Output => 
>> Ada.Text_IO.Current_Output);
>> ...
>>     My_Generic_Handler := My_Full_Handler'Access;
>>
>> Well, logically (?), My_Log_3 follows the change and outputs with 
>> Full_Logging.
> 
> No, My_Log_3 continues to call Log with My_Handler as the object, IIUC.

Yet, the code:
    My_Log_3 ("Hei");
    My_Generic_Handler := My_Full_Handler'Access;
    My_Log_3 ("Hei");
gives:
Hei
Full Hei

I thought that was correct, wasn't it?

Pascal.

^ permalink raw reply	[relevance 0%]

* Re: Renaming primitives.
  2024-01-10 10:37  1% Renaming primitives Blady
  2024-01-10 11:38  0% ` Jeffrey R.Carter
@ 2024-01-10 12:13  0% ` Dmitry A. Kazakov
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2024-01-10 12:13 UTC (permalink / raw)


On 2024-01-10 11:37, Blady wrote:

> Is a procedure renaming equivalent to a simple call?
> For instance:
>     procedure Log (Msg : String) is
>     begin
>        Ada.Text_IO.Put_Line (Msg);
>     end Log;
>     procedure My_Log_1 (Msg : String) is
>     begin
>        Log (Msg);
>     end My_Log_1;
>     procedure My_Log_2 (Msg : String) renames Log;
> 
> Almost, My_Log_1 is equivalent to My_Log_2, isn't it?
> 
> Is it the same with primitives?
> 
> For instance:
>     package Loggings is
>        type Logging is tagged record
>           Output : Ada.Text_IO.File_Access;
>        end record;
>        procedure Log (Handler : Logging; Msg : String);
>     end Loggings;
>     My_Handler : aliased Loggings.Logging := (Output => 
> Ada.Text_IO.Current_Output);
>     My_Generic_Handler : access Loggings.Logging'Class := 
> My_Handler'Access;
>     procedure My_Log_3 (Msg : String) renames My_Generic_Handler.Log;
> 
> To my surprise (well I hoped) My_Log_3 is compiled by GNAT.
> Is it conformed to the Ada standard?

This looks like a bug to me. ARM 8.5.4 (2/3) states that the right part 
of "renames" must be a name of a callable entity. My_Generic_Handler.Log 
is a procedure call which is not a callable entity name.

Renaming a callable result of a function call might be legal [and quite 
funny].

Disclaimer. I am not a language lawyer.

P.S. Specialization of subprograms would be a nice feature, though.

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

^ permalink raw reply	[relevance 0%]

* Re: Renaming primitives.
  2024-01-10 10:37  1% Renaming primitives Blady
@ 2024-01-10 11:38  0% ` Jeffrey R.Carter
  2024-01-11 10:06  0%   ` Blady
  2024-01-10 12:13  0% ` Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2024-01-10 11:38 UTC (permalink / raw)


On 2024-01-10 11:37, Blady wrote:
> 
>     package Loggings is
>        type Logging is tagged record
>           Output : Ada.Text_IO.File_Access;
>        end record;
>        procedure Log (Handler : Logging; Msg : String);
>     end Loggings;
>     My_Handler : aliased Loggings.Logging := (Output => Ada.Text_IO.Current_Output);
>     My_Generic_Handler : access Loggings.Logging'Class := My_Handler'Access;
>     procedure My_Log_3 (Msg : String) renames My_Generic_Handler.Log;

My_Generic_Handler.Log is shorthand for My_Generic_Handler.all.Log. According to 
AARM 8.5.4(5.e/5) (http://www.ada-auth.org/standards/22aarm/html/AA-8-5-4.html), 
the renaming also renames the prefixing object and passes it to calls to the 
renamed subprogram: "The prefix in such a case is essentially renamed and passed 
to any calls of the renamed subprogram."

So if I understand this correctly the renaming is roughly equivalent to

<anonymous> : Loggings.Logging renames My_Generic_Handler.all;
procedure My_Log_3 (Handler : Loggings.Logging := <anonymous>; Msg : String) 
renames Loggings.Logging.Log;

except that My_Log_3 is called with only a String parameter even when using 
positional notation.

Another way to look at it is that

    My_Log_3 ("msg");

is implemented as

    <anonymous>.Log (Msg => "msg");

 > What is happening if My_Generic_Handler change?
 >
>        type Full_Logging is new Logging with null record;
>        procedure Log (Handler : Full_Logging; Msg : String);
> ...
>     My_Full_Handler : aliased Loggings.Full_Logging := (Output => 
> Ada.Text_IO.Current_Output);
> ...
>     My_Generic_Handler := My_Full_Handler'Access;
> 
> Well, logically (?), My_Log_3 follows the change and outputs with Full_Logging.

No, My_Log_3 continues to call Log with My_Handler as the object, IIUC.

> Unfortunately, GNAT claims renaming with several parameters.
> I add:
>        procedure Log (Handler : Logging; Msg : String; Err : Natural);
> ...
>     procedure My_Log_4 (Msg : String; Err : Natural) renames 
> My_Generic_Handler.Log;
> 
> I got:
> test_20240110_renproc.adb:47:14: error: too many arguments in call to "log"
> 
> Is it a correct or a GNAT issue?

I'm not sure what is going on here. This looks correct to me.

-- 
Jeff Carter
"Fundamental improvements in performance
are most often made by algorithm changes,
not by tuning."
Elements of Programming Style
201

^ permalink raw reply	[relevance 0%]

* Renaming primitives.
@ 2024-01-10 10:37  1% Blady
  2024-01-10 11:38  0% ` Jeffrey R.Carter
  2024-01-10 12:13  0% ` Dmitry A. Kazakov
  0 siblings, 2 replies; 200+ results
From: Blady @ 2024-01-10 10:37 UTC (permalink / raw)


Hello,

Is a procedure renaming equivalent to a simple call?
For instance:
    procedure Log (Msg : String) is
    begin
       Ada.Text_IO.Put_Line (Msg);
    end Log;
    procedure My_Log_1 (Msg : String) is
    begin
       Log (Msg);
    end My_Log_1;
    procedure My_Log_2 (Msg : String) renames Log;

Almost, My_Log_1 is equivalent to My_Log_2, isn't it?

Is it the same with primitives?

For instance:
    package Loggings is
       type Logging is tagged record
          Output : Ada.Text_IO.File_Access;
       end record;
       procedure Log (Handler : Logging; Msg : String);
    end Loggings;
    My_Handler : aliased Loggings.Logging := (Output => 
Ada.Text_IO.Current_Output);
    My_Generic_Handler : access Loggings.Logging'Class := My_Handler'Access;
    procedure My_Log_3 (Msg : String) renames My_Generic_Handler.Log;

To my surprise (well I hoped) My_Log_3 is compiled by GNAT.
Is it conformed to the Ada standard?

What is happening if My_Generic_Handler change?

For instance:
       type Full_Logging is new Logging with null record;
       procedure Log (Handler : Full_Logging; Msg : String);
...
    My_Full_Handler : aliased Loggings.Full_Logging := (Output => 
Ada.Text_IO.Current_Output);
...
    My_Generic_Handler := My_Full_Handler'Access;

Well, logically (?), My_Log_3 follows the change and outputs with 
Full_Logging.

Unfortunately, GNAT claims renaming with several parameters.
I add:
       procedure Log (Handler : Logging; Msg : String; Err : Natural);
...
    procedure My_Log_4 (Msg : String; Err : Natural) renames 
My_Generic_Handler.Log;

I got:
test_20240110_renproc.adb:47:14: error: too many arguments in call to "log"

Is it a correct or a GNAT issue?

Full source code on demand.

Thanks.
Happy New Year to all!
Pascal.

^ permalink raw reply	[relevance 1%]

* Re: get_immediate echoe character--compiled error?
  2023-10-04 13:05  1%                     ` Jeffrey R.Carter
@ 2023-10-05  0:43  0%                       ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2023-10-05  0:43 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message 
news:ufjnu0$62ki$1@dont-email.me...
> On 2023-10-04 13:38, Simon Wright wrote:
>>
>> Obviously you need to turn echoing off for password input. But neither
>> the ARM nor the GNAT RM says anything about Get_Immediate's echoing
>> behaviour, so it's hard to explain why OA does the same thing. Does its
>> manual specify this behaviour?
>
> Unfortunately, Ada does not provide a standard way to turn off echo.
>
> I agree that the ARM says nothing about echo for any of its operations on 
> Standard_Input, but clearly there is a broad consensus of Ada.Text_IO 
> writers and users who think this is desirable behavior.

For what it's worth, Janus/Ada turns off echoing, and that was decided 
without referring to any other implementation's choice in the matter. 
Rather, it was done to provide a way using standard calls to provide 
functionality that had always been available in Janus/Ada in a non-standard 
way.

Specifically, Janus/Ada has always had a predefined file name "KBD:" (or 
"/dev/kbd" on Unix), which provides raw access to the keyboard device (or 
standard input on more modern systems). This did not echo (or do any line 
editing) on CP/M and MS-DOS, and we carried that same behavior over into 
more modern systems.

For instance, the "Continue or Abort?" question in the compiler uses KBD: to 
take and discard input immediately without any waiting (usual standard input 
is line buffered and usually input is not processed until "enter" or similar 
is pressed). It seemed to us that the Get_Immediate function was intending 
the same sorts of uses. Note that implementing it this way makes it hard to 
get meaningful results if Get_Immediate is mixed with other input on the 
same file. (That's why we treated it as a special file in the beginning, but 
even that gets confused if someone else reads from Standard_Input.)

                                  Randy. 


^ permalink raw reply	[relevance 0%]

* Re: get_immediate echoe character--compiled error?
  2023-10-04 21:14  0% ` Jeffrey R.Carter
@ 2023-10-04 22:12  0%   ` Keith Thompson
  0 siblings, 0 replies; 200+ results
From: Keith Thompson @ 2023-10-04 22:12 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
> On 2023-10-02 04:42, richardthiebaud wrote:
>> with ada.text_io; use ada.text_io;
>> procedure test3 is
>>    c: character;
>>    avail: boolean;
>> begin
>>    loop
>>      loop
>>        Get_Immediate(c, Avail);
>>        if Avail then
>>          exit;
>>        end if;
>>        delay 0.01;
>>      end loop;
>>    end loop;
>> end test3;
>
> I should have checked this earlier, but this does not echo with ObjectAda.

On what target system?

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[relevance 0%]

* Re: get_immediate echoe character--compiled error?
  2023-10-02  2:42  1% get_immediate echoe character--compiled error? richardthiebaud
  2023-10-02  5:48  0% ` Keith Thompson
@ 2023-10-04 21:14  0% ` Jeffrey R.Carter
  2023-10-04 22:12  0%   ` Keith Thompson
  1 sibling, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-10-04 21:14 UTC (permalink / raw)


On 2023-10-02 04:42, richardthiebaud wrote:
> 
> with ada.text_io; use ada.text_io;
> procedure test3 is
>    c: character;
>    avail: boolean;
> begin
>    loop
>      loop
>        Get_Immediate(c, Avail);
>        if Avail then
>          exit;
>        end if;
>        delay 0.01;
>      end loop;
>    end loop;
> end test3;

I should have checked this earlier, but this does not echo with ObjectAda.

-- 
Jeff Carter
“[A]bout half the patterns in the 'Gang of Four'
book only exist because of defects in C++ ...”
Brian Drummond
174

^ permalink raw reply	[relevance 0%]

* Re: get_immediate echoe character--compiled error?
  @ 2023-10-04 13:05  1%                     ` Jeffrey R.Carter
  2023-10-05  0:43  0%                       ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-10-04 13:05 UTC (permalink / raw)


On 2023-10-04 13:38, Simon Wright wrote:
> 
> Obviously you need to turn echoing off for password input. But neither
> the ARM nor the GNAT RM says anything about Get_Immediate's echoing
> behaviour, so it's hard to explain why OA does the same thing. Does its
> manual specify this behaviour?

Unfortunately, Ada does not provide a standard way to turn off echo.

I agree that the ARM says nothing about echo for any of its operations on 
Standard_Input, but clearly there is a broad consensus of Ada.Text_IO writers 
and users who think this is desirable behavior.

-- 
Jeff Carter
“[A]bout half the patterns in the 'Gang of Four'
book only exist because of defects in C++ ...”
Brian Drummond
174

^ permalink raw reply	[relevance 1%]

* Re: get_immediate echoe character--compiled error?
  2023-10-02  5:48  0% ` Keith Thompson
@ 2023-10-02 20:07  0%   ` richardthiebaud
    0 siblings, 1 reply; 200+ results
From: richardthiebaud @ 2023-10-02 20:07 UTC (permalink / raw)


On 10/2/23 01:48, Keith Thompson wrote:
> richardthiebaud <thiebauddick2@aol.com> writes:
>> When I build and run the following program using Gnat 11 in Linux Mint
>> 21.2, the keys I press are echoed on the console. According to the Ada
>> Reference Manual, they should not be echoed. Is this a compiler error?
> 
> Where does the ARM say that?
https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-10-7.html

> 
>> with ada.text_io; use ada.text_io;
>> procedure test3 is
>>    c: character;
>>    avail: boolean;
>> begin
>>    loop
>>      loop
>>        Get_Immediate(c, Avail);
>>        if Avail then
>>          exit;
>>        end if;
>>        delay 0.01;
>>      end loop;
>>    end loop;
>> end test3;	
>>
>> This does not happen if I call get_immediate without the avail
>> parameter, i.e. get_immediate(c);
>>
> 

^ permalink raw reply	[relevance 0%]

* Re: get_immediate echoe character--compiled error?
  2023-10-02  2:42  1% get_immediate echoe character--compiled error? richardthiebaud
@ 2023-10-02  5:48  0% ` Keith Thompson
  2023-10-02 20:07  0%   ` richardthiebaud
  2023-10-04 21:14  0% ` Jeffrey R.Carter
  1 sibling, 1 reply; 200+ results
From: Keith Thompson @ 2023-10-02  5:48 UTC (permalink / raw)


richardthiebaud <thiebauddick2@aol.com> writes:
> When I build and run the following program using Gnat 11 in Linux Mint
> 21.2, the keys I press are echoed on the console. According to the Ada 
> Reference Manual, they should not be echoed. Is this a compiler error?

Where does the ARM say that?

> with ada.text_io; use ada.text_io;
> procedure test3 is
>   c: character;
>   avail: boolean;
> begin
>   loop
>     loop
>       Get_Immediate(c, Avail);
>       if Avail then
>         exit;
>       end if;
>       delay 0.01;
>     end loop;
>   end loop;
> end test3;	
>
> This does not happen if I call get_immediate without the avail
> parameter, i.e. get_immediate(c);
>

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[relevance 0%]

* get_immediate echoe character--compiled error?
@ 2023-10-02  2:42  1% richardthiebaud
  2023-10-02  5:48  0% ` Keith Thompson
  2023-10-04 21:14  0% ` Jeffrey R.Carter
  0 siblings, 2 replies; 200+ results
From: richardthiebaud @ 2023-10-02  2:42 UTC (permalink / raw)


When I build and run the following program using Gnat 11 in Linux Mint 
21.2, the keys I press are echoed on the console. According to the Ada 
Reference Manual, they should not be echoed. Is this a compiler error?

with ada.text_io; use ada.text_io;
procedure test3 is
   c: character;
   avail: boolean;
begin
   loop
     loop
       Get_Immediate(c, Avail);
       if Avail then
         exit;
       end if;
       delay 0.01;
     end loop;
   end loop;
end test3;	

This does not happen if I call get_immediate without the avail 
parameter, i.e. get_immediate(c);

^ permalink raw reply	[relevance 1%]

* Re: GNAT linking and macOS
  @ 2023-09-30  2:30  1%     ` Kenneth Wolcott
  0 siblings, 0 replies; 200+ results
From: Kenneth Wolcott @ 2023-09-30  2:30 UTC (permalink / raw)


Hi Simon;

>I'd recommend taking a copy of /Library/Developer/CommandLineTools 
> before updating to 15.0.

Well, I should have done this, but I didn't...

> > It turns out there's an environment variable DEFAULT_LINKER, which with

I tried this (xport DEFAULT_LINKER=/Library/Developer/CommandLineTools/usr/bin/ld-classic) and it did not help:

Using:

/opt/gcc-13.1.0-aarch64/bin/gnatmake --version
GNATMAKE 13.1.0

-- This is from Rosetta Code:

with Ada.Text_IO;  use Ada.Text_IO;

procedure Test_Short_Circuit is
   function A (Value : Boolean) return Boolean is
   begin
      Put (" A=" & Boolean'Image (Value));
      return Value;
   end A;
   function B (Value : Boolean) return Boolean is
   begin
      Put (" B=" & Boolean'Image (Value));
      return Value;
   end B;
begin
   for I in Boolean'Range loop
      for J in Boolean'Range loop
         Put (" (A and then B)=" & Boolean'Image (A (I) and then B (J)));
         New_Line;
      end loop;
   end loop;
   for I in Boolean'Range loop
      for J in Boolean'Range loop
         Put (" (A or else B)=" & Boolean'Image (A (I) or else B (J)));
         New_Line;
      end loop;
   end loop;
end Test_Short_Circuit;

gnatmake test_short_circuit.adb
gcc -c test_short_circuit.adb
gnatbind -x test_short_circuit.ali
gnatlink test_short_circuit.ali
-macosx_version_min has been renamed to -macos_version_min
ld: warning: ignoring duplicate libraries: '-lgcc'
0  0x10306b648  __assert_rtn + 72
1  0x102f9ffac  ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1204
2  0x102fb5924  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 15164
3  0x102fc304c  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 960
4  0x18e36d950  _dispatch_client_callout2 + 20
5  0x18e3821a4  _dispatch_apply_invoke_and_wait + 176
6  0x18e381464  _dispatch_apply_with_attr_f + 1176
7  0x18e381650  dispatch_apply + 96
8  0x10303d3b8  ld::AtomFileConsolidator::parseFiles(bool) + 292
9  0x102fde170  main + 9048
ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
collect2: error: ld returned 1 exit status
gnatlink: error when calling /opt/gcc-13.1.0-aarch64/bin/gcc
gnatmake: *** link failed.

Are there any other workarounds to solve the inability to link?  This does not only adversely affect Ada, but everything that uses a linker, BTW.

Thanks,
Ken Wolcott

^ permalink raw reply	[relevance 1%]

* Re: Valid attribute and input operations
  2023-09-23 21:48  1% ` Jeffrey R.Carter
@ 2023-09-26  6:13  0%   ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2023-09-26  6:13 UTC (permalink / raw)


I believe Jeffrey's analysis is correct.

Note that there are some special cases for validity that are intended to 
make it easier to write code like that you have. But they only make sense 
for base subtypes (and the type you have is not that). Moreover, they are 
not foolproof -- exceution is not erroneous in these cases, but they still 
are a bounded error, and it is always correct for a bounded error to be 
detected and raise Program_Error.

This can happen in practice, too. For instance, for Janus/Ada, enumeration 
types with specified representations operate internally on the position 
numbers, and thus reading an enumeration variable will convert the 
representation to a position number with a table lookup. If the lookup 
fails, Program_Error is raised, and that happens before the value ever can 
be assigned to a named variable (and thus before any possible test of 
validity). I believe that we identified other similar cases back in the day. 
Probably one of them is the signalling NaN. Some bit patterns for float 
values represent signalling NaNs, which trap instantly if read. That's at 
the hardware level on most processors, so the only hope is the handle the 
resulting exception. It's too late by the time you get to 'Valid.

Moral: to make truly bulletproof code, you have to handle exceptions AND use 
'Valid. You probably can skip the exceptions if everything is typed with 
integer basetypes, but if any other kinds of types are involved, they are 
necessary.

                  Randy.

"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message 
news:uenmg1$qctd$1@dont-email.me...
> On 2023-09-23 22:22, Maciej Sobczak wrote:
>>
>> I have checked the above program on several on-line compilers, all of 
>> them behave according to interpretation 2 above.
>> Richard claims to get behavior 1 on his compiler.
>>
>> What is your take on this? Any language lawyers?
>
> The important thing is the definition of Ada.Text_IO.Integer_IO.Get [ARM 
> A.10.8(7-10)]:
>
> "... skips any leading blanks, line terminators, or page terminators, then 
> reads a plus sign if present or (for a signed type only) a minus sign if 
> present, then reads the longest possible sequence of characters matching 
> the syntax of a numeric literal without a point. ...
>
> "Returns, in the parameter Item, the value of type Num that corresponds to 
> the sequence input.
>
> "The exception Data_Error is propagated if the sequence of characters read 
> does not form a legal integer literal or if the value obtained is not of 
> the subtype Num."
>
> So a call to Get can only return a valid value of type Num (Integer for 
> your case) or raise Data_Error.
>
> If Get is reading "500" then that certainly represents a valid value of 
> type Integer, and Get should copy that back to the actual parameter.
>
> If you are using Ada (a language with run-time checks), then a check 
> should be made that the value is in the range of the actual parameter's 
> subtype, here Integer range 0 .. 200. That should fail and 
> Constraint_Error should be raised.
>
> However, if you are not using Ada because that check has been suppressed, 
> then the actual parameter will be left with the invalid value 500 and 
> Constraint_Error will not be raised.
>
> If I build your program with checks enabled, I get Constraint_Error. If I 
> build it with checks suppressed, I get the not-valid message (GNAT 12.3).
>
> -- 
> Jeff Carter
> "If you don't get the President of the United States on that
> phone, ... you're going to have to answer to the Coca-Cola
> Company."
> Dr. Strangelove
> 32
> 


^ permalink raw reply	[relevance 0%]

* Re: Valid attribute and input operations
  2023-09-23 20:22  1% Valid attribute and input operations Maciej Sobczak
@ 2023-09-23 21:48  1% ` Jeffrey R.Carter
  2023-09-26  6:13  0%   ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-09-23 21:48 UTC (permalink / raw)


On 2023-09-23 22:22, Maciej Sobczak wrote:
> 
> I have checked the above program on several on-line compilers, all of them behave according to interpretation 2 above.
> Richard claims to get behavior 1 on his compiler.
> 
> What is your take on this? Any language lawyers?

The important thing is the definition of Ada.Text_IO.Integer_IO.Get [ARM 
A.10.8(7-10)]:

"... skips any leading blanks, line terminators, or page terminators, then reads 
a plus sign if present or (for a signed type only) a minus sign if present, then 
reads the longest possible sequence of characters matching the syntax of a 
numeric literal without a point. ...

"Returns, in the parameter Item, the value of type Num that corresponds to the 
sequence input.

"The exception Data_Error is propagated if the sequence of characters read does 
not form a legal integer literal or if the value obtained is not of the subtype 
Num."

So a call to Get can only return a valid value of type Num (Integer for your 
case) or raise Data_Error.

If Get is reading "500" then that certainly represents a valid value of type 
Integer, and Get should copy that back to the actual parameter.

If you are using Ada (a language with run-time checks), then a check should be 
made that the value is in the range of the actual parameter's subtype, here 
Integer range 0 .. 200. That should fail and Constraint_Error should be raised.

However, if you are not using Ada because that check has been suppressed, then 
the actual parameter will be left with the invalid value 500 and 
Constraint_Error will not be raised.

If I build your program with checks enabled, I get Constraint_Error. If I build 
it with checks suppressed, I get the not-valid message (GNAT 12.3).

-- 
Jeff Carter
"If you don't get the President of the United States on that
phone, ... you're going to have to answer to the Coca-Cola
Company."
Dr. Strangelove
32

^ permalink raw reply	[relevance 1%]

* Valid attribute and input operations
@ 2023-09-23 20:22  1% Maciej Sobczak
  2023-09-23 21:48  1% ` Jeffrey R.Carter
  0 siblings, 1 reply; 200+ results
From: Maciej Sobczak @ 2023-09-23 20:22 UTC (permalink / raw)


Hi there,

I am in the middle of a heated debate with Richard Riehle on LinkedIn, where we cannot get to terms with regard to the exact semantics of X'Valid in the context of input operations performed by standard Get procedure.
In short, consider the following example:

with Ada.Text_IO;
with Ada.Integer_Text_IO;
procedure Is_Valid_Test is
   X : Integer range 0..200;
begin
   Ada.Text_IO.Put("Get an Integer: ");
   Ada.Integer_Text_IO.Get(X);
   if X'Valid then
      Ada.Text_IO.Put_Line("The Input is Valid ");
   else
      Ada.Text_IO.Put_Line("The Input is not Valid ");
   end if;
end Is_Valid_Test;

When the input is 500, what should be the behavior of this program?
There are two interpretations:

1. Get is an input operation and can create invalid representations (as stated in 13.9.2, p.7). Then, the X'Valid test that follows Get(X) can be used to safely recognize whether the value is in the range or not. The program should print the second string (from the else branch), but should not raise any exceptions for this input (500).

2. Get is not an input operation in the meaning referred to in 13.9.2/7, or is an input, but only for type Integer (and it cannot create invalid integer representations on typical computers anyway). The X variable is an actual parameter that has a subtype that is different from the formal parameter and is subject to conversions when the Get subprogram exits normally (6.4.1/17,17a). This conversion should raise Constraint_Error for this input (500).

I have checked the above program on several on-line compilers, all of them behave according to interpretation 2 above.
Richard claims to get behavior 1 on his compiler.

What is your take on this? Any language lawyers?

Regards,
Maciej Sobczak

^ permalink raw reply	[relevance 1%]

* Re: Weird behavior of Get character with trailing new lines.
  2023-09-22 19:30  1% Weird behavior of Get character with trailing new lines Blady
@ 2023-09-22 19:52  0% ` Niklas Holsti
  0 siblings, 0 replies; 200+ results
From: Niklas Holsti @ 2023-09-22 19:52 UTC (permalink / raw)


On 2023-09-22 22:30, Blady wrote:
> Hello,
> 
> I'm reading a text file with Get character from Text_IO with a while 
> loop controlled by End_Of_File.
> 
> % cat test_20230922_get_char.adb
> with Ada.Text_IO; use Ada.Text_IO;
> procedure test_20230922_get_char is
>     procedure Get is
>        F : File_Type;
>        Ch : Character;
>     begin
>        Open (F, In_File, "test_20230922_get_char.adb");
>        while not End_Of_File(F) loop
>           Get (F, Ch);
>           Put (Ch);
>        end loop;
>        Close (F);
>        Put_Line ("File read with get.");
>     end;
> begin
> Get;
> end;
> 
> 
> 
> All will be well, unfortunately not!
> 
> Despite the End_Of_File, I got an END_ERROR exception when there are 
> several trailing new lines at the end of the text:
> 
> % test_20230922_get_char
> with Ada.Text_IO; use Ada.Text_IO;procedure test_20230922_get_char is 
> procedure Get is      F : File_Type;      Ch : Character;   begin Open 
> (F, In_File, "test_20230922_get_char.adb");      while not 
> End_Of_File(F) loop         Get (F, Ch);         Put (Ch);      end 
> loop;      Close (F);      Put_Line ("File read with get."); 
> end;beginGet;end;
> 
> Execution of ../bin/test_20230922_get_char terminated by unhandled 
> exception
> raised ADA.IO_EXCEPTIONS.END_ERROR : a-textio.adb:517
> 
> The code is compiled with GNAT, does it comply with the standard?
> 
> A.10.7 Input-Output of Characters and Strings
> For an item of type Character the following procedures are provided:
> procedure Get(File : in File_Type; Item : out Character);
> procedure Get(Item : out Character);
> After skipping any line terminators and any page terminators, reads the 
> next character from the specified input file and returns the value of 
> this character in the out parameter Item.
> The exception End_Error is propagated if an attempt is made to skip a 
> file terminator.
> 
> This seems to be the case, then how to avoid the exception?


In Text_IO, a line terminator is not an ordinary character, so you must 
handle it separately, for example like this:

       while not End_Of_File(F) loop
          if End_Of_Line(F) then
             New_Line;
             Skip_Line(F);
          else
             Get (F, Ch);
             Put (Ch);
          end if;





^ permalink raw reply	[relevance 0%]

* Weird behavior of Get character with trailing new lines.
@ 2023-09-22 19:30  1% Blady
  2023-09-22 19:52  0% ` Niklas Holsti
  0 siblings, 1 reply; 200+ results
From: Blady @ 2023-09-22 19:30 UTC (permalink / raw)


Hello,

I'm reading a text file with Get character from Text_IO with a while 
loop controlled by End_Of_File.

% cat test_20230922_get_char.adb
with Ada.Text_IO; use Ada.Text_IO;
procedure test_20230922_get_char is
    procedure Get is
       F : File_Type;
       Ch : Character;
    begin
       Open (F, In_File, "test_20230922_get_char.adb");
       while not End_Of_File(F) loop
          Get (F, Ch);
          Put (Ch);
       end loop;
       Close (F);
       Put_Line ("File read with get.");
    end;
begin
Get;
end;



All will be well, unfortunately not!

Despite the End_Of_File, I got an END_ERROR exception when there are 
several trailing new lines at the end of the text:

% test_20230922_get_char
with Ada.Text_IO; use Ada.Text_IO;procedure test_20230922_get_char is 
procedure Get is      F : File_Type;      Ch : Character;   begin 
Open (F, In_File, "test_20230922_get_char.adb");      while not 
End_Of_File(F) loop         Get (F, Ch);         Put (Ch);      end 
loop;      Close (F);      Put_Line ("File read with get."); 
end;beginGet;end;

Execution of ../bin/test_20230922_get_char terminated by unhandled exception
raised ADA.IO_EXCEPTIONS.END_ERROR : a-textio.adb:517

The code is compiled with GNAT, does it comply with the standard?

A.10.7 Input-Output of Characters and Strings
For an item of type Character the following procedures are provided:
procedure Get(File : in File_Type; Item : out Character);
procedure Get(Item : out Character);
After skipping any line terminators and any page terminators, reads the 
next character from the specified input file and returns the value of 
this character in the out parameter Item.
The exception End_Error is propagated if an attempt is made to skip a 
file terminator.

This seems to be the case, then how to avoid the exception?

Thanks, Pascal.



^ permalink raw reply	[relevance 1%]

* Re: Aggregate with derived types.
  2023-09-14 15:31  0% ` Jeffrey R.Carter
@ 2023-09-14 20:00  0%   ` Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2023-09-14 20:00 UTC (permalink / raw)


Le 14/09/2023 à 17:31, Jeffrey R.Carter a écrit :
> On 2023-09-14 16:02, Blady wrote:
>>
>>       1. with Ada.Containers.Vectors;
>>       2. with Ada.Text_IO;
>>       3. procedure test_20230914_derived_agg is
>>       4.    package My_Float_Lists is new Ada.Containers.Vectors 
>> (Positive, Float);
>>       5.    subtype My_Float_List1 is My_Float_Lists.Vector;
>>       6.    type My_Float_List2 is new My_Float_Lists.Vector with null 
>> record;
>>       7.    ML1 : My_Float_List1 := [-3.1, -6.7, 3.3, -3.14, 0.0];
>>       8.    ML2 : My_Float_List2 := ([-3.1, -6.7, 3.3, -3.14, 0.0] 
>> with null record);
>>                                      |
>>          >>> error: no unique type for this aggregate
> 
> IIUC, you have to qualify the value:
> 
> (My_Float_List1'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)
> 
> or
> 
> (My_Float_Lists.Vector'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)
> 
> (not tested)

Thanks Jeff, both proposals are compiled ok by GNAT.

I wonder why the float list aggregate isn't inferred by the compiler and 
need some help with a qualification.

^ permalink raw reply	[relevance 0%]

* Re: Aggregate with derived types.
  2023-09-14 14:02  1% Aggregate with derived types Blady
@ 2023-09-14 15:31  0% ` Jeffrey R.Carter
  2023-09-14 20:00  0%   ` Blady
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-09-14 15:31 UTC (permalink / raw)


On 2023-09-14 16:02, Blady wrote:
> 
>       1. with Ada.Containers.Vectors;
>       2. with Ada.Text_IO;
>       3. procedure test_20230914_derived_agg is
>       4.    package My_Float_Lists is new Ada.Containers.Vectors (Positive, Float);
>       5.    subtype My_Float_List1 is My_Float_Lists.Vector;
>       6.    type My_Float_List2 is new My_Float_Lists.Vector with null record;
>       7.    ML1 : My_Float_List1 := [-3.1, -6.7, 3.3, -3.14, 0.0];
>       8.    ML2 : My_Float_List2 := ([-3.1, -6.7, 3.3, -3.14, 0.0] with null 
> record);
>                                      |
>          >>> error: no unique type for this aggregate

IIUC, you have to qualify the value:

(My_Float_List1'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)

or

(My_Float_Lists.Vector'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)

(not tested)

-- 
Jeff Carter
"[M]any were collected near them, ... to
enjoy the sight of a dead young lady, nay,
two dead young ladies, for it proved twice
as fine as the first report."
Persuasion
155

^ permalink raw reply	[relevance 0%]

* Aggregate with derived types.
@ 2023-09-14 14:02  1% Blady
  2023-09-14 15:31  0% ` Jeffrey R.Carter
  0 siblings, 1 reply; 200+ results
From: Blady @ 2023-09-14 14:02 UTC (permalink / raw)


Hello,

I want to extend a container type like Vectors, I've written:
   type My_Float_List2 is new My_Float_Lists.Vector with null record;

But the initialization gives an error line 6:

      1. with Ada.Containers.Vectors;
      2. with Ada.Text_IO;
      3. procedure test_20230914_derived_agg is
      4.    package My_Float_Lists is new Ada.Containers.Vectors 
(Positive, Float);
      5.    subtype My_Float_List1 is My_Float_Lists.Vector;
      6.    type My_Float_List2 is new My_Float_Lists.Vector with null 
record;
      7.    ML1 : My_Float_List1 := [-3.1, -6.7, 3.3, -3.14, 0.0];
      8.    ML2 : My_Float_List2 := ([-3.1, -6.7, 3.3, -3.14, 0.0] with 
null record);
                                     |
         >>> error: no unique type for this aggregate
      9. begin
     10.    Ada.Text_IO.Put_Line (ML1.Element (3)'Image);
     11.    Ada.Text_IO.Put_Line (ML2.Element (3)'Image);
     12. end test_20230914_derived_agg;

The RM says:
4.3.2 Extension Aggregates
1   [An extension_aggregate specifies a value for a type that is a record
extension by specifying a value or subtype for an ancestor of the type,
followed by associations for any components not determined by the
ancestor_part.]
                          Language Design Principles
1.a         The model underlying this syntax is that a record extension can
             also be viewed as a regular record type with an ancestor 
"prefix".
             The record_component_association_list corresponds to 
exactly what
             would be needed if there were no ancestor/prefix type. The
             ancestor_part determines the value of the ancestor/prefix.
                                    Syntax
2       extension_aggregate ::=
             (ancestor_part with record_component_association_list)
3       ancestor_part ::= expression | subtype_mark

It is not so clear for me what could a unique type?
Any clue?

Thanks Pascal.


^ permalink raw reply	[relevance 1%]

* Re: project euler 26
  2023-09-05  7:23  0%               ` Dmitry A. Kazakov
  2023-09-05 15:18  0%                 ` Ben Bacarisse
@ 2023-09-05 17:35  0%                 ` moi
  1 sibling, 0 replies; 200+ results
From: moi @ 2023-09-05 17:35 UTC (permalink / raw)


On 05/09/2023 08:23, Dmitry A. Kazakov wrote:
> On 2023-09-05 01:16, Ben Bacarisse wrote:
> 
>> The term "abstraction" is usually taken to be more general than that so
>> as to include function (or procedural) abstraction.
> 
> These are means of software decomposition rather than abstraction (of 
> something).

They are both of these things, actually.

>
>> Ada is good at that, but the syntax is sufficiently cumbersome that I
>> think it discourages people from exploiting that part of the language.
>> Mind you, I am no Ada expert so maybe it's simpler to do than I think.
> 
> If the program does not resemble electric transmission noise, some 
> people call the language syntax cumbersome... (:-))

8-)

>> Here's my Ada solution:
>>
>> with Ada.Text_IO; use Ada.Text_IO;
>> with Ada.Containers.Ordered_Maps; use Ada.Containers;
>>
>> procedure Euler_26 is
>>
>>     function Period(Divisor: Positive) return Positive is
> 
> You cannot use a number here because the period may have leading zeros.
> 
>> I know it won't make this program shorter, but it would be interesting
>> to know how it might be done.
> 
> The goal of engineering is not making programs shorter, it is to make 
> them understandable, safer, reusable, maintainable, extensible, integrable.

Hear, hear!

Functionalists do seem to have an obsession with brevity at all costs.
It's very strange.

-- 
Bill F.

^ permalink raw reply	[relevance 0%]

* Re: project euler 26
  2023-09-05  7:23  0%               ` Dmitry A. Kazakov
@ 2023-09-05 15:18  0%                 ` Ben Bacarisse
  2023-09-05 17:35  0%                 ` moi
  1 sibling, 0 replies; 200+ results
From: Ben Bacarisse @ 2023-09-05 15:18 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2023-09-05 01:16, Ben Bacarisse wrote:
>
>> The term "abstraction" is usually taken to be more general than that so
>> as to include function (or procedural) abstraction.
>
> These are means of software decomposition rather than abstraction (of
> something).

That's not how the word is usually used.  Obviously I can't (and don't
want to) change your mind, but algorithms can be abstracted as well as
data.

I was hoping someone could how me how in for the example program I gave
since that's an area of Ada I am not familiar with (but I's sure it's
possible).

>> Ada is good at that, but the syntax is sufficiently cumbersome that I
>> think it discourages people from exploiting that part of the language.
>> Mind you, I am no Ada expert so maybe it's simpler to do than I think.
>
> If the program does not resemble electric transmission noise, some people
> call the language syntax cumbersome... (:-))

That's true.  But there are also constructs that are genuinely
cumbersome in some languages.  Anyway, to find out more, I was hoping
someone would show me what it looks like in Ada -- I outlined what I
wanted to do after the code I posted.

>> Here's my Ada solution:
>> with Ada.Text_IO; use Ada.Text_IO;
>> with Ada.Containers.Ordered_Maps; use Ada.Containers;
>> procedure Euler_26 is
>>     function Period(Divisor: Positive) return Positive is
>
> You cannot use a number here because the period may have leading
> zeros.

The function returns the decimal period of 1/Divisor.  I don't believe
there is a bug, but if you think you've found one, I'd like to know
about it.

Of course there can be leading zeros, but my algorithm ignores the
digits and determines the period using the "carry" instead.

>> I know it won't make this program shorter, but it would be interesting
>> to know how it might be done.
>
> The goal of engineering is not making programs shorter, it is to make them
> understandable, safer, reusable, maintainable, extensible, integrable.

Yes.  That's exactly why I was asking for someone who knows Ada better
to show me how to write the reusable component I described.  There was
boiler plate code in my program that could be abstracted out into a
generic function (or package?) so that any function can be maximised
over some range or, better yet, any iterable type (if that's how Ada
does things).

Can someone here show me how?

-- 
Ben.

^ permalink raw reply	[relevance 0%]

* Re: project euler 26
  2023-09-04 23:16  1%             ` Ben Bacarisse
@ 2023-09-05  7:23  0%               ` Dmitry A. Kazakov
  2023-09-05 15:18  0%                 ` Ben Bacarisse
  2023-09-05 17:35  0%                 ` moi
  0 siblings, 2 replies; 200+ results
From: Dmitry A. Kazakov @ 2023-09-05  7:23 UTC (permalink / raw)


On 2023-09-05 01:16, Ben Bacarisse wrote:

> The term "abstraction" is usually taken to be more general than that so
> as to include function (or procedural) abstraction.

These are means of software decomposition rather than abstraction (of 
something).

> Ada is good at that, but the syntax is sufficiently cumbersome that I
> think it discourages people from exploiting that part of the language.
> Mind you, I am no Ada expert so maybe it's simpler to do than I think.

If the program does not resemble electric transmission noise, some 
people call the language syntax cumbersome... (:-))

> Here's my Ada solution:
> 
> with Ada.Text_IO; use Ada.Text_IO;
> with Ada.Containers.Ordered_Maps; use Ada.Containers;
> 
> procedure Euler_26 is
> 
>     function Period(Divisor: Positive) return Positive is

You cannot use a number here because the period may have leading zeros.

> I know it won't make this program shorter, but it would be interesting
> to know how it might be done.

The goal of engineering is not making programs shorter, it is to make 
them understandable, safer, reusable, maintainable, extensible, integrable.

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

^ permalink raw reply	[relevance 0%]

* Re: project euler 26
  @ 2023-09-04 23:16  1%             ` Ben Bacarisse
  2023-09-05  7:23  0%               ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Ben Bacarisse @ 2023-09-04 23:16 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2023-09-04 22:18, Ben Bacarisse wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> 
>>> On 2023-09-04 18:01, Ben Bacarisse wrote:
>>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>>>
>>>>> BTW, Ada is perfect for numeric algorithms no need to resort to functional
>>>>> mess... (:-))
>>>> Perfect?  That's a bold claim!
>>>
>>> Ada is a very improved descendant of Algol 60, which was designed to codify
>>> algorithms.
>> Yes, though I was respond to you narrower remark about being perfect for
>> numeric algorithms.
>
> Yes, Ada is.

:-)

>>> (rather than about for example building
>>> abstractions as in the case of OOP)
>>
>> That's interesting.  You don't consider using functions and procedures
>> (possibly higher-order ones) to be a way to build abstractions?
>
> No, they do not introduce new types and do not form some structure of their
> values. And "using" is not an abstraction anyway.

The term "abstraction" is usually taken to be more general than that so
as to include function (or procedural) abstraction.

Ada is good at that, but the syntax is sufficiently cumbersome that I
think it discourages people from exploiting that part of the language.
Mind you, I am no Ada expert so maybe it's simpler to do than I think.

Here's my Ada solution:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Ordered_Maps; use Ada.Containers;

procedure Euler_26 is

   function Period(Divisor: Positive) return Positive is
      Index: Natural := 0;
      Carry: Natural := 1;

      package Carry_Maps is new Ordered_Maps(Natural, Natural);
      use Carry_Maps;
      Carries: Map;
      Loc: Cursor;
   begin
      loop
          Loc := Carries.Find(Carry);
          exit when Loc /= No_Element;
          Carries.Insert(Carry, Index);
          Index := Index + 1;
          Carry := Carry mod Divisor * 10;
      end loop;
      return Index - Element(Loc);
   end Period;

   Max_Period: Natural := 1;
   Divisor_With_Max_Period: Natural := 1;
begin
   for D in 2..999 loop
      declare Ds_Period: constant Positive := Period(D);
      begin
         if Ds_Period > Max_Period
         then
            Divisor_With_Max_Period := D;
            Max_Period := Ds_Period;
         end if;
      end;
   end loop;
   Put_Line(Integer'Image(Divisor_With_Max_Period));
end Euler_26;

The part that finds the D that maximises Period(D) is just boilerplate
code.  I know this can be abstracted out in Ada, but I think the syntax
is messy.  I was hoping to find (or be able to write) a generic function
that takes an 'iterable' (if that's the right word) and a function, and
which returns the element that maximises the function.  I got stuck
trying.  Maybe someone can help?

I know it won't make this program shorter, but it would be interesting
to know how it might be done.

-- 
Ben.

^ permalink raw reply	[relevance 1%]

* Re: project euler 26
    @ 2023-09-04 14:23  1% ` Dmitry A. Kazakov
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2023-09-04 14:23 UTC (permalink / raw)


On 2023-09-04 11:19, CSYH (QAQ) wrote:
> I am new to Ada, I know is there a good way to start this program?
> thanks
> https://projecteuler.net/problem=26

Ok, I leave it to you checking if my implementation is correct.
-------------------test.adb----------
with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test is

    N : constant := 1000;

    function Period (Divisor : Positive) return String is
       type Remainder is record
          Index : Positive;
          Value : Positive;
       end record;
       Result     : String (1..N);
       Value      : Integer := 1;
       Remainders : array (1..N) of Remainder;
    begin
       for Index in Result'Range loop
          Value  := Value * 10;
          Result (Index) :=
             Character'Val (Character'Pos ('0') + Value / Divisor);
          Value := Value mod Divisor;
          if Value = 0 then
             return ""; -- Non-periodic
          end if;
          if Index > 1 then
             for Item in 1..Index - 1 loop
                declare
                   This : Remainder renames Remainders (Item);
                begin
                   if Value = This.Value then
                      return Result (This.Index + 1..Index);
                   end if;
                end;
             end loop;
          end if;
          Remainders (Index) := (Index, Value);
       end loop;
       raise Constraint_Error with "Period calculation error";
    end Period;

    Max_Period  : Unbounded_String;
    Max_Divisor : Positive;
begin
    for Divisor in 2..999 loop
       declare
          This : constant String := Period (Divisor);
       begin
          if This /= "" then
             Put_Line
             (  "1 /"
             &  Integer'Image (Divisor)
             &  " has "
             &  This
             &  " in period"
             );
          end if;
          if Length (Max_Period) < This'Length then
             Max_Period  := To_Unbounded_String (This);
             Max_Divisor := Divisor;
          end if;
       end;
    end loop;
    Put_Line
    (  "The first longest period is "
    &  To_String (Max_Period)
    &  " in 1 /"
    &  Integer'Image (Max_Divisor)
    );
end Test;
-------------------test.adb----------
It gives the longest period for 1/983.

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

^ permalink raw reply	[relevance 1%]

* Re: Parameterised 'Image Attributes
  @ 2023-08-28 19:08  1%                                     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2023-08-28 19:08 UTC (permalink / raw)


On 2023-08-28 19:33, G.B. wrote:
> On 28.08.23 18:09, Dmitry A. Kazakov wrote:
>> On 2023-08-28 17:42, Stephen Davies wrote:
>>> On Monday, 28 August 2023 at 11:58:24 UTC+1, Dmitry A. Kazakov wrote:
>>>> On 2023-08-28 11:18, Stephen Davies wrote:
>>>> This will not happen either. But here I would agree, it is clearly a
>>>> case of language littering.
>>>
>>> Littering, schmittering, how about adding Bin_Image, Oct_Image & 
>>> Hex_Image
>>> for Ints and Dec_Image for Ints & Reals ;-)
>>
>> Bin_Width_1_Image, Dec_Width_4_Image and so on... Cool, make Ada C 
>> again! (:-))
> 
> Or maybe leave type attributes alone. Instead, let Ada.Streams
> have I/O manipulating setters.
> 
> Then,  in order to preserve the meaning of "corresponding S'Output"
> (LRM 13.13.2) for every S'Input, add AI to the Ada run-time system.

I like the idea of unification of serialization and formatting.

However it does not solve the problem of parameters. In GUI frameworks 
facing this very problem the parameters for rendering are set into the 
graphic context/surface.

E.g. in the case of string formatting you would need a global object to 
set the parameters into. E.g. a set of procedures like 
Ada.Text_IO.Set_Field_Width, Ada.Text_IO.Set_Integer_Base etc. That 
would be incredibly boring and unsafe.

For stream serialization the parameters could be set on the stream 
itself. Which might break a lot of code if you added them to 
Root_Stream_Type.

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

^ permalink raw reply	[relevance 1%]

* Re: Unifont static compiled and stack size...
  2023-08-14 10:06  1% ` Jeffrey R.Carter
@ 2023-08-14 15:10  1%   ` Micah Waddoups
  0 siblings, 0 replies; 200+ results
From: Micah Waddoups @ 2023-08-14 15:10 UTC (permalink / raw)


On Monday, August 14, 2023 at 4:06:39 AM UTC-6, Jeffrey R.Carter wrote:
> On 2023-08-13 18:16, Micah Waddoups wrote: 
> > I tried to compile the Unifont hex file, converted with a script into variable Ada code, but it went on forever, gradually blowing up my memory. I used an .ads file and aimed for a static build, but I suspect I would have hit the stack size limit for executables if I succeeded
> As I understand it, the file in question is for code points 0 .. 16#FFFF#, with 
> a maximum of 32 bytes per code point. A straightforward representation of this is 
> 
> package Unifont is 
> type Byte is mod 2 ** 8 with Size => 8; 
> 
> type Line is array (1 .. 2) of Byte with Size => 16; 
> 
> type Bitmap is array (1 .. 16) of Line with Size => 256; 
> 
> function Width_8 (Map : in Bitmap) return Boolean is 
> (for all L of Map => L (2) = 0); 
> 
> type Code_Point is mod 16#FFFF# + 1; 
> 
> type Font_Map is array (Code_Point) of Bitmap with Size => 2 ** 24; 
> 
> Font : constant Font_Map := (others => (others => (others => 0) ) ); 
> end Unifont; 
> 
> Font will occupy 2 MB. 
> 
> We can test this with 
> 
> with Ada.Text_IO; 
> with Unifont; 
> 
> procedure Unifont_Test is 
> -- Empty 
> begin -- Unifont_Test 
> Ada.Text_IO.Put_Line (Item => Unifont.Font (0) (1) (1)'Image); 
> end Unifont_Test; 
> 
> and see what happens: 
> 
> $ gnatmake -m -j0 -gnat12 -gnatan -gnato2 -O2 -fstack-check unifont_test.adb 
> x86_64-linux-gnu-gcc-12 -c -gnat12 -gnatan -gnato2 -O2 -fstack-check 
> unifont_test.adb 
> x86_64-linux-gnu-gcc-12 -c -gnat12 -gnatan -gnato2 -O2 -fstack-check unifont.ads 
> x86_64-linux-gnu-gnatbind-12 -x unifont_test.ali 
> x86_64-linux-gnu-gnatlink-12 unifont_test.ali -O2 -fstack-check 
> $ ./unifont_test 
> 0 
> 
> so this representation seems to be workable. It should be trivial to write a 
> program to read the file and produce the real array aggregate for Font. 
> 
> -- 
> Jeff Carter 
> "I wave my private parts at your aunties." 
> Monty Python & the Holy Grail 
> 13

Thank you all for replying while I was working away from home.  

Jeff, you missed a digit - it's five F's  16#FFFFF# because that is as high as Unifont goes in my copy of the hex file.  Of course the technique should be able to go higher if that changes, but Unicode is pretty exhaustive as it is and Unifont is meant to keep up with every version and addition to the Unicode code points, so I sincerely hope for no trouble for a while yet.  I checked, and it seem my system has about 8 megabytes as the stack size limit, so with the ranges left empty it is not 32 megabytes, but still pretty big.  Good looking code, by the way.  Very easy to read.  Mine is appended, but it was really a quick hack of a job with too little sleep.  I probably should have done a Z Shell script (maybe take 20 seconds?), but I thought the two second efficiency of writing a compiled composer was worth it ...somehow...

Niklas, I think you have the most actionable suggestions for me to test.  Thank you.

Dmitry, Thank you for trying to understand.  Since both methods of rendering fonts made available by GTK, I consider it GTK providing it.  I don't want any more imports than I can provide easily with a static compile or as accompanying dynamic modules (reason hereafter mentioned), and Licensing needs to be the most permissive possible.  The idea is to be able to create a shell or a variety of other programs using my library as a very focused kind of interface that supports more characters and more languages that my other most available options, so the font is important, even if I'm just drawing to the Linux frame buffer.  I meant a transfer of code from one platform to another.  Sometimes in a graphical window that acts like a text interface window, sometimes on the linux frame buffer, and in the extreme case some times on the text console without any particular font support.  The main collection of code is supposed to support all that with very limited modification  to say transfer from Linux to macOS or MS Windows?  I hope this s answered your questions.

Oh, and to all, I have already abandon the idea of using Boolean with Pack, since it no longer seems to work and was a bit *too* verbose

pragma Ada_2012;
pragma Wide_Character_Encoding (UTF8);


with Ada.Text_IO;
use Ada.Text_IO;


procedure Unifont_Hex_To_Ada is


   Target_Name: String := "./src/unifont.ads";
   Source_Name: String := "unifont_all-15.0.06.hex";
   Target: aliased File_Type;
   Source: aliased File_Type;
   Buffer: aliased String (1 .. 96) := (others=>' ');
   Index, F: Positive := 1;
   Previous, Current, Length, L: Natural := 0;
   Finished: aliased Boolean:= False;
   subtype Hex_Character is Character range '0' .. 'f'
     with Static_Predicate=> (Hex_Character in '0' .. '9') or (Hex_Character in 'A' .. 'F') or (Hex_Character in 'a' .. 'f');
   type Byte is mod 2 **8;
   type Bit is mod 8;
   --type Bytes is array (Natural range <>) of aliased Byte;
   Bit_X: Bit := 0;
   Byte_X: Byte := 0;
   function Find (Item: Character)
                  return Natural
   is
   begin
      for
        N in Buffer'Range
      loop
         if Item = Buffer(N)
         then return N;
         end if;
      end loop;
      return 0;
   end Find;
   function Enum return Natural
   is
      First: Positive := 1;
      Last: Natural := Integer'Max ((Find (':') -1), 0);
   begin
      return R: Natural
      do
         R := Natural'Value ("16#" &Buffer (First..Last) &'#');
      end return;
   end Enum;
   procedure Next_Byte
   is
      S: String renames Buffer (F .. L);
   begin
      loop
         if
           (Index in S'Range) and (Index +1 in S'Range)
         then
            exit;
         else
            Index := S'First;
            if
              (Index in S'Range) and (Index +1 in S'Range)
            then
               exit;
            else
               raise Program_Error with "Next_Byte-> Somehow there are no Hex codes in string... line " &Current'Img &", string => " & S;
            end if;
         end if;
      end loop;
      if
        S (Index) in Hex_Character
        and
          S (Index +1) in Hex_Character
      then
         Byte_X := Byte'Value ("16#" &S (Index..Index +1) &"#");
         Bit_X := 0;
         Index := Index +2;
      end if;
   end Next_Byte;
   procedure Next_Line
   is
   begin
      for
        N in Buffer'First .. Length
      loop
         Buffer (N):= ' ';
      end loop;
      begin
         Get_Line (Source, Buffer, Length);
      exception
         when others => null;
      end;
      if
        Length < 32
      then
         Put_Line (Standard_Error, "empty or incomplete line at code point " &Natural'Image (Enum) &" (" &Current'Img &" + 1)");
      else
         Previous:= Current;
         Current:= Enum;
         if
           ((Previous + 1) = Current)
           or else (Current = 0)
         then
            F:= Find (':') +1;
            L:= Length;
            Next_Byte;
         else
            F:= Find (':') +1;
            L:= Length;
            Next_Byte;
            Put_Line (Standard_Error, " Missing character range in Source: " &Previous'Img &" .. " &Current'Img);
         end if;
      end if;
   end Next_Line;


   subtype Index_Type is Natural range 0 .. 16#FFFFF#;
   subtype Y_Type is Integer range 1 .. 16;
   subtype X_Type is Integer range 1 .. 16;
   type Size_Type is
      record
         Y: aliased Y_Type:= Y_Type'First;
         X: aliased X_Type:= X_Type'First;
      end record;
   type Size_Set_Type is array (Index_Type) of aliased Size_Type;
   type Size_Set_Access is access all Size_Set_Type;
   function Dot return String is
   begin
      if
        1 = ((Byte_X / 2 **(7 - Natural(Bit_X))) and 1)
      then
         if
           Bit_X = Bit'Last
         then
            Next_Byte;
         else
            Bit_X := Bit_X +1;
         end if;
         return "True";
      else
         if
           Bit_X = Bit'Last
         then
            Next_Byte;
         else
            Bit_X := Bit_X +1;
         end if;
         return "False";
      end if;
   end Dot;
   Cache_Size: Size_Set_Access := new Size_Set_Type'(others => (16, 8));
   Size: Size_Set_Type renames Cache_Size.all;

begin

   begin
      Open (Source, In_File, Source_Name);
   exception
      when others =>
         raise Status_Error with " Source File not found: " &Source_Name;
   end;

   begin
      Create (Target, Out_File, Target_Name);
   exception
      when others =>
         Open (Target, Out_File, Target_Name);
   end;


   begin
      Put_Line (Target, "pragma Ada_2012;");
      Put_Line (Target, "pragma Wide_Character_Encoding (UTF8);");
      New_Line (Target, 2);
      --Put_Line (Target, "with ada.unchecked_conversion;");
      --New_Line (Target, 2);
      Put_Line (Target, "package Unifont is");
      Put_Line (Target, "subtype Index_Type is Wide_Wide_Character range Wide_Wide_Character'Val (0) .. Wide_Wide_Character'Val (16#FFFFF#);");
      Put_Line (Target, "subtype Y_Type is Integer range 1 .. 16;");
      Put_Line (Target, "subtype X_Type is Integer range 1 .. 16;");
      Put_Line (Target, "type Size_Type is record Y: aliased Y_Type := 1; X: aliased X_Type := 1; end record;");
      Put_Line (Target, "type Size_Set_Type is array (Index_Type) of aliased Size_Type;");
      Put_Line (Target, "type Glyph_Type is array (Y_Type, X_Type) of Boolean");
      Put_Line (Target, "with Pack, Size=> 256;");
      Put_Line (Target, "type Glyph_Set_Type is array (Index_Type) of aliased Glyph_Type;");
      Put_Line (Target, "Glyph: constant Glyph_Set_Type :=");
      Put (Target, "(");
      loop
         exit when End_Of_File (Source);
         Next_Line; -- Load Next Line and extract Code Point index
         if
           Length > 64
         then
            Size (Current) := (16, 16);
            Put_Line (Target, "Wide_Wide_Character'Val (" &Integer'Image(Current) &") =>");
            Put (Target, "(");
            for Y in 1 .. 16
            loop
               Put_Line (Target, Y'Img &" =>");
               Put (Target, "(");
               for X in 1 .. 16
               loop
                  if
                    X < 16
                  then
                     Put (Target, Dot &", ");
                  else
                     Put (Target, Dot &")");
                  end if;
               end loop;
               if
                 Y < 16
               then
                  Put_Line (Target, ",");
               else
                  Put_Line (Target, "),");
               end if;
            end loop;
         elsif
           Length > 32
         then
            Put_Line (Target, "Wide_Wide_Character'Val (" &Integer'Image(Current) &") =>");
            Put (Target, "(");
            for Y in 1 .. 16
            loop
               Put_Line (Target, Y'Img &" =>");
               Put (Target, "(");
               for X in 1 .. 8
               loop
                  Put (Target, Dot &", ");
               end loop;
               for X in 9 .. 16
               loop
                  if
                    X < 16
                  then
                     Put (Target, "False, ");
                  else
                     Put (Target, "False)");
                  end if;
               end loop;
               if
                 Y < 16
               then
                  Put_Line (Target, ",");
               else
                  Put_Line (Target, "),");
               end if;
            end loop;
         end if;
      end loop;
      Close (Source);
      Put_Line (Target, "others => (others => (others => False)));");
      New_Line (Target);
      Put_Line (Target, "Size: constant Size_Set_Type :=");
      Put (Target, "(");
      for N in Index_Type'Range
      loop
         Put (Target, "Wide_Wide_Character'Val (" &Integer'Image(N) &") =>");
         Put (Target, "(" &Integer'Image(Size(N).Y) &", " &Integer'Image(Size(N).X) &")");
         if
           N < Index_Type'Last
         then
            Put_Line (Target, ",");
         else
            Put_Line (Target, ");");
         end if;
      end loop;
      Put_Line (Target, "end Unifont;");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Put_Line (Target, "");
      Close (Target);
   end;
end Unifont_Hex_To_Ada;

^ permalink raw reply	[relevance 1%]

* Re: Unifont static compiled and stack size...
  @ 2023-08-14 10:06  1% ` Jeffrey R.Carter
  2023-08-14 15:10  1%   ` Micah Waddoups
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-08-14 10:06 UTC (permalink / raw)


On 2023-08-13 18:16, Micah Waddoups wrote:
> I tried to compile the Unifont hex file, converted with a script into variable Ada code, but it went on forever, gradually blowing up my memory.  I used an .ads file and aimed for a static build, but I suspect I would have hit the stack size limit for executables if I succeeded

As I understand it, the file in question is for code points 0 .. 16#FFFF#, with 
a maximum of 32 bytes per code point. A straightforward representation of this is

package Unifont is
    type Byte is mod 2 ** 8 with Size => 8;

    type Line is array (1 .. 2) of Byte with Size => 16;

    type Bitmap is array (1 .. 16) of Line with Size => 256;

    function Width_8 (Map : in Bitmap) return Boolean is
       (for all L of Map => L (2) = 0);

    type Code_Point is mod 16#FFFF# + 1;

    type Font_Map is array (Code_Point) of Bitmap with Size => 2 ** 24;

    Font : constant Font_Map := (others => (others => (others => 0) ) );
end Unifont;

Font will occupy 2 MB.

We can test this with

with Ada.Text_IO;
with Unifont;

procedure Unifont_Test is
    -- Empty
begin -- Unifont_Test
    Ada.Text_IO.Put_Line (Item => Unifont.Font (0) (1) (1)'Image);
end Unifont_Test;

and see what happens:

$ gnatmake -m -j0 -gnat12 -gnatan -gnato2 -O2 -fstack-check unifont_test.adb
x86_64-linux-gnu-gcc-12 -c -gnat12 -gnatan -gnato2 -O2 -fstack-check 
unifont_test.adb
x86_64-linux-gnu-gcc-12 -c -gnat12 -gnatan -gnato2 -O2 -fstack-check unifont.ads
x86_64-linux-gnu-gnatbind-12 -x unifont_test.ali
x86_64-linux-gnu-gnatlink-12 unifont_test.ali -O2 -fstack-check
$ ./unifont_test
  0

so this representation seems to be workable. It should be trivial to write a 
program to read the file and produce the real array aggregate for Font.

-- 
Jeff Carter
"I wave my private parts at your aunties."
Monty Python & the Holy Grail
13

^ permalink raw reply	[relevance 1%]

* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
  2023-07-29 23:53  1%           ` Kenneth Wolcott
@ 2023-07-30  4:43  1%             ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2023-07-30  4:43 UTC (permalink / raw)


'Image doesn't support any formatting, so no "Aft" or "Exp". The slicing 
isn't the problem. :-)

You can use Text_IO to write to a string if you need formatting. 'Image is 
for quick & dirty debugging, not fancy output. (Of course, if you're lucky 
and it does what you need, then feel free to use it.)

                                 Randy.

"Kenneth Wolcott" <kennethwolcott@gmail.com> wrote in message 
news:2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com...
On Saturday, July 29, 2023 at 4:49:08?PM UTC-7, Kenneth Wolcott wrote:
> On Saturday, July 29, 2023 at 4:07:17?AM UTC-7, AdaMagica wrote:
> > > Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
> > With the aspect Integer_Literal, also Powers_of_2 * 2 must work. The 
> > attributes Integer_Literal, Real_Literal, Put_Image make the new big 
> > numbers nearly work like numeric types (they are not). A difference: The 
> > range syntax for instance in loops A .. B is illegal.
> I understand that the range syntax in loops implies that the loop variable 
> is acting like an enumerated type which is not true for Big_Integers.
>
> What confused me is that I thought I had to convert the numeric literal 
> (I'll have to go back and look at the package spec again to get this 
> firmly understood.
>
> I have an another question about string slicing: I've tried (obviously 
> incorrectly) to use a variable is one of the slice integers. Can this be 
> done?
>
> Thanks,
> Ken

Apparently not :-(

gnatmake main.adb
gcc -c main.adb
main.adb:28:67: error: named parameters not permitted for attributes
     9 with Ada.Text_IO; use Ada.Text_IO;
    10 with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
    11 with Ada.Float_Text_IO; use Ada.Float_Text_IO;
    12 with Ada.Numerics.Elementary_Functions; use 
Ada.Numerics.Elementary_Functions;
    13 with Ada.Command_Line; use Ada.Command_Line;
    14
    15 procedure Main is
    16   Substr : String := Argument (1);
    17   Nth : Positive := Integer'Value (Argument (2));
    18   I, J : Natural;
    19   Temp : Float;
    20 begin
    21   I := 0;
    22   J := 0;
    23   loop
    24     I := I + 1;
    25     exit when I >= 10;
    26     Temp := 10.0 ** (log (2.0, 10.0) * Float (I));
    27     if I >= 4  then
    28       if (Float'Image (10.0 ** (log (2.0, 10.0) * Float (I)), Aft => 
0, Exp => 0) (1 .. Substr'Length) = Substr then
    29         J := J + 1;
    30         if J = Nth then
    31           Put (I, 0);
    32           New_Line;
    33           exit;
    34         end if;
    35       end if;
    36     end if;
    37   end loop;
    38 end Main;

Thanks,
Ken 


^ permalink raw reply	[relevance 1%]

* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
  @ 2023-07-29 23:53  1%           ` Kenneth Wolcott
  2023-07-30  4:43  1%             ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Kenneth Wolcott @ 2023-07-29 23:53 UTC (permalink / raw)


On Saturday, July 29, 2023 at 4:49:08 PM UTC-7, Kenneth Wolcott wrote:
> On Saturday, July 29, 2023 at 4:07:17 AM UTC-7, AdaMagica wrote: 
> > > Powers_of_2 := Powers_of_2 * To_Big_Integer (2); 
> > With the aspect Integer_Literal, also Powers_of_2 * 2 must work. The attributes Integer_Literal, Real_Literal, Put_Image make the new big numbers nearly work like numeric types (they are not). A difference: The range syntax for instance in loops A .. B is illegal.
> I understand that the range syntax in loops implies that the loop variable is acting like an enumerated type which is not true for Big_Integers. 
> 
> What confused me is that I thought I had to convert the numeric literal (I'll have to go back and look at the package spec again to get this firmly understood. 
> 
> I have an another question about string slicing: I've tried (obviously incorrectly) to use a variable is one of the slice integers. Can this be done? 
> 
> Thanks, 
> Ken

Apparently not :-(

gnatmake main.adb
gcc -c main.adb
main.adb:28:67: error: named parameters not permitted for attributes
     9	with Ada.Text_IO; use Ada.Text_IO;
    10	with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
    11	with Ada.Float_Text_IO; use Ada.Float_Text_IO;
    12	with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
    13	with Ada.Command_Line; use Ada.Command_Line;
    14
    15	procedure Main is
    16	  Substr : String := Argument (1);
    17	  Nth : Positive := Integer'Value (Argument (2));
    18	  I, J : Natural;
    19	  Temp : Float;
    20	begin
    21	  I := 0;
    22	  J := 0;
    23	  loop
    24	    I := I + 1;
    25	    exit when I >= 10;
    26	    Temp := 10.0 ** (log (2.0, 10.0) * Float (I));
    27	    if I >= 4  then
    28	      if (Float'Image (10.0 ** (log (2.0, 10.0) * Float (I)), Aft => 0, Exp => 0) (1 .. Substr'Length) = Substr then
    29	        J := J + 1;
    30	        if J = Nth then
    31	          Put (I, 0);
    32	          New_Line;
    33	          exit;
    34	        end if;
    35	      end if;
    36	    end if;
    37	  end loop;
    38	end Main;

Thanks,
Ken

^ permalink raw reply	[relevance 1%]

* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
  2023-07-27  8:53  1% ` Jeffrey R.Carter
@ 2023-07-27 22:47  1%   ` Kenneth Wolcott
    0 siblings, 1 reply; 200+ results
From: Kenneth Wolcott @ 2023-07-27 22:47 UTC (permalink / raw)


On Thursday, July 27, 2023 at 1:53:38 AM UTC-7, Jeffrey R.Carter wrote:
> On 2023-07-27 07:26, Kenneth Wolcott wrote: 
> > 
> > When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced? 
> > 
> > I'd like to slice out the first two digits from the output of the To_String function of Ada.Big_Numbers.Big_Integers. 
> > 
> > When trying to do the usual string slicing on the output I get a silent failure, it is just as if I typed the null statement.
> It would be helpful if you could show what you're doing and what results you 
> get. This 
> 
> with Ada.Numerics.Discrete_Random; 
> with Ada.Text_IO; 
> 
> procedure Func_Slice is 
> subtype Digit is Character range '0' .. '9'; 
> 
> package Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Digit); 
> 
> Gen : Random.Generator; 
> 
> function Image (N : in Natural) return String is 
> (if N = 0 then "" else Random.Random (Gen) & Image (N - 1) ); 
> -- Returns a string of N random Digits 
> begin -- Func_Slice 
> Random.Reset (Gen => Gen); 
> Ada.Text_IO.Put_Line (Item => Image (10) (1 .. 2) ); 
> end Func_Slice; 
> 
> works as expected 
> 
> $ gnatmake -m -j0 -gnat12 -gnatan -gnato2 -O2 -fstack-check func_slice.adb 
> x86_64-linux-gnu-gcc-12 -c -gnat12 -gnatan -gnato2 -O2 -fstack-check func_slice.adb 
> x86_64-linux-gnu-gnatbind-12 -x func_slice.ali 
> x86_64-linux-gnu-gnatlink-12 func_slice.ali -O2 -fstack-check 
> $ ./func_slice 
> 10 
> $ ./func_slice 
> 51 

Hi Jeff;

  After going back and exhaustively reviewing the AdaCore Learning Introduction sections on Strings and Arrays, I determined that I was not slicing with the correct syntax for what I wanted to obtain, it seems that I was slicing built-in whitespace, not the digits I was looking for.  So I am now extracting the two-digit slice using (2 .. 3) rather than (1 .. 2) and I am now obtaining the desired output.  What I was trying to do was to obtain the slice from the string on the fly, not first saving the string to a variable.

This is what I have now (which works great):
---------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Numerics.Big_Numbers.Big_Integers; use Ada.Numerics.Big_Numbers.Big_Integers;

procedure Powers_Of_2_With_Leading_Digits_Of_12 is
  Max : Positive := Integer'Value (Argument (1));
  Powers_of_2 : Big_Positive := 1;
begin
  for I in 1 .. Max loop
    Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
    if I >= 4 then
      declare
        Powers_of_2_in_String_Format : String := To_String (Powers_of_2);
        First_Pair_of_String_Digits : String := Powers_of_2_in_String_Format (2 .. 3);
      begin
        if First_Pair_of_String_Digits = "12" then
          Put ("2^");
          Put (I, 0);
          Put_Line (To_String (Powers_of_2));
        end if;
      end; -- declare
    end if;
  end loop;
end Powers_Of_2_With_Leading_Digits_Of_12;
---------------------------------------------------------------------------

Now I can generalize this to more closely match the task requirements.

I think I tried to incorrectly create the slice from the To_String output directly without creating the variable in which to store the slice, which then requires the declare block.

Thanks,
Ken

^ permalink raw reply	[relevance 1%]

* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
  @ 2023-07-27  8:53  1% ` Jeffrey R.Carter
  2023-07-27 22:47  1%   ` Kenneth Wolcott
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-07-27  8:53 UTC (permalink / raw)


On 2023-07-27 07:26, Kenneth Wolcott wrote:
> 
> When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
> 
>    I'd like to slice out the first two digits from the output of the To_String function of Ada.Big_Numbers.Big_Integers.
> 
>    When trying to do the usual string slicing on the output I get a silent failure, it is just as if I typed the  null statement.

It would be helpful if you could show what you're doing and what results you 
get. This

with Ada.Numerics.Discrete_Random;
with Ada.Text_IO;

procedure Func_Slice is
    subtype Digit is Character range '0' .. '9';

    package Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Digit);

    Gen : Random.Generator;

    function Image (N : in Natural) return String is
       (if N = 0 then "" else Random.Random (Gen) & Image (N - 1) );
    -- Returns a string of N random Digits
begin -- Func_Slice
    Random.Reset (Gen => Gen);
    Ada.Text_IO.Put_Line (Item => Image (10) (1 .. 2) );
end Func_Slice;

works as expected

$ gnatmake -m -j0 -gnat12 -gnatan -gnato2 -O2 -fstack-check func_slice.adb
x86_64-linux-gnu-gcc-12 -c -gnat12 -gnatan -gnato2 -O2 -fstack-check func_slice.adb
x86_64-linux-gnu-gnatbind-12 -x func_slice.ali
x86_64-linux-gnu-gnatlink-12 func_slice.ali -O2 -fstack-check
$ ./func_slice
10
$ ./func_slice
51

-- 
Jeff Carter
"I would never want to belong to any club that
would have someone like me for a member."
Annie Hall
41

^ permalink raw reply	[relevance 1%]

* Re: does a safer language mean it is slower to run?
  @ 2023-06-08  8:50  1% ` Jeffrey R.Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2023-06-08  8:50 UTC (permalink / raw)


On 2023-06-08 05:55, Nasser M. Abbasi wrote:
> 
> Some in that thread seem to argue that a safer language
> will/could be slower than otherwise.
> 
> Since Ada is known to be one of the safest languages,
> do others here feel there is any truth to this?

Equivalent programs in compiled, non-GC languages have equivalent execution 
times. Robert Dewar famously had a set of equivalent Ada and C programs that 
produced identical machine code when compiled with gcc. So this is false.

The problem is getting equivalent programs. If the safe language includes 
run-time checks, then equivalent checks must be manually added to the unsafe 
language. Ada.Text_IO is not equivalent to C's I/O facilities. And so on.

Once consequence of this is that both programs will be equally correct. What is 
usually compared is a correct (run-time checks) program in the safe language to 
an incorrect (no run-time checks) program in the unsafe language.

About optimization, Tartan made its living selling highly optimizing C compilers 
for TI chips, which came with a free C compiler. They also made highly 
optimizing Ada compilers, which did a better job of optimization than their C 
compilers. This was documented in

C vs Ada: arguing performance religion 
(https://dl.acm.org/doi/10.1145/216578.216583)

which discusses four advantages Ada (83) has over C for optimization.

See also

Ada Outperforms Assembly: A Case Study 
(https://www2.seas.gwu.edu/~adagroup/sigada-website/lawlis.html)

TI bought Tartan and sold its Ada compilers to DDC-I.

-- 
Jeff Carter
"Monsieur Arthur King, who has the brain of a duck, you know."
Monty Python & the Holy Grail
09


^ permalink raw reply	[relevance 1%]

* Re: problemn with string'last
  2023-05-05  9:51  1% problemn with string'last Daniel Gaudry
  2023-05-05 10:02  0% ` Dmitry A. Kazakov
@ 2023-05-05 11:17  0% ` Jeffrey R.Carter
  1 sibling, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2023-05-05 11:17 UTC (permalink / raw)


On 2023-05-05 11:51, Daniel Gaudry wrote:
>   
>     Ada.Text_Io.Put_Line("     05   10   15   20   25   30   35   40   45   50   55   65   70   75   80   85   90");
>     Ada.Text_Io.Put_Line(" ....|....!....|....!....|....!....|....!....|....!....|....!....|....!....|....!....|....!");
>     Ada.Text_Io.Put_Line("»" & Data & "« " & Data'Last'Img);

As Kazakov pointed out, your scale is incorrect.

However, it's important to remember that 'Last is not necessarily the same as 
'Length because 'First is not necessarily one. This is especially important in 
subprograms that take String parameters, as they are often passed slices.

Some questions:

>    Double_Quote : constant String(1 .. 1) := (others => '"' );

ARM 2.1(15/3) 
(http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-2-1.html#I1199) defines 
the name of '"' as "quotation mark". Why do you refer to a single quotation mark 
as Double_Quote?

>    Data         : constant String         := "  PLUS_STRING    : CONSTANT STRING(1..3) :=(1 =>'" & Double_Quote & "' , 2 =>'+' , 3 =>'" & Double_Quote & ");";

Wouldn't it be simpler and clearer to write this as

Data : constant String := "  PLUS_STRING : CONSTANT STRING := " & '"' & '+' & '"';

? Note also that you seem to be missing an apostrophe (''') before the right 
parenthesis if you intend Data to be a valid Ada declaration.

-- 
Jeff Carter
"All citizens will be required to change their underwear
every half hour. Underwear will be worn on the outside,
so we can check."
Bananas
29

^ permalink raw reply	[relevance 0%]

* Re: problemn with string'last
  2023-05-05  9:51  1% problemn with string'last Daniel Gaudry
@ 2023-05-05 10:02  0% ` Dmitry A. Kazakov
  2023-05-05 11:17  0% ` Jeffrey R.Carter
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2023-05-05 10:02 UTC (permalink / raw)


On 2023-05-05 11:51, Daniel Gaudry wrote:

> here is a code that i simplified
> 
> with Ada.Text_Io;
> procedure Help
>     is
>     Double_Quote : constant String(1 .. 1) := (others => '"' );
>     Data         : constant String         := "  PLUS_STRING    : CONSTANT STRING(1..3) :=(1 =>'" & Double_Quote & "' , 2 =>'+' , 3 =>'" & Double_Quote & ");";
>     begin
>   
>     Ada.Text_Io.Put_Line("     05   10   15   20   25   30   35   40   45   50   55   65   70   75   80   85   90");
>     Ada.Text_Io.Put_Line(" ....|....!....|....!....|....!....|....!....|....!....|....!....|....!....|....!....|....!");
>     Ada.Text_Io.Put_Line("»" & Data & "« " & Data'Last'Img);
>   
> end Help;
> 
> but the data'last seems not to match the string size

It matches. You missed the "60" tick in your scale. (:-))

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

^ permalink raw reply	[relevance 0%]

* problemn with string'last
@ 2023-05-05  9:51  1% Daniel Gaudry
  2023-05-05 10:02  0% ` Dmitry A. Kazakov
  2023-05-05 11:17  0% ` Jeffrey R.Carter
  0 siblings, 2 replies; 200+ results
From: Daniel Gaudry @ 2023-05-05  9:51 UTC (permalink / raw)


hi,
here is a code that i simplified

with Ada.Text_Io;
procedure Help
   is
   Double_Quote : constant String(1 .. 1) := (others => '"' );
   Data         : constant String         := "  PLUS_STRING    : CONSTANT STRING(1..3) :=(1 =>'" & Double_Quote & "' , 2 =>'+' , 3 =>'" & Double_Quote & ");";
   begin
 
   Ada.Text_Io.Put_Line("     05   10   15   20   25   30   35   40   45   50   55   65   70   75   80   85   90");
   Ada.Text_Io.Put_Line(" ....|....!....|....!....|....!....|....!....|....!....|....!....|....!....|....!....|....!");
   Ada.Text_Io.Put_Line("»" & Data & "« " & Data'Last'Img);
 
end Help;


but the data'last seems not to match the string size

Any help is welcome
best regards

^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  2023-03-31  3:06  1%               ` Thomas
@ 2023-04-01 10:18  0%                 ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2023-04-01 10:18 UTC (permalink / raw)


I'm not going to answer this point-by-point, as it would take very much too 
long, and there is a similar thread going on the ARG's Github (which needs 
my attention more than comp.lang.ada.

But my opinion is that Ada got strings completely wrong, and the best thing 
to do with them is to completely nuke them and start over. But one cannot do 
that in the context of Ada, one would have to at least leave way to use the 
old mechanisms for compatibility with older code. That would leave a 
hodge-podge of mechanisms that would make Ada very much harder (rather than 
easier) to use.

As far as the cruft goes, I wrote up a 20+ page document on that during the 
pandemic, but I could never interest anyone knowledgeable to review it, and 
I don't plan to make it available without that. Most of the things are 
caused by interactions -- mostly because of too much generality. And of 
course there are features that Ada would be better off without (like 
anonymous access types).

                          Randy.

"Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message 
news:64264e2f$0$25952$426a74cc@news.free.fr...
> In article <t2g0c1$eou$1@dont-email.me>,
> "Randy Brukardt" <randy@rrsoftware.com> wrote:
>
>> "Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message
>> news:fantome.forums.tDeContes-5E3B70.20370903042022@news.free.fr...
>> ...
>> > as i said to Vadim Godunko, i need to fill a string type with an UTF-8
>> > litteral.but i don't think this string type has to manage various
>> > conversions.
>> >
>> > from my point of view, each library has to accept 1 kind of string type
>> > (preferably UTF-8 everywhere),
>> > and then, this library has to make needed conversions regarding the
>> > underlying API. not the user.
>>
>> This certainly is a fine ivory tower solution,
>
> I like to think from an ivory tower,
> and then look at the reality to see what's possible to do or not. :-)
>
>
>
>> but it completely ignores two
>> practicalities in the case of Ada:
>>
>> (1) You need to replace almost all of the existing Ada language defined
>> packages to make this work. Things that are deeply embedded in both
>> implementations and programs (like Ada.Exceptions and Ada.Text_IO) would
>> have to change substantially. The result would essentially be a different
>> language, since the resulting libraries would not work with most existing
>> programs.
>
> - in Ada, of course we can't delete what's existing, and there are many
> packages which are already in 3 versions (S/WS/WWS).
> imho, it would be consistent to make a 4th version of them for a new
> UTF_8_String type.
>
> - in a new language close to Ada, it would not necessarily be a good
> idea to remove some of them, depending on industrial needs, to keep them
> with us.
>
>> They'd have to have different names (since if you used the same
>> names, you change the failures from compile-time to runtime -- or even
>> undetected -- which would be completely against the spirit of Ada), which
>> means that one would have to essentially start over learning and using 
>> the
>> resulting language.
>
> i think i don't understand.
>
>> (and it would make sense to use this point to
>> eliminate a lot of the cruft from the Ada design).
>
> could you give an example of cruft from the Ada design, please? :-)
>
>
>>
>> (2) One needs to be able to read and write data given whatever encoding 
>> the
>> project requires (that's often decided by outside forces, such as other
>> hardware or software that the project needs to interoperate with).
>
>> At a minimum, you
>> have to have a way to specify the encoding of files, streams, and 
>> hardware
>> interfaces
>
>> That will greatly complicate the interface and
>> implementation of the libraries.
>
> i don't think so.
> it's a matter of interfacing libraries, for the purpose of communicating
> with the outside (neither of internal libraries nor of the choice of the
> internal type for the implementation).
>
> Ada.Text_IO.Open.Form already allows (a part of?) this (on the content
> of the files, not on their name), see ARM A.10.2 (6-8).
> (write i the reference to ARM correctly?)
>
>
>
>>
>> > ... of course, it would be very nice to have a more thicker language 
>> > with
>> > a garbage collector ...
>>
>> I doubt that you will ever see that in the Ada family,
>
>> as analysis and
>> therefore determinism is a very important property for the language.
>
> I completely agree :-)
>
>> Ada has
>> lots of mechanisms for managing storage without directly doing it 
>> yourself
>> (by calling Unchecked_Deallocation), yet none of them use any garbage
>> collection in a traditional sense.
>
> sorry, i meant "garbage collector" in a generic sense, not in a
> traditional sense.
> that is, as Ada users we could program with pointers and pool, without
> memory leaks nor calling Unchecked_Deallocation.
>
> for example Ada.Containers.Indefinite_Holders.
>
> i already wrote one for constrained limited types.
> do you know if it's possible to do it for unconstrained limited types,
> like the class of a limited tagged type?
>
> -- 
> RAPID maintainer
> http://savannah.nongnu.org/projects/rapid/ 


^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  2022-04-04 23:52  1%             ` Randy Brukardt
@ 2023-03-31  3:06  1%               ` Thomas
  2023-04-01 10:18  0%                 ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Thomas @ 2023-03-31  3:06 UTC (permalink / raw)


In article <t2g0c1$eou$1@dont-email.me>,
 "Randy Brukardt" <randy@rrsoftware.com> wrote:

> "Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message 
> news:fantome.forums.tDeContes-5E3B70.20370903042022@news.free.fr...
> ...
> > as i said to Vadim Godunko, i need to fill a string type with an UTF-8
> > litteral.but i don't think this string type has to manage various 
> > conversions.
> >
> > from my point of view, each library has to accept 1 kind of string type
> > (preferably UTF-8 everywhere),
> > and then, this library has to make needed conversions regarding the
> > underlying API. not the user.
> 
> This certainly is a fine ivory tower solution,

I like to think from an ivory tower, 
and then look at the reality to see what's possible to do or not. :-)



> but it completely ignores two 
> practicalities in the case of Ada:
> 
> (1) You need to replace almost all of the existing Ada language defined 
> packages to make this work. Things that are deeply embedded in both 
> implementations and programs (like Ada.Exceptions and Ada.Text_IO) would 
> have to change substantially. The result would essentially be a different 
> language, since the resulting libraries would not work with most existing 
> programs.

- in Ada, of course we can't delete what's existing, and there are many 
packages which are already in 3 versions (S/WS/WWS).
imho, it would be consistent to make a 4th version of them for a new 
UTF_8_String type.

- in a new language close to Ada, it would not necessarily be a good 
idea to remove some of them, depending on industrial needs, to keep them 
with us.

> They'd have to have different names (since if you used the same 
> names, you change the failures from compile-time to runtime -- or even 
> undetected -- which would be completely against the spirit of Ada), which 
> means that one would have to essentially start over learning and using the 
> resulting language.

i think i don't understand.

> (and it would make sense to use this point to 
> eliminate a lot of the cruft from the Ada design).

could you give an example of cruft from the Ada design, please? :-)


> 
> (2) One needs to be able to read and write data given whatever encoding the 
> project requires (that's often decided by outside forces, such as other 
> hardware or software that the project needs to interoperate with).

> At a minimum, you 
> have to have a way to specify the encoding of files, streams, and hardware 
> interfaces

> That will greatly complicate the interface and 
> implementation of the libraries.

i don't think so.
it's a matter of interfacing libraries, for the purpose of communicating 
with the outside (neither of internal libraries nor of the choice of the 
internal type for the implementation).

Ada.Text_IO.Open.Form already allows (a part of?) this (on the content 
of the files, not on their name), see ARM A.10.2 (6-8).
(write i the reference to ARM correctly?)



> 
> > ... of course, it would be very nice to have a more thicker language with 
> > a garbage collector ...
> 
> I doubt that you will ever see that in the Ada family,

> as analysis and 
> therefore determinism is a very important property for the language.

I completely agree :-)

> Ada has 
> lots of mechanisms for managing storage without directly doing it yourself 
> (by calling Unchecked_Deallocation), yet none of them use any garbage 
> collection in a traditional sense.

sorry, i meant "garbage collector" in a generic sense, not in a 
traditional sense.
that is, as Ada users we could program with pointers and pool, without 
memory leaks nor calling Unchecked_Deallocation.

for example Ada.Containers.Indefinite_Holders.

i already wrote one for constrained limited types.
do you know if it's possible to do it for unconstrained limited types, 
like the class of a limited tagged type?

-- 
RAPID maintainer
http://savannah.nongnu.org/projects/rapid/

^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  @ 2023-03-30 23:35  1%         ` Thomas
  0 siblings, 0 replies; 200+ results
From: Thomas @ 2023-03-30 23:35 UTC (permalink / raw)


sorry for the delay.


In article <48309745-aa2a-47bd-a4f9-6daa843e0771n@googlegroups.com>,
 Vadim Godunko <vgodunko@gmail.com> wrote:

> On Sunday, April 3, 2022 at 10:20:21 PM UTC+3, Thomas wrote:
> > 
> > > But don't use unit names containing international characters, at any 
> > > rate if you're (interested in compiling on) Windows or macOS: 
> > > 
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81114
> > 
> > and this kind of problems would be easier to avoid if string types were 
> > stronger ... 
> > 
> 
> Your suggestion is unable to resolve this issue on Mac OS X.

i said "easier" not "easy".

don't forget that Unicode has 2 levels :
- octets <-> code points
- code points <-> characters/glyphs

and you can't expect the upper to work if the lower doesn't.


> Like case 
> sensitivity, binary compare of two strings can't compare strings in different 
> normalization forms. Right solution is to use right type to represent any 
> paths,

what would be the "right type", according to you?


In fact, here the first question to ask is:
what's the expected encoding for Ada.Text_IO.Open.Name?
- is it Latin-1 because the type is String not UTF_8_String?
- is it undefined because it depends on the underling FS?

-- 
RAPID maintainer
http://savannah.nongnu.org/projects/rapid/

^ permalink raw reply	[relevance 1%]

* ChatGPT
@ 2023-03-30 21:49  1% Anatoly Chernyshev
  0 siblings, 0 replies; 200+ results
From: Anatoly Chernyshev @ 2023-03-30 21:49 UTC (permalink / raw)


Just had an exercise with ChatGPT for Ada.

Here is what my request was: "Produce Ada code for solving a quadratic equation."

And here's the output from ChatGPT (quite flawless forgiving the absence of a math lib in the header):
----------------------------
with Ada.Text_IO; use Ada.Text_IO;

procedure Quadratic_Equation is
   A, B, C, D : Float;
   X1, X2 : Float;
begin
   -- read coefficients A, B, and C from the user
   Put("Enter coefficient A: ");
   Get(A);
   
   Put("Enter coefficient B: ");
   Get(B);
   
   Put("Enter coefficient C: ");
   Get(C);

   -- calculate the discriminant
   D := B*B - 4.0*A*C;

   -- check if the discriminant is negative
   if D < 0.0 then
      Put_Line("No real roots exist.");
   else
      -- calculate the roots
      X1 := (-B + Sqrt(D)) / (2.0*A);
      X2 := (-B - Sqrt(D)) / (2.0*A);
      
      -- output the roots
      Put_Line("Root 1 = " & Float'Image(X1));
      Put_Line("Root 2 = " & Float'Image(X2));
   end if;
end Quadratic_Equation;

and an extra remark:

Note that this implementation assumes that the discriminant (B^2 - 4AC) is positive or zero. If the discriminant is negative, then no real roots exist.
-----------------------------------------------

Before crying wolf, my impression is that ChatGPT might be useful for drafting simple pieces of code (say, homeworks). Very soon though one will arrive at a situation when the amount of efforts to explain the task to ChatGPT will be the same as to write the code yourself (I shall call it a limiting Kolmogorov complexity).

What do you think?



^ permalink raw reply	[relevance 1%]

* Re: Build order with gprbuild
  @ 2023-03-01 20:08  1%   ` Gautier write-only address
  0 siblings, 0 replies; 200+ results
From: Gautier write-only address @ 2023-03-01 20:08 UTC (permalink / raw)


Between normal Ada projects, everything works as you describe (and as expected).
However, in the special case where project B, instead of transforming Ada files into .o files, transforms other kind of files into Ada files that are with-ed by units of project A, things get off the road: project A doesn't see out-of-date Ada files produced by project B.

Here is a full example. Files are reproduced below (they are meant to land into the same directory).
Then you do the following commands:

gprbuild -P fuzzy_gen.gpr
gprbuild -P code_generation.gpr
gnatstudio -P main.gpr

First build launched from GNAT Studio does the following on my machine:

    Compile
    [Ada]          main.adb
    [Fuzzy]        x789.cfg
    Ada file "fuzzy_x789.adb" is up to date
    [Fuzzy]        x456.cfg
    Ada file "fuzzy_x456.adb" is up to date
    [Fuzzy]        x123.cfg
    Ada file "fuzzy_x123.adb" is up to date
    [Ada]          fuzzy_x123.adb
    [Ada]          fuzzy_x456.adb
    [Ada]          fuzzy_x789.adb
    Bind
    [gprbind]      main.bexch
    [Ada]          main.ali
    Link
    [link]         main.adb

Second build has an expected output as well:

    Compile
       [Fuzzy]        x789.cfg
    Ada file "fuzzy_x789.adb" is up to date
       [Fuzzy]        x456.cfg
    Ada file "fuzzy_x456.adb" is up to date
       [Fuzzy]        x123.cfg
    Ada file "fuzzy_x123.adb" is up to date
    gprbuild: "main.exe" up to date

Now, say you modify x123.cfg and save it.
    Compile
       [Fuzzy]        x789.cfg
    Ada file "fuzzy_x789.adb" is up to date
       [Fuzzy]        x456.cfg
    Ada file "fuzzy_x456.adb" is up to date
       [Fuzzy]        x123.cfg
    Converting "x123.cfg" into "fuzzy_x123.adb"...
    gprbuild: "main.exe" up to date

That's *not* what I would like: gprbuild did not detect the out-of-date file "fuzzy_x123.adb" in time.
A second call to gprbuild compiles the changed "fuzzy_x123.adb" and all is well, but it is one step too late.

The files
=========

1) The code generator
=====================

fuzzy_gen.gpr:
-------------

project Fuzzy_Gen is
  for Object_Dir use "obj";
  for Exec_Dir use "gen";
  for Create_Missing_Dirs use "True";
  for Main use ("fuzzy_gen.adb");
end Fuzzy_Gen;

fuzzy_gen.adb:
-------------

with Ada.Calendar,
     Ada.Command_Line,
     Ada.Directories,
     Ada.Text_IO;

procedure Fuzzy_Gen is
  use Ada.Command_Line, Ada.Directories, Ada.Text_IO;

  procedure Convert (arg : String) is
    cfg : constant String := Simple_Name (arg);
    cfg_file_name : constant String := "../" & cfg;
    ada_unit_name : constant String :=
      "fuzzy_" & cfg (cfg'First .. cfg'Last - 4);
    ada_file_name : constant String := ada_unit_name & ".adb";
    cfg_in, ada_out : File_Type;
    use type Ada.Calendar.Time;
  begin
    if Exists (ada_file_name) and then
       Modification_Time (ada_file_name) >=
       Modification_Time (cfg_file_name)
    then
      Put_Line ("Ada file """ & ada_file_name & """ is up to date");
      return;
    end if;
    Put_Line
      ("Converting """ & cfg & """ into """ & ada_file_name & """...");
    Open (cfg_in, In_File, cfg_file_name);
    Create (ada_out, Out_File, ada_file_name);
    Put_Line
      (ada_out, "function " & ada_unit_name & " return String is");
    Put_Line (ada_out, "begin");
    Put_Line (ada_out, "  return """ & Get_Line (cfg_in) & """;");
    Put_Line (ada_out, "end;");
    Close (cfg_in);
    Close (ada_out);
  end Convert;


begin
  if Argument_Count = 0 then
    Put_Line (Current_Error, "config file name missing");
  else
    Convert (Argument (1));
  end if;
end Fuzzy_Gen;

2) The project that generates Ada files ("project B")
=====================================================

code_generation.gpr:
-------------------
project Code_Generation is

   for Languages use ("Fuzzy");
   for Source_Dirs use (".");
   for Object_Dir use "gen";
   for Objects_Linked  ("Fuzzy") use "False";

   package Naming is
      for Body_Suffix ("Fuzzy") use ".cfg";
   end Naming;

   package Compiler is
      for Driver ("Fuzzy") use "fuzzy_gen";
   end Compiler;

end Code_Generation;

x123.cfg:
--------
123

x456.cfg:
--------
456

x789.cfg:
--------
789

3) The main project (project A)
===============================

main.gpr:
--------
with "code_generation.gpr";

project Main is
  for Source_Dirs use (".", "gen");
  for Object_Dir use "obj";
  for Create_Missing_Dirs use "True";
  for Main use ("main.adb");
end Main;

main.adb:
--------
with Ada.Text_IO;
with Fuzzy_X123,
     Fuzzy_X456,
     Fuzzy_X789;

procedure Main is
begin
  Ada.Text_IO.Put
    ("Messages from elsewhere:" &
     " """ & Fuzzy_X123 & '"' &
     " """ & Fuzzy_X456 & '"' &
     " """ & Fuzzy_X789 & '"');
end;

^ permalink raw reply	[relevance 1%]

* Re: wait does not perform as expected
  2023-02-22 16:34  1% wait does not perform as expected Daniel Gaudry
  2023-02-22 17:36  1% ` Niklas Holsti
@ 2023-02-24 21:16  1% ` Jeffrey R.Carter
  1 sibling, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2023-02-24 21:16 UTC (permalink / raw)


On 2023-02-22 17:34, Daniel Gaudry wrote:
> the following code :

Atio and Tio are undefined. Clearly this code is not what you are running.

The important bit:

>           if Skip_After > 0.0
>              then
> 
>              -- KEEP THE USER'S ATTENTION
>              while Timer < Skip_After loop
>                 Timer := 1.0 + @;
>                 delay 1.0;
>                 ada.text_io.Put(Natural(Skip_After - Timer)'Img);
> 
>                 --USER ENDS THE WAITING PERIOD  BEFORE IT'S END ?
> 
> 
>                 TIO.LOOK_AHEAD(ITEM          => CHAR,
>                                END_OF_LINE   => HIT);
>                 
>                   ada.text_io.GET_IMMEDIATE(ITEM      => CHAR,
>                                      AVAILABLE => HIT);
>                    IF HIT THEN
>                       RETURN;
>                    END IF;
> 
>              end loop;
> 
>              -- USER WAITED FOR THE WHOLE  WAITING PERIOD
>              -- LET HIM READ THE ZERO ON THE SCREEN
> 
>              delay 1.0;
>              return;
>           end if;

Let's simplify this. Without the countdown, this can be rewritten using ATC

Timed_Out : Boolean := False;
...
select
    delay Skip_After;

    Timed_Out := True;
then abort
    Ada.Text_IO.Get_Immediate (Item => Char);
end select;

if Timed_Out then
    delay 1.0;
end if;

return;

This should be simple enough to get right. If ATC doesn't work well with this, 
it should still be simple enough to get right without it.

To add the countdown, let's split that out into a task:

declare
    task Timer is
       entry Stop;
    end Timer;

    task body Timer is ...
    -- Does the countdown immediately (uses the global constant Skip_After)
    -- Stops the countdown if Stop is called
begin
    select
       delay Skip_After;

       Timed_Out := True;
    then abort
       Ada.Text_IO.Get_Immediate (Item => Char);
       Timer.Stop;
    end select;
end;

if Timed_Out then
    delay 1.0;
end if;

return;

The task should be simple enough to get right, too.

-- 
Jeff Carter
"Saving keystrokes is the job of the text editor,
not the programming language."
Preben Randhol
64

^ permalink raw reply	[relevance 1%]

* Re: wait does not perform as expected
  2023-02-23 18:47  1%           ` Daniel Gaudry
  2023-02-23 19:08  0%             ` Niklas Holsti
@ 2023-02-23 19:31  0%             ` Niklas Holsti
  1 sibling, 0 replies; 200+ results
From: Niklas Holsti @ 2023-02-23 19:31 UTC (permalink / raw)


On 2023-02-23 20:47, Daniel Gaudry wrote:

> Hi,
> On my ubuntu system the
> ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
> just pause the program regardless of any key being hit.


Hmm... it occurred to me to try to execute the program under GPS, not in 
a shell window.

If I run a Get_Immediate loop under GPS, within the input-output window 
of GPS, there is /no reaction/ to keystrokes until I press Return/Enter. 
Get_Immediate returns Available => False until Return/Enter is pressed, 
after which it returns the characters typed before Return/Enter, one by 
one in order.

So it seems that, on my system, Get_Immediate cannot disable the 
line-buffering of the standard-input "terminal", but must wait for 
Return/Enter until it sees any input. And line-editing too is still 
active under Get_Immediate, when running within GPS.

I am starting to suspect that the behaviour I see in my shell command 
window may be due partly to the terminal emulator that implements such 
windows on my system (MacOS "Terminal" app).

Daniel, how are you compiling and running your code? Under GPS, in a 
shell window, or in some other way (shell script)?

If you have been running within GPS, try to run your program in a normal 
shell command window.

^ permalink raw reply	[relevance 0%]

* Re: wait does not perform as expected
  2023-02-23 18:47  1%           ` Daniel Gaudry
@ 2023-02-23 19:08  0%             ` Niklas Holsti
  2023-02-23 19:31  0%             ` Niklas Holsti
  1 sibling, 0 replies; 200+ results
From: Niklas Holsti @ 2023-02-23 19:08 UTC (permalink / raw)


On 2023-02-23 20:47, Daniel Gaudry wrote:
> On Thursday, February 23, 2023 at 7:29:36 PM UTC+1, Niklas Holsti wrote:
>> On 2023-02-23 20:14, Dmitry A. Kazakov wrote:
>>> On 2023-02-23 18:35, Niklas Holsti wrote:
>>>> On 2023-02-23 16:26, AdaMagica wrote:
>>>>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
>>>>>> On my system, Get_Immediate does /not/ use the inputs collected (but
>>>>>> not
>>>>>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
>>>>>> keystrokes. If there are none, Get_Immediate returns "not Available"
>>>>>> (Hit is False) and so the loop continues.
>>>>>
>>>>> Are you sure?
>>>>
>>>> That is what I observe.
>>>
>>> The implementation of Look_Ahead calls getc followed by ungetc. Thus it
>>> blocks until an input if there is no buffered. And not just input, but
>>> for a line or file end.
>> That seems in order.
>>
>> However, the crux of the question is in Get_Immediate. Do you know how
>> that is implemented on various systems? It has to disable line buffering
>> and line editing on the input stream. One question is whether and how
>> such "tty" configuration changes affect whatever buffers getc/ungetc use.
>>
>> On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
>> does not use the same buffers, and has no effect on those buffers. That
>> could be desirable behaviour in some cases, undesirable in others.
>>
>> On AdaMagica's system, it seems that Get_Immediate uses the same buffers
>> as Look_Ahead (getc/ungetc).
> 
> 
> Hi,
> On my ubuntu system the
> ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
> just pause the program regardless of any key being hit.
> I just cannot use a wait  (several shorts one in a row) interrupted by a key hit.
> Any possibility you may know of ??


Please show the Ada code you have now. I assume there is no Look_Ahead 
there, right?

Best if you can write, test and post a short, stand-alone program that 
just contains the wait-for-keystroke procedure, then we can be sure that 
there is nothing else in the program that might interfere.

^ permalink raw reply	[relevance 0%]

* Re: wait does not perform as expected
  @ 2023-02-23 18:47  1%           ` Daniel Gaudry
  2023-02-23 19:08  0%             ` Niklas Holsti
  2023-02-23 19:31  0%             ` Niklas Holsti
  0 siblings, 2 replies; 200+ results
From: Daniel Gaudry @ 2023-02-23 18:47 UTC (permalink / raw)


On Thursday, February 23, 2023 at 7:29:36 PM UTC+1, Niklas Holsti wrote:
> On 2023-02-23 20:14, Dmitry A. Kazakov wrote: 
> > On 2023-02-23 18:35, Niklas Holsti wrote: 
> >> On 2023-02-23 16:26, AdaMagica wrote: 
> >>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1: 
> >>>> On my system, Get_Immediate does /not/ use the inputs collected (but 
> >>>> not 
> >>>> "consumed") by Look_Ahead, but instead checks if there are _new_ input 
> >>>> keystrokes. If there are none, Get_Immediate returns "not Available" 
> >>>> (Hit is False) and so the loop continues. 
> >>> 
> >>> Are you sure? 
> >> 
> >> That is what I observe. 
> > 
> > The implementation of Look_Ahead calls getc followed by ungetc. Thus it 
> > blocks until an input if there is no buffered. And not just input, but 
> > for a line or file end.
> That seems in order. 
> 
> However, the crux of the question is in Get_Immediate. Do you know how 
> that is implemented on various systems? It has to disable line buffering 
> and line editing on the input stream. One question is whether and how 
> such "tty" configuration changes affect whatever buffers getc/ungetc use. 
> 
> On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate 
> does not use the same buffers, and has no effect on those buffers. That 
> could be desirable behaviour in some cases, undesirable in others. 
> 
> On AdaMagica's system, it seems that Get_Immediate uses the same buffers 
> as Look_Ahead (getc/ungetc).


Hi,
On my ubuntu system the 
ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
just pause the program regardless of any key being hit.
I just cannot use a wait  (several shorts one in a row) interrupted by a key hit.
Any possibility you may know of ??
My Best Regards

^ permalink raw reply	[relevance 1%]

* Re: wait does not perform as expected
  2023-02-22 16:34  1% wait does not perform as expected Daniel Gaudry
@ 2023-02-22 17:36  1% ` Niklas Holsti
    2023-02-24 21:16  1% ` Jeffrey R.Carter
  1 sibling, 1 reply; 200+ results
From: Niklas Holsti @ 2023-02-22 17:36 UTC (permalink / raw)


On 2023-02-22 18:34, Daniel Gaudry wrote:
> hi
> the following code :


(I include only the relevant parts:)


>      while Timer < Skip_After loop
>         Timer := 1.0 + @;
>         delay 1.0;
>         ada.text_io.Put(Natural(Skip_After - Timer)'Img);
> 
>         --USER ENDS THE WAITING PERIOD  BEFORE IT'S END ?
> 
> 
>          TIO.LOOK_AHEAD(ITEM          => CHAR,
>                         END_OF_LINE   => HIT); >
>
>          ada.text_io.GET_IMMEDIATE(ITEM      => CHAR,
>                                    AVAILABLE => HIT);
>          IF HIT THEN
>            RETURN;
>          END IF;
> 
>        end loop;

Why do you call both Look_Ahead and Get_Immediate, but throw away the 
result of Look_Ahead?

The behaviour may depend on how you configure (via OS calls) the 
behaviour of your terminal emulator (the "shell window"), but for me, on 
Mac OS/X with the default configuration, it behaves as follows.

The first time Look_Ahead is called (first loop iteration) it waits for 
the user to press Return (Enter) before it delivers the look-ahead 
character to the program. It must do so because it must see if the next 
input is an end-of-line (Return/Enter) or a character (assuming there is 
no "unconsumed" input when the loop starts).

The program is therefore suspended in the first Look_Ahead call, and the 
timer loop and remaining-time output are also suspended, until you at 
least press Return/Enter.

If you do press Return/Enter, perhaps after pressing some other keys, 
the waiting Look_Ahead call returns either the (first) character you 
pressed before Return/Enter, or End_Of_Line (Hit is True). However, your 
code then throws those results away, and instead calls Get_Immediate.

On my system, Get_Immediate does /not/ use the inputs collected (but not 
"consumed") by Look_Ahead, but instead checks if there are _new_ input 
keystrokes. If there are none, Get_Immediate returns "not Available" 
(Hit is False) and so the loop continues.

When Look_Ahead is called again, in the further loop iterations, it sees 
that there now is unconsumed input (from the first call of Look_Ahead) 
so it returns immediately (with the same results as on the first call). 
Therefore the loop now works are you intend: if the user presses any key 
before the Skip_After time is exhausted, the subprogram returns when 
Get_Immediate sees that keystroke.

To fix the problem, remove the Look_Ahead call from the loop.

(For goodness sake, also clean up your "with" clauses -- only 
Ada.Text_IO is relevant for your code -- and remove the multiple renames 
of Ada.Text_IO. You seem to have at least "Atio" and "TIO" as renames 
for Ada.Text_IO. One would be plenty.)

^ permalink raw reply	[relevance 1%]

* wait does not perform as expected
@ 2023-02-22 16:34  1% Daniel Gaudry
  2023-02-22 17:36  1% ` Niklas Holsti
  2023-02-24 21:16  1% ` Jeffrey R.Carter
  0 siblings, 2 replies; 200+ results
From: Daniel Gaudry @ 2023-02-22 16:34 UTC (permalink / raw)


hi
the following code :


with Gnat.Os_Lib;
with Ada.Strings;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Ada.Strings.Maps.Constants;
 with ada.text_io;
with Ada.Strings;


 procedure Hit_Return_To_Continue(Header     : in String   := "HIT RETURN TO CONTINUE";
                                    Mandatory  : in Boolean  := False;
                                    Skip_After : in Duration := 0.0)
      is

      Char  : Character := ' ';
      Hit   : Boolean   := True;
      Timer : Duration  := 0.0;

      begin

      -- ANYTHING TO DO ?
      if Mandatory
         then
          ada.text_io.Put(Header);

         -- ANY WAITING PERIOD TO DISPLAY ?
         if Skip_After > 0.0
            then

            -- KEEP THE USER'S ATTENTION
            while Timer < Skip_After loop
               Timer := 1.0 + @;
               delay 1.0;
               ada.text_io.Put(Natural(Skip_After - Timer)'Img);

               --USER ENDS THE WAITING PERIOD  BEFORE IT'S END ?


               TIO.LOOK_AHEAD(ITEM          => CHAR,
                              END_OF_LINE   => HIT);
               
                 ada.text_io.GET_IMMEDIATE(ITEM      => CHAR,
                                    AVAILABLE => HIT);
                  IF HIT THEN
                     RETURN;
                  END IF;

            end loop;

            -- USER WAITED FOR THE WHOLE  WAITING PERIOD
            -- LET HIM READ THE ZERO ON THE SCREEN

            delay 1.0;
            return;
         end if;

         Atio.Get_Immediate(Item      => Char,
                            Available => Hit);

         Atio.New_Line(Spacing => 1);

      end if;

   end Hit_Return_To_Continue;




the following call:

Hit_Return_To_Continue(Header        => "HIT RETURN TO CONTINUE",
                                           Mandatory  => true,
                                          Skip_After    => 5.0);

does not return if the user hits a key before the end of the countdown.

Can anybody help
Best regards

^ permalink raw reply	[relevance 1%]

* Re: Broadcast / iterate to all Connection objects via Simple Components?
  @ 2023-02-15 10:57  1%                         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2023-02-15 10:57 UTC (permalink / raw)


On 2023-02-15 10:54, Niklas Holsti wrote:
> On 2023-02-13 21:48, Dmitry A. Kazakov wrote:
>> On 2023-02-13 17:26, Niklas Holsti wrote:
>>> On 2023-02-13 17:10, Dmitry A. Kazakov wrote:
>>
>>> But why should the RM define two "task" concepts that have exactly 
>>> the same properties? Or should co-routines have some different 
>>> properties? That was the point of my question, apologies if I was 
>>> unclear.
>>
>> Ada has floating-point, fixed-point, universal real implementations of 
>> the same concept of real number. Why?
> 
> Of course because these implementations have /different/ properties, 
> suitable for different uses. They are /not/ the same, and their 
> differences are defined in the Ada RM.

The concept here is R, the set of real numbers.

> Perhaps you think that those differences are implicit in the term 
> "co-routine", but I don't find it so, sorry.

Clearly co-routine and OS thread have different properties as 
implementations of same concept of a "thread of control."

>> Rendezvous is asymmetric client-server. In a callback scenario parties 
>> are equivalent. Each can wait for another. With tasks a protected 
>> object is usually thrown in to work it around.
> 
> Aha, so you are proposing that co-routines would have some other means, 
> not protected objects, for symmetric inter-co-routine communication.

When you do blocking I/O you do not [explicitly] communicate with the 
system PCI bus or whatever.

> What would that be, perhaps directly shared (unprotected) variables?

Nothing. When you call Ada.Text_IO.Put_Line, you just do that, File_Type 
is not shared, not explicitly.

> Then you have to ensure that those co-routines are implicitly mutually 
> exclusive, right?

Exclusive to what?

>> 1. To simplify "pipeline" stuff. Each side need not to know what the 
>> other side does or each other. They know the pipeline. The programmer 
>> should use a call or a timed entry call or a selective accept. I leave 
>> that open for now.
> 
> By "pipeline", do you mean an order-preserving stream of data from a 
> producer to a consumer? If so, a simple protected queue or buffer 
> between producer and consumer tasks implements it.

No it does not. I was talking about the pipeline ends, not about the 
pipeline itself.

> By leaving the details open, you leave your proposal fuzzy and hard to 
> understand.

You need an implementation writing a buffer of n bytes into a FIFO queue?

procedure Write (S : in out FIFO; X : Stream_Element_Array) is
    From : Stream_Element_Offset := X'First;
begin
    loop
       Queue_Immediate (S, X (This..X'Last), From);
       exit when From >= X'Last;
       Wait_For_Not_Full (S);
       From := From + 1;
    end loop;
end Write;

The client code calls Write, which appears as a blocking call.

Should I provide another end too? (:-))

>> 2. To allow sharing context of a single OS thread. So the term 
>> "co-routine."
> 
> I don't think that property is implicit in the term "co-routine", 
> because co-routines can exist even without OS threads.

In the same sense how System.Address can exist without a processor? (:-))

> But most importantly, this property cannot be used to /define/ the 
> "co-routine" concept in the Ada RM. That definition may of course be 
> /chosen/ so as to /allow/ this implementation.

See above. The concept here is thread of control.

> However, this property is already satisfied for "tasks" in those Ada 
> systems that implement tasking in the RTS, without using multiple OS 
> threads. So the current definition of Ada "tasks" already allows such 
> sharing.

It does not support user implementations of tasks coexisting with the 
OS-backed tasks. Certainly one possible way would be like it was done 
with the access types and storage pools to provide an abstraction layer 
for tasks. However, I think that could be a bit extreme.

>> 3. As I said above, the goal is to take plain I/O code (the client) 
>> and reuse it with no adjustments with a server/provider/consumer in 
>> place of the OS I/O subsystem.
> 
> And that server/provider/consumer would be what?

See the pipeline example.

> Ada code in the 
> application? Or part of the Ada RTS? Would it have to be aware of all of 
> the OS I/O subsystem's services? For example, would it have to know 
> about the socket interface to networking?

The library supplied implementation of Send (see Write above) will. The 
client will call Send which in the case of non-blocking I/O will yield 
in Wait_For_Not_Full above and resume upon a callback or explicitly by 
the handler of the socket set. The co-routine case is having the handler 
and many callers to Send ran by the same OS thread (or by a much 
narrower pool of OS threads).

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

^ permalink raw reply	[relevance 1%]

* Re: Real_Arrays on heap with overloaded operators and clean syntax
  @ 2023-01-22 23:53  1%       ` Joakim Strandberg
  0 siblings, 0 replies; 200+ results
From: Joakim Strandberg @ 2023-01-22 23:53 UTC (permalink / raw)


måndag 23 januari 2023 kl. 00:34:31 UTC+1 skrev roda...@gmail.com:
> On 23/1/23 10:20, Jim Paloander wrote: 
> >>> Dear ADA lovers, 
> >>> with stack allocation of Real_Vector ( 1 .. N ) when N >= 100,000 I get STACK_OVERFLOW ERROR while trying to check how fast operator overloading is working for an expression 
> >>> 
> >>> X := A + B + C + C + A + B, where 
> >>> A,B,C,X are all Real_Vector ( 1 .. N ). 
> >>> 
> >>> So my only option was to allocate on the heap using new. But then I lost the clean syntax 
> >>> 
> >>> X := A + B + C + C + A + B 
> >>> 
> >>> and I had to write instead: 
> >>> 
> >>> X.all := A.all + B.all + C.all + C.all + A.all + B.all. 
> >>> 
> >>> This is really ugly and annoying because when you are using Real_Arrays for implementing some linear algebra method who relies heavilly on matrix vector products and vector updates, you do need to allocate on the heap (sizes are determined in runtime) and you do need a clean syntax. So, is there any way to simplify my life without using the .all or even without declaring A,B,C,X as access Real_Vector? 
> >>> Thanks for your time! 
> >> If you are on linux, then you could set the stack size with 
> >> 
> >> $ ulimit -s unlimited 
> >> $ launch_my_app 
> >> 
> >> 
> >> 
> >> Regards. 
> > On Windows 10 with mingw64?
> Not sure. I don't have a windows machine. 
> 
> What happens when try ? 
> 
> $ ulimit -a

Something came up and I had to send my previous reply/e-mail as is. I wanted to find the video where Jean Pierre Rosen talks about how memory is handled in the Ada language from FOSDEM perhaps 2018-2019. Unfortunately I have been unable to find it.

Secondly, example of Ada code where Storage pool usage is demonstrated: https://github.com/joakim-strandberg/advent_of_code

Example of task with rendez-vous mechanism:
task T with Storage_Size => 10_000_000 is
   entry Run (I : Integer);
end T;

task body T is
begin
   loop
       begin
           select
                accept Run (I : Integer) do
                     null;  --  Here save the value of the integer I for later processing in the task
                end Run;
                null;  -- Whenever another task calls Run on this task, the work to be done should be put here.
               -- Put the mathematical calcuations here.
           or
                terminate;  --  To end the select-statement with "or terminate;" means the task will terminate when the environment task has finished execution of the "Main" procedure of the application. No need to tell the task T that now it is time to shutdown.
           end select;
       exception
            when Error : others =>
              -- Print error to standard out here using subprograms from Ada.Exceptions and Ada.Text_IO.
       end;
   end loop;
end T; 

Best regards,
Joakim

^ permalink raw reply	[relevance 1%]

* Re: Text_io package's Positive_Count type
  2023-01-11 21:04  1%   ` Mace Ayres
  2023-01-11 21:42  0%     ` Niklas Holsti
@ 2023-01-11 21:46  1%     ` Jeffrey R.Carter
  1 sibling, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2023-01-11 21:46 UTC (permalink / raw)


On 2023-01-11 22:04, Mace Ayres wrote:
> ____
> This is different error than before and I easily see Put() is expecting Integer but has the.. count type; so I need some sort of translation to satisfy put(), maybe with and use Text_IO.Integer_IO as error message suggest?

Ada.Text_IO.Integer_IO is a generic package that you would instantiate with 
Ada.Text_IO.Positive_Count. The instantiation would then have a Put procedure 
for Positive_Count.

Alternatively, you could use Positive_Count'Image to convert your values into 
Strings that may be used directly with Ada.Text_IO.Put.

-- 
Jeff Carter
"You me on the head hitted."
Never Give a Sucker an Even Break
108

^ permalink raw reply	[relevance 1%]

* Re: Text_io package's Positive_Count type
  2023-01-11 21:04  1%   ` Mace Ayres
@ 2023-01-11 21:42  0%     ` Niklas Holsti
  2023-01-11 21:46  1%     ` Jeffrey R.Carter
  1 sibling, 0 replies; 200+ results
From: Niklas Holsti @ 2023-01-11 21:42 UTC (permalink / raw)


On 2023-01-11 23:04, Mace Ayres wrote:
> -- combinations.ads -- physical file
> with gearbox; use  gearbox;
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> with Term_IO;              use TERM_IO;
> with Text_IO;                use Text_IO;
> package combinations is
> ...
> col_is : Positive_Count ;  -- types from Text_IO
> row_is : Positive_Count ;
> procedure build;
> ...
> end combinations;
> -- *************************************
> -- combinations.adb -- physical file
> package body combination is
> ....
> procedure build is
> ..
> begin
> ...
> put(" Row is " );   put(row_is);
> put(" Column is "); put(col_is);
> ...
> end combinations;
> 
> -- *****************************
> compiler error
> line_no : no candidate interpretations match the actual:
>       missing argument for parameter 'Item' in call to "put"
>      ...
>    possible missing instantiation of Text_IO.Integer_IO
>    expected type "Standard Integer"
>    found type Ada.Text_IO.count


Thanks for showing the code (although it seems you have changed it since 
you asked the question originally).


> ____
> This is different error than before and I easily see Put() is
> expecting Integer but has the.. count type; so I need some sort of
> translation to satisfy put(), maybe with and use Text_IO.Integer_IO
> as error message suggest?


Well, yes. But note that the message says you should _instantiate_ 
Text_IO.Integer_IO, not "with" it. This is because Text_IO.Integer_IO is 
not its own library unit, but a generic package nested within Text_IO, 
which you already "withed". So the message suggests that you should do 
this, somewhere in the declaration part of the body of package combination:

    package Count_IO is new Text_IO.Integer_IO (Num => Positive_Count);

and then you can call

    Count_IO.Put (row_is);

and so forth. Or, if you add "use Count_IO" after the instantiation, you 
can write just Put (row_is).

However, the simplest method for occasional or debugging output is to 
use the 'Image attribute to convert a number to text, as for example

    Put (row_is'Image);

or (for older Ada versions)

   Put (Positive_Count'Image (row_is));

where the "Put" is the Put in Text_IO for strings. With 'Image, you 
don't need Text_IO.Integer_IO (but you have less control over the form 
of the output).

^ permalink raw reply	[relevance 0%]

* Re: Text_io package's Positive_Count type
  @ 2023-01-11 21:04  1%   ` Mace Ayres
  2023-01-11 21:42  0%     ` Niklas Holsti
  2023-01-11 21:46  1%     ` Jeffrey R.Carter
  0 siblings, 2 replies; 200+ results
From: Mace Ayres @ 2023-01-11 21:04 UTC (permalink / raw)


-- combinations.ads -- physical file
with gearbox; use  gearbox;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Term_IO;              use TERM_IO;
with Text_IO;                use Text_IO;
package combinations is
...
col_is : Positive_Count ;  -- types from Text_IO
row_is : Positive_Count ;
procedure build;
...
end combinations;
-- *************************************
-- combinations.adb -- physical file
package body combination is
....
procedure build is
..
begin
...
put(" Row is " );   put(row_is);
put(" Column is "); put(col_is);
...
end combinations;

-- *****************************
compiler error
line_no : no candidate interpretations match the actual:
     missing argument for parameter 'Item' in call to "put"
    ...
  possible missing instantiation of Text_IO.Integer_IO
  expected type "Standard Integer"
  found type Ada.Text_IO.count

____
This is different error than before and I easily see Put() is expecting Integer but has the.. count type; so I need some sort of translation to satisfy put(), maybe with and use Text_IO.Integer_IO as error message suggest?

^ permalink raw reply	[relevance 1%]

* Re: Is this my failure or of the compiler's debugger
  2023-01-11 13:43  1%     ` Niklas Holsti
@ 2023-01-11 16:52  0%       ` ldries46
  0 siblings, 0 replies; 200+ results
From: ldries46 @ 2023-01-11 16:52 UTC (permalink / raw)


Op 11-1-2023 om 14:43 schreef Niklas Holsti:
> On 2023-01-11 0:17, ldries46 wrote:
>> Op 10-1-2023 om 19:12 schreef Niklas Holsti:
>>> On 2023-01-10 15:16, ldries46 wrote:
>>>> I try to create a program that read Unbounded strings from a file 
>>>> in the loop:
>>>>        Open(C_File, In_File, To_String(Inp_File));
>>>>        while not End_of_File(C_File) loop
>>>>           str_line_n := To_Unbounded_String(Get_Line(C_File));
>>>>           Buffer_GL.Set_Buffer(str_line_n); -- breakpoint on this line
>>>>           glade_lines := glade_lines + 1;
>>>>        end loop;
>>>>        Close(C_File);
>>>> where str_line_n is of the type Unbounded_String.
>>>> I used a test file with the below presented three text lines:
>>>> Line 1 abcdef9876543210
>>>> Line 2 " abcdef"9876543210
>>>> Line 3 "abc"de"f"9876543210
>>>>
>>>> In the debugger the results were:
>>>> "Line 1 abcdef 9876543210"
>>>> "Line 2 "" abcdef"" 98765432"
>>>> "Line 3 ""abc""de ""f""987654"
>>>
>>>
>>> It seems that the debugger displays the strings in the form of Ada 
>>> string literals, which are enclosed in quotes (") and within which 
>>> each quote character has to be duplicated (to show that it is not 
>>> the terminating quote). So the duplication of the quotes is nothing 
>>> to worry about. If you were to print out the strings (with 
>>> Ada.Text_IO) they should appear just as in the input, with only the 
>>> original quote characters.
>>>
>>> However, your example also shows some extra blank spaces in the 
>>> debugger output, for example:
>>>
>>> Input   : Line 1 abcdef9876543210
>>> Debugger: "Line 1 abcdef 9876543210"
>>>
>>>
>>>
>> Not only that but also some of the  last characters disappear in line 
>> 2 the 10 and in line 3 3210
>
>
> My guess is that these differences are bugs in the debugger's display 
> of strings with embedded quote characters. For Line 1, which has no 
> embedded quotes, the full string is displayed (though with an inserted 
> blank). For Line 2, with two embedded quotes, two of the last 
> characters are not displayed. For Line 3, with four embedded quotes, 
> four of the last characters are not displayed. It seems that the 
> debugger does not realize that doubling the quote characters makes the 
> displayed string longer...
>
> Try to print the strings with Ada.Text_IO instead, that should give 
> the right result. In other words, your code reading the strings works, 
> but the debugger is probably buggy. (One reason why I avoid debuggers 
> whenever I can.)
>
That is also my guess but I like to use the debugger because You stop 
running the program anywhere you want and check all parameters you think 
are nice to know. Now you have to add a lot of code and still see that 
you need tyo know another parameter and run the program over and over 
again each time with other code added.

^ permalink raw reply	[relevance 0%]

* Re: Is this my failure or of the compiler's debugger
  2023-01-10 22:17  0%   ` ldries46
  2023-01-11  7:40  0%     ` ldries46
@ 2023-01-11 13:43  1%     ` Niklas Holsti
  2023-01-11 16:52  0%       ` ldries46
  1 sibling, 1 reply; 200+ results
From: Niklas Holsti @ 2023-01-11 13:43 UTC (permalink / raw)


On 2023-01-11 0:17, ldries46 wrote:
> Op 10-1-2023 om 19:12 schreef Niklas Holsti:
>> On 2023-01-10 15:16, ldries46 wrote:
>>> I try to create a program that read Unbounded strings from a file in 
>>> the loop:
>>>        Open(C_File, In_File, To_String(Inp_File));
>>>        while not End_of_File(C_File) loop
>>>           str_line_n := To_Unbounded_String(Get_Line(C_File));
>>>           Buffer_GL.Set_Buffer(str_line_n); -- breakpoint on this line
>>>           glade_lines := glade_lines + 1;
>>>        end loop;
>>>        Close(C_File);
>>> where str_line_n is of the type Unbounded_String.
>>> I used a test file with the below presented three text lines:
>>> Line 1 abcdef9876543210
>>> Line 2 " abcdef"9876543210
>>> Line 3 "abc"de"f"9876543210
>>>
>>> In the debugger the results were:
>>> "Line 1 abcdef 9876543210"
>>> "Line 2 "" abcdef"" 98765432"
>>> "Line 3 ""abc""de ""f""987654"
>>
>>
>> It seems that the debugger displays the strings in the form of Ada 
>> string literals, which are enclosed in quotes (") and within which 
>> each quote character has to be duplicated (to show that it is not the 
>> terminating quote). So the duplication of the quotes is nothing to 
>> worry about. If you were to print out the strings (with Ada.Text_IO) 
>> they should appear just as in the input, with only the original quote 
>> characters.
>>
>> However, your example also shows some extra blank spaces in the 
>> debugger output, for example:
>>
>> Input   : Line 1 abcdef9876543210
>> Debugger: "Line 1 abcdef 9876543210"
>>
>>
>>
> Not only that but also some of the  last characters disappear in line 2 
> the 10 and in line 3 3210


My guess is that these differences are bugs in the debugger's display of 
strings with embedded quote characters. For Line 1, which has no 
embedded quotes, the full string is displayed (though with an inserted 
blank). For Line 2, with two embedded quotes, two of the last characters 
are not displayed. For Line 3, with four embedded quotes, four of the 
last characters are not displayed. It seems that the debugger does not 
realize that doubling the quote characters makes the displayed string 
longer...

Try to print the strings with Ada.Text_IO instead, that should give the 
right result. In other words, your code reading the strings works, but 
the debugger is probably buggy. (One reason why I avoid debuggers 
whenever I can.)

^ permalink raw reply	[relevance 1%]

* Re: Is this my failure or of the compiler's debugger
  2023-01-10 22:17  0%   ` ldries46
@ 2023-01-11  7:40  0%     ` ldries46
  2023-01-11 13:43  1%     ` Niklas Holsti
  1 sibling, 0 replies; 200+ results
From: ldries46 @ 2023-01-11  7:40 UTC (permalink / raw)


Op 10-1-2023 om 23:17 schreef ldries46:
> Op 10-1-2023 om 19:12 schreef Niklas Holsti:
>> On 2023-01-10 15:16, ldries46 wrote:
>>> I try to create a program that read Unbounded strings from a file in 
>>> the loop:
>>>        Open(C_File, In_File, To_String(Inp_File));
>>>        while not End_of_File(C_File) loop
>>>           str_line_n := To_Unbounded_String(Get_Line(C_File));
>>>           Buffer_GL.Set_Buffer(str_line_n); -- breakpoint on this line
>>>           glade_lines := glade_lines + 1;
>>>        end loop;
>>>        Close(C_File);
>>> where str_line_n is of the type Unbounded_String.
>>> I used a test file with the below presented three text lines:
>>> Line 1 abcdef9876543210
>>> Line 2 " abcdef"9876543210
>>> Line 3 "abc"de"f"9876543210
>>>
>>> In the debugger the results were:
>>> "Line 1 abcdef 9876543210"
>>> "Line 2 "" abcdef"" 98765432"
>>> "Line 3 ""abc""de ""f""987654"
>>
>>
>> It seems that the debugger displays the strings in the form of Ada 
>> string literals, which are enclosed in quotes (") and within which 
>> each quote character has to be duplicated (to show that it is not the 
>> terminating quote). So the duplication of the quotes is nothing to 
>> worry about. If you were to print out the strings (with Ada.Text_IO) 
>> they should appear just as in the input, with only the original quote 
>> characters.
>>
>> However, your example also shows some extra blank spaces in the 
>> debugger output, for example:
>>
>> Input   : Line 1 abcdef9876543210
>> Debugger: "Line 1 abcdef 9876543210"
>>
>>
>>
> Not only that but also some of the  last characters disappear in line 
> 2 the 10 and in line 3 3210
In the mean time by inserting a write command to a Gtk window I found 
that the problem is really a problem of the debugger. The values in the 
Gtk window are correct. this means that in a next version of the 
debugger that must be corrected

^ permalink raw reply	[relevance 0%]

* Re: Is this my failure or of the compiler's debugger
  2023-01-10 18:12  1% ` Is this my failure or of the compiler's debugger Niklas Holsti
@ 2023-01-10 22:17  0%   ` ldries46
  2023-01-11  7:40  0%     ` ldries46
  2023-01-11 13:43  1%     ` Niklas Holsti
  0 siblings, 2 replies; 200+ results
From: ldries46 @ 2023-01-10 22:17 UTC (permalink / raw)


Op 10-1-2023 om 19:12 schreef Niklas Holsti:
> On 2023-01-10 15:16, ldries46 wrote:
>> I try to create a program that read Unbounded strings from a file in 
>> the loop:
>>        Open(C_File, In_File, To_String(Inp_File));
>>        while not End_of_File(C_File) loop
>>           str_line_n := To_Unbounded_String(Get_Line(C_File));
>>           Buffer_GL.Set_Buffer(str_line_n); -- breakpoint on this line
>>           glade_lines := glade_lines + 1;
>>        end loop;
>>        Close(C_File);
>> where str_line_n is of the type Unbounded_String.
>> I used a test file with the below presented three text lines:
>> Line 1 abcdef9876543210
>> Line 2 " abcdef"9876543210
>> Line 3 "abc"de"f"9876543210
>>
>> In the debugger the results were:
>> "Line 1 abcdef 9876543210"
>> "Line 2 "" abcdef"" 98765432"
>> "Line 3 ""abc""de ""f""987654"
>
>
> It seems that the debugger displays the strings in the form of Ada 
> string literals, which are enclosed in quotes (") and within which 
> each quote character has to be duplicated (to show that it is not the 
> terminating quote). So the duplication of the quotes is nothing to 
> worry about. If you were to print out the strings (with Ada.Text_IO) 
> they should appear just as in the input, with only the original quote 
> characters.
>
> However, your example also shows some extra blank spaces in the 
> debugger output, for example:
>
> Input   : Line 1 abcdef9876543210
> Debugger: "Line 1 abcdef 9876543210"
>
>
>
Not only that but also some of the  last characters disappear in line 2 
the 10 and in line 3 3210

^ permalink raw reply	[relevance 0%]

* Re: Is this my failure or of the compiler's debugger
       [not found]     <nnd$70b29fcd$4811e339@5bc1ef990a7003a8>
@ 2023-01-10 18:12  1% ` Niklas Holsti
  2023-01-10 22:17  0%   ` ldries46
  0 siblings, 1 reply; 200+ results
From: Niklas Holsti @ 2023-01-10 18:12 UTC (permalink / raw)


On 2023-01-10 15:16, ldries46 wrote:
> I try to create a program that read Unbounded strings from a file in the 
> loop:
>        Open(C_File, In_File, To_String(Inp_File));
>        while not End_of_File(C_File) loop
>           str_line_n := To_Unbounded_String(Get_Line(C_File));
>           Buffer_GL.Set_Buffer(str_line_n); -- breakpoint on this line
>           glade_lines := glade_lines + 1;
>        end loop;
>        Close(C_File);
> where str_line_n is of the type Unbounded_String.
> I used a test file with the below presented three text lines:
> Line 1 abcdef9876543210
> Line 2 " abcdef"9876543210
> Line 3 "abc"de"f"9876543210
> 
> In the debugger the results were:
> "Line 1 abcdef 9876543210"
> "Line 2 "" abcdef"" 98765432"
> "Line 3 ""abc""de ""f""987654"


It seems that the debugger displays the strings in the form of Ada 
string literals, which are enclosed in quotes (") and within which each 
quote character has to be duplicated (to show that it is not the 
terminating quote). So the duplication of the quotes is nothing to worry 
about. If you were to print out the strings (with Ada.Text_IO) they 
should appear just as in the input, with only the original quote characters.

However, your example also shows some extra blank spaces in the debugger 
output, for example:

Input   : Line 1 abcdef9876543210
Debugger: "Line 1 abcdef 9876543210"

There seems to be a new blank space between 'f' and '9'. Are you sure 
that you presented the input and output correctly?

^ permalink raw reply	[relevance 1%]

* Variable value if exception is raised
@ 2022-11-20 18:03  1% nytpu
  0 siblings, 0 replies; 200+ results
From: nytpu @ 2022-11-20 18:03 UTC (permalink / raw)


Hello everyone,

If an exception is *explicitly* raised during a variable assignment, what 
happens to the variable contents?  Are they in an undefined ("abnormal") 
state, or are the previous contents preserved?

For example:
```
with Ada.Text_IO;
procedure Test is
    function Always_Raises return Integer is
    begin
        raise Program_Error;
        return 1;
    end Always_Raises;
    
    I : Integer := 0;
begin
    -- insert a nested handler, because the ARM § 11.4 ¶ 3 *does*
    -- say that the currently executing body is "abnormally
    -- completed" (including finalizing everything) before
    -- entering the exception handler
    begin
        I := Always_Raises;
    exception
        when others => null;
    end;
    Ada.Text_IO.Put_Line(Integer'Image(I));
end;
```
What, if anything, will be printed?  (Disclaimer: I know the preexisting 
variable value will be preserved in GNAT specifically, but I'm asking if 
the standard guarantees that's the case)

I read through the ARM 2012 § 11 and § 5.2, as well as skimming through 
everything related to “assignment” and “exceptions” in the ARM index;
and didn't see much relating to this.  All I saw is this:
> When an exception occurrence is raised by the execution of a given 
> construct, the rest of the execution of that construct is abandoned
— ARM 2012 § 11.4 ¶ 3
Which I guess implicitly protects variable values since assigning to a 
variable is performed after evaluating the right hand side, but still not 
necessarily a clear answer.

I did see in § 13.9.1 that language-defined validity checks (e.g. bounds 
checks) failing or calling `abort` in a task during an assignment will 
cause the variable to enter an "abnormal" (i.e. invalid) state, but that 
doesn't cover user-raised exceptions.

-- 
~nytpu

^ permalink raw reply	[relevance 1%]

* Re: Bold text (in terminal) from Ada?
  @ 2022-10-11  8:49  1% ` Niklas Holsti
  0 siblings, 0 replies; 200+ results
From: Niklas Holsti @ 2022-10-11  8:49 UTC (permalink / raw)


On 2022-10-11 11:06, reinert wrote:
> Any simple way to print out bold text from an Ada program?
> In case, how?
> 
> Assume linux.
> 
> reinert


Print the corresponding ANSI control sequence to turn on bold mode 
before you print the text, then print the ANSI control sequence to turn 
off bold mode.

See https://www.linux.org/threads/ansi-codes-and-colorized-terminals.11706/.

Example:

with Ada.Characters.Latin_1;
with Ada.Text_IO;
procedure Be_Bold
is
    use Ada.Characters, Ada.Text_IO;
begin
    Put ("This is a very ");
    -- Bold mode:
    Put (Latin_1.ESC); Put ("[1m");
    Put ("bold");
    -- Normal mode:
    Put (Latin_1.ESC); Put ("[0m");
    Put_Line (" program.");
end Be_Bold;


^ permalink raw reply	[relevance 1%]

* Re: Compiler error (2) ?
  2022-09-26  8:47  1%   ` reinert
@ 2022-09-26  9:59  0%     ` reinert
  0 siblings, 0 replies; 200+ results
From: reinert @ 2022-09-26  9:59 UTC (permalink / raw)


Sorry for some typos in my latest post, but the intelligent reader should understand :-)

reinert

mandag 26. september 2022 kl. 10:47:16 UTC+2 skrev reinert:
> This is what I (also) get: 
> 
> test1a.adb:16:42: error: expected type "Standard.Integer" 
> test1a.adb:16:42: error: found type "Ada.Containers.Count_Type" 
> 
> compilation of test1a.adb failed 
> 
> gprbuild: *** compilation phase failed 
> error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/reinert/test1a/test1a.gpr"] exited with code 4 
> error: Compilation failed. 
> --------------------------------------------------------------------------------------------------- 
> **However, the following version goes through the compiler and runs 
> (using "subtype n_t is Positive range 3..Positive'Last;" for)
> in the package specification) - confirming what Simon says: 
> 
> with Ada.Text_IO; 
> with Ada.Containers.Vectors; 
> procedure test1a is 
> type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9); 
> for s_name_type use 
> (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4, 
> S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
> subtype n_t is Positive range 3..Positive'Last;
> package s_names_p is new Ada.Containers.Vectors
> (Index_Type => n_t, Element_Type => s_name_type); 
> k : integer := 7;
> n : constant integer := 7;
> -- n : constant integer := k; -- uncomment this line and comment out the line above.
> s_names: constant s_names_p.Vector := [for i in 3..n => S0]; 
> begin 
> Ada.Text_IO.Put_Line(s_names'Image); 
> end test1a;
> reinert
> mandag 26. september 2022 kl. 10:34:18 UTC+2 skrev J-P. Rosen: 
> > Please give the exact error message, and why you think it could be a 
> > compiler error. Otherwise, it's hard to help... 
> > Le 26/09/2022 à 08:54, reinert a écrit : 
> > > Hello, 
> > > 
> > > This must reveal a compiler error : 
> > > ------------------------------------------------------------------------------------------------------- 
> > > with Ada.Text_IO; 
> > > with Ada.Containers.Vectors; 
> > > procedure test1a is 
> > > type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9); 
> > > for s_name_type use 
> > > (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4, 
> > > S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9); 
> > > package s_names_p is new Ada.Containers.Vectors 
> > > (Index_Type => Positive, Element_Type => s_name_type); 
> > > k : integer := 7; 
> > > 
> > > -- n : constant integer := 7; -- uncomment this line and comment out the line below. 
> > > n : constant integer := k; 
> > > 
> > > s_names: constant s_names_p.Vector := [for i in 3..n => S0]; 
> > > begin 
> > > Ada.Text_IO.Put_Line(s_names'Image); 
> > > end test1a; 
> > > ------------------------------------------------------------------------------------------------------- 
> > > (compiled using alire and 
> > > package Compiler is 
> > > for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv"); 
> > > end Compiler; 
> > > ------------------------------------------------------------------------------------------------------- 
> > > 
> > > Right? 
> > > 
> > > reinert 
> > -- 
> > J-P. Rosen 
> > Adalog 
> > 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX 
> > Tel: +33 1 45 29 21 52 
> > https://www.adalog.fr

^ permalink raw reply	[relevance 0%]

* Re: A new universe of Ada
  @ 2022-09-26  9:16  1%         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2022-09-26  9:16 UTC (permalink / raw)


On 2022-09-26 10:04, Rick Duley wrote:
> Okay - you can use GDB within Studio.  Great, but first I have to write a program.
> 
> Please ...
> 
> Assume:  I am an Elementary School kid brought up by his Grandparents who are still struggling to control an abacus.  Assume I know absolutely nothing at all about programming.  Assume that I do not speak Geek!  Assume that there is access to a PC with Gnat Studio installed.
> 
> Now:  Teach me how to write "Hello_World" using Studio from scratch right up to where I have 'hello_world.exe' and can run it.  That'll be great!  Then I'll have something to tell Grandma about.  :)

1. Start GPS

2. Select default project

3. Press File->New file

4. Type:
project Hello_World is
    for Main use ("hello_world.adb");
end Hello_World;

5. File->Save as
hello_world.gpr

6. Press File->New file

7. Type:
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello_World is
begin
    Put_Line ("Hello world!");
end Hello_World;

8. File->Save as
hello_world.adb

9. Press File->Open Project and select file hello_world.gpr


You are done.

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

^ permalink raw reply	[relevance 1%]

* Re: Compiler error (2) ?
  2022-09-26  8:34  0% ` J-P. Rosen
@ 2022-09-26  8:47  1%   ` reinert
  2022-09-26  9:59  0%     ` reinert
  0 siblings, 1 reply; 200+ results
From: reinert @ 2022-09-26  8:47 UTC (permalink / raw)


This is what I (also) get:

test1a.adb:16:42: error: expected type "Standard.Integer"
test1a.adb:16:42: error: found type "Ada.Containers.Count_Type"

   compilation of test1a.adb failed

gprbuild: *** compilation phase failed
error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/reinert/test1a/test1a.gpr"] exited with code 4
error: Compilation failed.
---------------------------------------------------------------------------------------------------
**However, the following version goes through the compiler and runs 
(using "subtype n_t is Positive range 3..Positive'Last;" for)
in the package specification) - confirming what Simon says:

with Ada.Text_IO;
with Ada.Containers.Vectors;
procedure test1a is
   type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
   for s_name_type use
      (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
       S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
   subtype n_t is Positive range 3..Positive'Last;
   package s_names_p is new Ada.Containers.Vectors
     (Index_Type => n_t, Element_Type => s_name_type);
   k : integer := 7;

   n : constant integer := 7; 
 --  n : constant integer := k; -- uncomment this line and comment out the line above.

   s_names: constant s_names_p.Vector := [for i in 3..n => S0];
begin
   Ada.Text_IO.Put_Line(s_names'Image);
end test1a;


reinert




mandag 26. september 2022 kl. 10:34:18 UTC+2 skrev J-P. Rosen:
> Please give the exact error message, and why you think it could be a 
> compiler error. Otherwise, it's hard to help...
> Le 26/09/2022 à 08:54, reinert a écrit : 
> > Hello, 
> > 
> > This must reveal a compiler error : 
> > ------------------------------------------------------------------------------------------------------- 
> > with Ada.Text_IO; 
> > with Ada.Containers.Vectors; 
> > procedure test1a is 
> > type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9); 
> > for s_name_type use 
> > (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4, 
> > S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9); 
> > package s_names_p is new Ada.Containers.Vectors 
> > (Index_Type => Positive, Element_Type => s_name_type); 
> > k : integer := 7; 
> > 
> > -- n : constant integer := 7; -- uncomment this line and comment out the line below. 
> > n : constant integer := k; 
> > 
> > s_names: constant s_names_p.Vector := [for i in 3..n => S0]; 
> > begin 
> > Ada.Text_IO.Put_Line(s_names'Image); 
> > end test1a; 
> > ------------------------------------------------------------------------------------------------------- 
> > (compiled using alire and 
> > package Compiler is 
> > for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv"); 
> > end Compiler; 
> > ------------------------------------------------------------------------------------------------------- 
> > 
> > Right? 
> > 
> > reinert
> -- 
> J-P. Rosen 
> Adalog 
> 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX 
> Tel: +33 1 45 29 21 52 
> https://www.adalog.fr

^ permalink raw reply	[relevance 1%]

* Re: Compiler error (2) ?
  2022-09-26  6:54  1% Compiler error (2) ? reinert
@ 2022-09-26  8:34  0% ` J-P. Rosen
  2022-09-26  8:47  1%   ` reinert
  0 siblings, 1 reply; 200+ results
From: J-P. Rosen @ 2022-09-26  8:34 UTC (permalink / raw)


Please give the exact error message, and why you think it could be a 
compiler error. Otherwise, it's hard to help...

Le 26/09/2022 à 08:54, reinert a écrit :
> Hello,
> 
> This must reveal a compiler error :
> -------------------------------------------------------------------------------------------------------
> with Ada.Text_IO;
> with Ada.Containers.Vectors;
> procedure test1a is
>     type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
>     for s_name_type use
>        (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
>         S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
>     package s_names_p is new Ada.Containers.Vectors
>       (Index_Type => Positive, Element_Type => s_name_type);
>     k : integer := 7;
> 
> -- n : constant integer := 7; -- uncomment this line and comment out the line below.
>     n : constant integer := k;
> 
>     s_names: constant s_names_p.Vector := [for i in 3..n => S0];
> begin
>     Ada.Text_IO.Put_Line(s_names'Image);
> end test1a;
> -------------------------------------------------------------------------------------------------------
> (compiled using alire and
> package Compiler is
>        for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv");
>     end Compiler;
> -------------------------------------------------------------------------------------------------------
> 
> Right?
> 
> reinert

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


^ permalink raw reply	[relevance 0%]

* Re: A new universe of Ada
  2022-09-26  6:45  1% ` Dmitry A. Kazakov
@ 2022-09-26  7:00  0%   ` Rick Duley
    1 sibling, 0 replies; 200+ results
From: Rick Duley @ 2022-09-26  7:00 UTC (permalink / raw)


On Monday, September 26, 2022 at 2:45:16 PM UTC+8, Dmitry A. Kazakov wrote:
> On 2022-09-26 08:20, Rick Duley wrote: 
> 
> > I have Gnat Studio but I can't do anything at all unless I create a Project (whatever that is). Even then, I can't write and run Hello_World unless I call it Main. The concept of an IDE where I can step through a program checking changes in variable values as I go seems to have vanished.
> That concept is called debugger. GDB for GCC (GNAT Ada is based in GDB). 
> GDB never ever really worked except for little exercises. It still does 
> not. So, forget about it.
> > In short, I am lost and I can't find any material to help me find my way.
> The project file is 3-liner: 
> ----------------hello_world.gpr-----> 
> project Hello_World is 
> for Main use ("hello_world.adb"); 
> end Hello_World; 
> <------------------------------------ 
> 
> No, you do not need main to be Main: 
> 
> ---hello_world.adb-----------------> 
> with Ada.Text_IO; use Ada.Text_IO; 
> procedure Hello_World is 
> begin 
> Put_Line ("Hello world!"); 
> end Hello_World; 
> <---------------------------------- 
> 
> You still can compile and build without projects. But projects are much 
> more comfortable. 
> 
> -- 
> Regards, 
> Dmitry A. Kazakov 
> http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Compiler error (2) ?
@ 2022-09-26  6:54  1% reinert
  2022-09-26  8:34  0% ` J-P. Rosen
  0 siblings, 1 reply; 200+ results
From: reinert @ 2022-09-26  6:54 UTC (permalink / raw)


Hello,

This must reveal a compiler error :
-------------------------------------------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Containers.Vectors;
procedure test1a is
   type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
   for s_name_type use
      (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
       S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
   package s_names_p is new Ada.Containers.Vectors
     (Index_Type => Positive, Element_Type => s_name_type);
   k : integer := 7;

-- n : constant integer := 7; -- uncomment this line and comment out the line below.
   n : constant integer := k; 

   s_names: constant s_names_p.Vector := [for i in 3..n => S0];
begin
   Ada.Text_IO.Put_Line(s_names'Image);
end test1a;
-------------------------------------------------------------------------------------------------------
(compiled using alire and  
package Compiler is
      for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv");
   end Compiler;
-------------------------------------------------------------------------------------------------------

Right?

reinert

^ permalink raw reply	[relevance 1%]

* Re: A new universe of Ada
  @ 2022-09-26  6:45  1% ` Dmitry A. Kazakov
  2022-09-26  7:00  0%   ` Rick Duley
    0 siblings, 2 replies; 200+ results
From: Dmitry A. Kazakov @ 2022-09-26  6:45 UTC (permalink / raw)


On 2022-09-26 08:20, Rick Duley wrote:

> I have Gnat Studio but I can't do anything at all unless I create a Project (whatever that is).  Even then, I can't write and run Hello_World unless I call it Main.  The concept of an IDE where I can step through a program checking changes in variable values as I go seems to have vanished.

That concept is called debugger. GDB for GCC (GNAT Ada is based in GDB). 
GDB never ever really worked except for little exercises. It still does 
not. So, forget about it.

> In short, I am lost and I can't find any material to help me find my way.

The project file is 3-liner:
----------------hello_world.gpr----->
project Hello_World is
    for Main use ("hello_world.adb");
end Hello_World;
<------------------------------------

No, you do not need main to be Main:

---hello_world.adb----------------->
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello_World is
begin
    Put_Line ("Hello world!");
end Hello_World;
<----------------------------------

You still can compile and build without projects. But projects are much 
more comfortable.

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

^ permalink raw reply	[relevance 1%]

* Re: Non-standard functions in GNAT's Ada.Containers packages?
  @ 2022-09-16 17:08  1%                 ` Jere
  0 siblings, 0 replies; 200+ results
From: Jere @ 2022-09-16 17:08 UTC (permalink / raw)


On Friday, September 16, 2022 at 12:30:51 PM UTC-4, amado...@gmail.com wrote:
> Jere, ehh.p..., thanks a lot, your complete code was very helpful. 
> For some reason I tried to write for maps as for vectors and it did not pass. 
> I see now some forms do pass. 
> Sorry for the entropy. 
> As you note, still not possible to access the Key with the "of" form. 
> 
> /* 
> And the form
> for (C : My_Maps.Cursor) of My_Map.Iterate loop
> does not pass. Must be "in" 
> */ 
> 
> Thanks all.
 No problem at all.  Yeah, all the standard Ada containers use the "of" form to iterate
over elements and the "in" form to iterate over cursors.  Keys are more like cursors 
from the perspective of the container, so you would need to use some form of "in" 
to get the keys.  

for what it is worth, the example I gave is usable for vectors.  you have to change
names and use append() instead of insert(), but the rest is pretty similar:

*******************************************
    with Ada.Text_IO; use Ada.Text_IO;
    with Ada.Containers.Vectors;
     
    procedure Program is
        package Vectors is new Ada.Containers.Vectors(Positive,Integer);
     
        Vector : Vectors.Vector;
     
    begin
     
        Vector.Append(10);
        Vector.Append(20);
        Vector.Append(30);
        Vector.Append(40);
     
        for Element of Vector loop
            Put_Line(Element'Image);
        end loop;   
    end Program;
**********************************************
Output:
10
 20
 30
 40
*******************************************
IDEONE compiler link:  https://ideone.com/3Ic49d#stdout

So it may depend on how your vector code was originally setup.  
The above is how I typically loop through a vector, which works
for maps and other Ada containers as well.  

Hope that helps!

^ permalink raw reply	[relevance 1%]

* Re: Non-standard functions in GNAT's Ada.Containers packages?
      @ 2022-09-16 15:47  1%           ` Jere
  2 siblings, 0 replies; 200+ results
From: Jere @ 2022-09-16 15:47 UTC (permalink / raw)


On Thursday, September 15, 2022 at 1:11:19 PM UTC-4, amado...@gmail.com wrote:
> Thanks, Niklas. 
> 
> > ... There are functions First and Next ... procedure Iterate ... 
> 
> Too verbose and error-prone (forget the Next and you get an endless loop).
> > "for X of M loop ... end loop".
> Not possible for maps.

I'm not sure I understand.  I tried it in gnat 11 and it compiled just fine:
*************************************************
    with Ada.Text_IO; use Ada.Text_IO;
    with Ada.Containers.Ordered_Maps;
     
    procedure Program is
        package Maps is new Ada.Containers.Ordered_Maps(Integer,Integer);
     
        Map : Maps.Map;
     
    begin
     
        Map.Insert(1,10);
        Map.Insert(2,20);
        Map.Insert(3,30);
        Map.Insert(4,40);
     
        for Element of Map loop
            Put_Line(Element'Image);
        end loop;   
    end Program;
*************************************************
Output:
10
 20
 30
 40
*************************************************

Even tried it on some online compilers and it compiled and ran:
IDEONE online compiler:  https://ideone.com/H2oEZt

If this isn't what you mean, what is the missing feature.?  the "for of" version does work for maps as far as I can tell.

^ permalink raw reply	[relevance 1%]

* Re: Non-standard functions in GNAT's Ada.Containers packages?
  @ 2022-09-16 15:42  1%               ` Egil H H
  0 siblings, 0 replies; 200+ results
From: Egil H H @ 2022-09-16 15:42 UTC (permalink / raw)


On Friday, September 16, 2022 at 5:00:29 PM UTC+2, amado...@gmail.com wrote:
> > >> "for X of M loop ... end loop". 
> > > 
> > > Not possible for maps. 
> > but you can as 
> > >https://programming-idioms.org/idiom/13/iterate-over-map-keys-and-value/1511/ada> 
> >
> > with Ada.Containers.Indefinite_Hashed_Maps; 
> > with Ada.Strings.Hash; 
> > use Ada.Containers; 
> > for C in My_Map.Iterate loop 
> > Put_Line ("Key = " & Key (C) & ", Value = " & Element (C)); 
> > end loop;
> Thanks, but this is "in", not "of", requires cursors, and DOES NOT COMPILE, as probably needs like ten lines of boiler plate not show.

(sorry for any botched formatting...)

with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;
with Ada.Text_IO;

procedure Iteration is
   package My_Maps is 
      new Ada.Containers.Indefinite_Hashed_Maps
         (String, Integer, Ada.Strings.Hash, "=");
   
   My_Map : My_Maps.Map;
begin
   My_Map.Include("One", 1);
   My_Map.Include("Two", 2);
   My_Map.Include("Three", 3);

   for C in My_Map.Iterate loop
      Ada.Text_IO.Put_Line(My_Maps.Key(C) & My_Maps.Element(C)'Image);
   end loop;
   
   for Element of My_Map loop
      Ada.Text_IO.Put_Line(Element'Image);
   end loop;
   
   -- Ada_2022:
   -- for (C : My_Maps.Cursor) of My_Map.Iterate loop
   --    Ada.Text_IO.Put_Line(My_Maps.Key(C) & My_Maps.Element(C)'Image);
   -- end loop Ada_2022;
   
end Iteration;

I don't know why they left out a two-parameter version of the Iterate procedure for Ada 2022 Maps,
   -- for (Key, Element) of My_Map.Iterate loop
would've been nice, just like
   -- for (Name, Val) of Ada.Environment_Variables.Iterate(<>) loop



^ permalink raw reply	[relevance 1%]

* Struggling to use fonts in SDLAda
@ 2022-09-12 22:43  1% Troy Jacobs
  0 siblings, 0 replies; 200+ results
From: Troy Jacobs @ 2022-09-12 22:43 UTC (permalink / raw)


I'm relatively new to programming with Ada, and as I've been learning the language I decided to try making a simple 2D game with it to apply what I learn about Ada. After unsuccessfully attempting to make my own binding to SDL2, I decided to simply use the SDLAda package because it seemed well put together.

However, I've been running into this issue while trying to render text where the program fails at runtime because it failed to load the font. I've been desperately scouring the web & my code for a solution ever since to no avail. As I am newish to Ada, I don't know the GNAT tools well enough to pinpoint what could be causing the problem.

Below is my .gpr file, Ada source file, and the message produced when I try to run it through Alire.
.gpr file:

    with "config/coolgame1_config.gpr";

    project Coolgame1 is

    for Source_Dirs use ("src/", "config/");

    for Object_Dir use "obj/" & Coolgame1_Config.Build_Profile;

    for Create_Missing_Dirs use "True";

    for Exec_Dir use "bin";

    for Main use ("coolgame1.adb");

    package Compiler is

    for Default_Switches ("Ada") use Coolgame1_Config.Ada_Compiler_Switches;

    end Compiler;

    package Linker is

    for Default_Switches ("Ada") use ("-lSDL2", "-lSDL2_ttf");

    end Linker;

    package Binder is

    for Switches ("Ada") use ("-Es"); -- Symbolic traceback

    end Binder;

    package Install is

    for Artifacts (".") use ("share");

    end Install;

    end Coolgame1;

Ada Source File (abridged for clarity:)

    with SDL;

    with SDL.Video.Renderers.Makers;

    with SDL.Video.Textures.Makers;

    with SDL.Video.Windows.Makers;

    with SDL.Video.Pixel_Formats;

    with SDL.Events.Events;

    with SDL.Events.Keyboards;

    with SDL.TTFs.Makers;

    with SDL.Video.Palettes;

    with SDL.Video.Surfaces;

    with Ada.Directories;

    with Ada.Text_IO;

    with SDL.Rwops;

    procedure Coolgame1 is

    window_size : constant SDL.Positive_Sizes := SDL.Positive_Sizes'(800, 600);

    window : SDL.Video.Windows.Window;

    renderer : SDL.Video.Renderers.Renderer;

    texture : SDL.Video.Textures.Texture;

    font_path : constant String := "resources/fonts/kunika_2.0/fonts/OpenType-TT/Kunika-Regular.ttf";

    font : SDL.TTFs.Fonts;

    text_surface : SDL.Video.Surfaces.Surface;

    begin

    if SDL.Initialise = True and then SDL.TTFs.Initialise = True then

    Ada.Text_IO.Put_Line("Ada directory:");

    Ada.Text_IO.Put_Line(Ada.Directories.Current_Directory);

    Ada.Text_IO.Put_Line("SDL2 directory:");

    Ada.Text_IO.Put_Line(SDL.Rwops.Base_Path);

    SDL.Video.Windows.Makers.Create(

    Win => window,

    Title => "HITBOXERS",

    Position => SDL.Natural_Coordinates'(X => 300, Y => 300),

    Size => window_size,

    Flags => SDL.Video.Windows.Resizable

    );

    SDL.Video.Renderers.Makers.Create(renderer, window);

    SDL.Video.Textures.Makers.Create(

    Tex => texture,

    Renderer => renderer,

    Format => SDL.Video.Pixel_Formats.Pixel_Format_ARGB_8888,

    Kind => SDL.Video.Textures.Streaming,

    Size => window_size

    );

    -- get font

    SDL.TTFs.Makers.Create(font, font_path, 1, 40);

    -- create surface for font

    text_surface := SDL.TTFs.Render_Shaded(

    Self => font,

    Text => "Yolo",

    Colour => SDL.Video.Palettes.Colour'(Red => 98, Green => 236, Blue => 120, Alpha => 255),

    Background_Colour => SDL.Video.Palettes.Colour'(Red => 236, Green => 203, Blue => 98, Alpha => 255)

    );

    renderer.Clear;

    renderer.Copy(texture);

    renderer.Present;

    end loop;

    end;

    window.Finalize;

    SDL.TTFs.Finalise;

    SDL.Finalise;

    end if;

    end Coolgame1;

Output:

    PS C:\Users\usernamehere\coolgame1> alr run

    Note: Building coolgame1/coolgame1.gpr...

    gprbuild: "coolgame1.exe" up to date

    Build finished successfully in 2.09 seconds.

    Ada directory:

    C:\Users\usernamehere\coolgame1

    SDL2 directory:

    C:\Users\usernamehere\coolgame1\bin\

    raised SDL.TTFS.TTF_ERROR : Couldn't load font file

    [C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]

    0x7ff69aff0089 ??? at ???

    [C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]

    0x7ff69afeffbb ??? at ???

    [C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]

    0x7ff69afebf10 ??? at ???

    [C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]

    0x7ff69affffe9 ??? at ???

    [C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]

    0x7ff69af9143d ??? at ???

    [C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]

    0x7ff69af91144 ??? at ???

    [C:\WINDOWS\System32\KERNEL32.DLL]

    0x7ffcf2397032

    [C:\WINDOWS\SYSTEM32\ntdll.dll]

    0x7ffcf384264f

And before you ask, the problem is not the font being in the wrong directory. I've confirmed this by moving the file around and reading the source code for both SDLAda & SDL_ttf.

I'll do my best to respond as much as I possibly can to questions. Thank you to anyone who is able to help.

^ permalink raw reply	[relevance 1%]

* Is this an error in compiler?
@ 2022-09-11  7:27  1% reinert
  0 siblings, 0 replies; 200+ results
From: reinert @ 2022-09-11  7:27 UTC (permalink / raw)


Hello,

I tried alire with the latest version of the compiler (I believe) and I got trouble
compiling this program (which I here have reduced just to communicate my 
point - i.e. the program has no other meaning here):
--------------------------------------------------------------------------------------------
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;

procedure c0a is

subtype String_1 is String (1 .. <>);

package cpros is
cfe0,cfe1,cfe2 : exception;
generic
with procedure execute_command1 (command1 : String);
procedure cpros0
(file1 : in Ada.Text_IO.File_Type; command0 : String := "");
end cpros;

package body cpros is

procedure cpros0 (file1 : in Ada.Text_IO.File_Type; command0 : String := "")
is
begin
declare
function rep1 (str0 : String_1) return String is
i : constant Natural := Index (str0, "$");
begin
return str0 when i = 0;
-- raise cfe2 with "(wrong use of '$')" when i = str0'Last; -- a
if i = str0'Last then -- b
raise cfe2 with "(wrong use of '$')"; -- b
end if; -- b
return "aaa";
end rep1;
str0 : constant String := rep1 (Get_Line (file1));
begin
null;
end;
end cpros0;
end cpros;

procedure execute_command1 (str : String) is
begin
null;
end execute_command1;

procedure cpros1 is new cpros.cpros0 (execute_command1 => execute_command1);

begin
null;
end c0a;
-----------------------------------------------------------------------------------------------
This goes through when I compile it.

However, if I uncomment the "a" line and comment out the alternative "b" line 
(see code above), then I get the error message:

c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: "cfe2" is not visible
c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: non-visible declaration at line 10

Have you the same experience?

reinert

^ permalink raw reply	[relevance 1%]

* Is this an error in compiler?
@ 2022-09-11  7:21  1% reinert
  0 siblings, 0 replies; 200+ results
From: reinert @ 2022-09-11  7:21 UTC (permalink / raw)


Hello,

I tried alire with the latest version of the compiler (I believe) and I got trouble
compiling this program (which I here have reduced just to communicate my point - i.e. the program has noe other meaning here):
--------------------------------------------------------------------------------------------
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;

procedure c0a is

subtype String_1 is String (1 .. <>);

package cpros is
cfe0,cfe1,cfe2 : exception;
generic
with procedure execute_command1 (command1 : String);
procedure cpros0
(file1 : in Ada.Text_IO.File_Type; command0 : String := "");
end cpros;

package body cpros is

procedure cpros0 (file1 : in Ada.Text_IO.File_Type; command0 : String := "")
is
begin
declare
function rep1 (str0 : String_1) return String is
i : constant Natural := Index (str0, "$");
begin
return str0 when i = 0;
-- raise cfe2 with "(wrong use of '$')" when i = str0'Last; -- a
if i = str0'Last then -- b
raise cfe2 with "(wrong use of '$')"; -- b
end if; -- b
return "aaa";
end rep1;
str0 : constant String := rep1 (Get_Line (file1));
begin
null;
end;
end cpros0;
end cpros;

procedure execute_command1 (str : String) is
begin
null;
end execute_command1;

procedure cpros1 is new cpros.cpros0 (execute_command1 => execute_command1);

begin
null;
end c0a;
-----------------------------------------------------------------------------------------------
This goes through when I compile it.

However, if I uncomment out the "a" line and comment out the "b" line (see code above), then I get the error message:

c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: "cfe2" is not visible
c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: non-visible declaration at line 10

Have you the same experience?

reinert

^ permalink raw reply	[relevance 1%]

* Is this an error in compiler
@ 2022-09-11  7:19  1% reinert
  0 siblings, 0 replies; 200+ results
From: reinert @ 2022-09-11  7:19 UTC (permalink / raw)


Hello,

I tried alire with the latest version of the compiler (I believe) and I got trouble
compiling this program (which I here have reduced just to communicate my point - i.e. the program has no other meaning here):
--------------------------------------------------------------------------------------------
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;

procedure c0a is

subtype String_1 is String (1 .. <>);

package cpros is
cfe0,cfe1,cfe2 : exception;
generic
with procedure execute_command1 (command1 : String);
procedure cpros0
(file1 : in Ada.Text_IO.File_Type; command0 : String := "");
end cpros;

package body cpros is

procedure cpros0 (file1 : in Ada.Text_IO.File_Type; command0 : String := "")
is
begin
declare
function rep1 (str0 : String_1) return String is
i : constant Natural := Index (str0, "$");
begin
return str0 when i = 0;
raise cfe2 with "(wrong use of '$')" when i = str0'Last; -- a
-- if i = str0'Last then -- b
-- raise cfe2 with "(wrong use of '$')"; -- b
-- end if; -- b
return "aaa";
end rep1;
str0 : constant String := rep1 (Get_Line (file1));
begin
null;
end;
end cpros0;
end cpros;

procedure execute_command1 (str : String) is
begin
null;
end execute_command1;

procedure cpros1 is new cpros.cpros0 (execute_command1 => execute_command1);

begin
null;
end c0a;
-----------------------------------------------------------------------------------------------
This goes through when I compile it.

However, if I uncomment  the "a" line and comment out the "b" line (see code above), then I get the error message:

c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: "cfe2" is not visible
c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: non-visible declaration at line 10

Have you the same experience?

reinert

^ permalink raw reply	[relevance 1%]

* Is this an error in compiler?
@ 2022-09-11  7:16  1% reinert
  0 siblings, 0 replies; 200+ results
From: reinert @ 2022-09-11  7:16 UTC (permalink / raw)


Hello,

I tried alire with the latest version of the compiler (I believe) and I got trouble
compiling this program (which I here have reduced just to communicate my point - i.e. the program has noe other meaning here):
--------------------------------------------------------------------------------------------
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Exceptions;
with Ada.Text_IO;       use Ada.Text_IO;

procedure c0a is

subtype String_1 is String (1 .. <>);

package cpros is
   cfe0,cfe1,cfe2 : exception;
   generic
      with procedure execute_command1 (command1 : String);
   procedure cpros0
     (file1 : in Ada.Text_IO.File_Type; command0 : String := "");
end cpros;

package body cpros is

   procedure cpros0 (file1 : in Ada.Text_IO.File_Type; command0 : String := "")
   is
   begin
       declare
          function rep1 (str0 : String_1) return String is
             i : constant Natural := Index (str0, "$");
          begin
             return str0 when i = 0;
             raise cfe2 with "(wrong use of '$')" when i = str0'Last;  -- a 
        --   if i = str0'Last then                                     -- b
        --      raise cfe2 with "(wrong use of '$')";                  -- b
        --   end if;                                                   -- b
             return "aaa";
          end rep1;
          str0 : constant String := rep1 (Get_Line (file1));
       begin
         null;
       end;
   end cpros0;
end cpros;

   procedure execute_command1 (str : String) is
   begin
     null;
   end execute_command1;

   procedure cpros1 is new cpros.cpros0 (execute_command1 => execute_command1);

begin
  null;
end c0a;
-----------------------------------------------------------------------------------------------
This goes through when I compile it.

However, if I  uncomment out the "a" line and comment out the "b" line (see code above), then I get the error message:

c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: "cfe2" is not visible
c0a.adb:45:04: error: instantiation error at line 27
c0a.adb:45:04: error: non-visible declaration at line 10

Have you the same experience?

reinert



^ permalink raw reply	[relevance 1%]

* Re: Adjust primitive not called on defaulted nonlimited controlled parameter, bug or feature ?
  2022-08-17 20:11  1% Adjust primitive not called on defaulted nonlimited controlled parameter, bug or feature ? David SAUVAGE
@ 2022-08-17 22:49  0% ` Jere
  0 siblings, 0 replies; 200+ results
From: Jere @ 2022-08-17 22:49 UTC (permalink / raw)


On Wednesday, August 17, 2022 at 4:11:46 PM UTC-4, david....@adalabs.com wrote:
> In the code extract below [2] Adjust primitive is not called on defaulted nonlimited controlled parameter Set. 
> A reproducer is available on gitlab [1] 
> 
> Seems like a bug, any feedbacks ? 
> 
> [1] 
> reproducer 
> https://gitlab.com/adalabs/reproducers/-/tree/main/adjust-not-called-on-defaulted-nonlimited-controlled-parameter 
> 
> [2] 
> 1 with Ada.Exceptions, 
> 2 Ada.Text_IO; 
> 3 
> 4 with GNAT.OS_Lib; 
> 5 
> 6 procedure Reproducer.Main is 
> 7 
> 8 -- 
> 9 -- snippet of reproducer.ads 
> 10 -- ... 
> 11 -- type Translate_Set is private; 
> 12 -- Null_Set : constant Translate_Set; 
> 13 -- private 
> 14 -- type Translate_Set is new Ada.Finalization.Controlled with record 
> 15 -- Ref_Count : Integer_Access; 
> 16 -- Set : Boolean_Access; 
> 17 -- end record; 
> 18 -- Null_Set : constant Translate_Set := (Ada.Finalization.Controlled with null, null); 
> 19 -- ... 
> 20 -- 
> 21 
> 22 procedure Process (Set : Translate_Set := Null_Set) 
> 23 is 
> 24 Content : constant String := Parse (Filename => "Process", 
> 25 Translations => Set); 
> 26 begin 
> 27 Ada.Text_IO.Put_Line (Content); 
> 28 end Process; 
> 29 begin 
> 30 Process; 
> 31 -- Ok, Initialize (Set) is not called because default value Null_Set is specified to Set (7.6 10/2). 
> 32 -- However Adjust (Set) is not called (7.6 17.8/3). 
> 33 -- Is it a feature or a bug ? 
> 34 
> 35 exception 
> 36 when E : others => 
> 37 Ada.Text_IO.Put_Line ("(FF) Adjust was not called on the nonlimited controlled object Set, when parameter defaulted to Null_Set"); 
> 38 Ada.Text_IO.Put_Line ("(FF) " & Ada.Exceptions.Exception_Information (E)); 
> 39 GNAT.OS_Lib.OS_Exit (255); 
> 40 end Reproducer.Main;

Since Translate_Set is a "by-reference type" (see section 6.2 of the RM), there isn't an 
assignment actually made is my guess.  The default parameter notation looks like assignment, but
I would hazard a guess that it doesn't mean an actual assignment is required.

^ permalink raw reply	[relevance 0%]

* Adjust primitive not called on defaulted nonlimited controlled parameter, bug or feature ?
@ 2022-08-17 20:11  1% David SAUVAGE
  2022-08-17 22:49  0% ` Jere
  0 siblings, 1 reply; 200+ results
From: David SAUVAGE @ 2022-08-17 20:11 UTC (permalink / raw)


In the code extract below [2] Adjust primitive is not called on defaulted nonlimited controlled parameter Set.
A reproducer is available on gitlab [1]

Seems like a bug, any feedbacks ?

[1] 
reproducer
https://gitlab.com/adalabs/reproducers/-/tree/main/adjust-not-called-on-defaulted-nonlimited-controlled-parameter

[2]
     1	with Ada.Exceptions,
     2	     Ada.Text_IO;
     3	
     4	with GNAT.OS_Lib;
     5	
     6	procedure Reproducer.Main is
     7	
     8	   --
     9	   --  snippet of reproducer.ads
    10	   --  ...
    11	   --     type Translate_Set is private;
    12	   --     Null_Set : constant Translate_Set;
    13	   --  private
    14	   --     type Translate_Set is new Ada.Finalization.Controlled with record
    15	   --        Ref_Count : Integer_Access;
    16	   --        Set       : Boolean_Access;
    17	   --     end record;
    18	   --     Null_Set : constant Translate_Set := (Ada.Finalization.Controlled with null, null);
    19	   --   ...
    20	   --
    21	
    22	   procedure Process (Set : Translate_Set := Null_Set)
    23	   is
    24	      Content : constant String := Parse (Filename          => "Process",
    25	                                          Translations      => Set);
    26	   begin
    27	      Ada.Text_IO.Put_Line (Content);
    28	   end Process;
    29	begin
    30	   Process;
    31	   --  Ok, Initialize (Set) is not called because default value Null_Set is specified to Set (7.6 10/2).
    32	   --  However Adjust (Set) is not called (7.6 17.8/3).
    33	   --  Is it a feature or a bug ?
    34	
    35	exception
    36	   when E : others =>
    37	      Ada.Text_IO.Put_Line ("(FF) Adjust was not called on the nonlimited controlled object Set, when parameter defaulted to Null_Set");
    38	      Ada.Text_IO.Put_Line ("(FF) " & Ada.Exceptions.Exception_Information (E));
    39	      GNAT.OS_Lib.OS_Exit (255);
    40	end Reproducer.Main;

^ permalink raw reply	[relevance 1%]

* Re: Using pointers with inline assembly in Ada
  2022-06-11 12:28  1% ` Simon Wright
@ 2022-06-11 12:32  0%   ` NiGHTS
  0 siblings, 0 replies; 200+ results
From: NiGHTS @ 2022-06-11 12:32 UTC (permalink / raw)


On Saturday, June 11, 2022 at 8:28:28 AM UTC-4, Simon Wright wrote:
> NiGHTS <nig...@unku.us> writes: 
> 
> > This was my first experiment which produces a memory access error. In 
> > this early version I'm just trying to write to the first element. 
> > 
> > declare 
> > type ff is array (0 .. 10) of Unsigned_32; 
> > pragma Pack(ff); 
> > Flags : aliased ff := (others => 0); 
> > Flag_Address : System.Address := Flags'Address; 
> > begin 
> > Asm ( "movl %0, %%eax" & 
> > "movl $1, (%%eax)" , 
> > Inputs => System.Address'Asm_Input ("g", Flag_Address), 
> > Clobber => "eax", 
> > Volatile => true 
> > ); 
> > Put_Line ("Output:" & Flags(0)'Img); 
> > end;
> I got an access error as well (macOS, GCC 12.1.0, 64 bits). 
> 
> Eventually, it turned out that the problem was that eax is a 32-bit 
> register. (the compiler used rdx, and the assembler told me that 
> movl %rdx, %eax wasn't allowed). 
> 
> This is my working code; Flags is volatile, because otherwise the 
> compiler doesn't realise (at -O2) that Flags (0) has been touched. 
> 
> ALso, note the Inputs line! 
> 
> ==== 
> with System.Machine_Code; use System.Machine_Code; 
> with Interfaces; use Interfaces; 
> with Ada.Text_IO; use Ada.Text_IO; 
> procedure Nights is 
> type Ff is array (0 .. 10) of Unsigned_32; 
> Flags : aliased Ff := (others => 0) with Volatile; 
> begin 
> Asm ( 
> "movq %0, %%rax" & ASCII.LF & ASCII.HT 
> & "movl $1, (%%rax)", 
> Inputs => System.Address'Asm_Input ("g", Flags (Flags'First)'Address), 
> Clobber => "rax", 
> Volatile => True
> ); 
> Put_Line ("Output:" & Flags(0)'Img);
> end Nights;
I haven't tested this yet but the solution makes sense to me. Thank you for your help!

^ permalink raw reply	[relevance 0%]

* Re: Using pointers with inline assembly in Ada
  @ 2022-06-11 12:28  1% ` Simon Wright
  2022-06-11 12:32  0%   ` NiGHTS
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2022-06-11 12:28 UTC (permalink / raw)


NiGHTS <nights@unku.us> writes:

> This was my first experiment which produces a memory access error. In
> this early version I'm just trying to write to the first element.
>
> declare
>          type ff is array (0 .. 10) of Unsigned_32;
>          pragma Pack(ff);
>          Flags : aliased ff := (others => 0);
>          Flag_Address : System.Address := Flags'Address;
> begin
>         Asm (   "movl %0, %%eax" &
>                 "movl $1, (%%eax)" ,             
>                 Inputs   => System.Address'Asm_Input ("g", Flag_Address),
>                 Clobber  => "eax",
>                 Volatile => true
>         );
>         Put_Line ("Output:" & Flags(0)'Img);
> end;

I got an access error as well (macOS, GCC 12.1.0, 64 bits).

Eventually, it turned out that the problem was that eax is a 32-bit
register. (the compiler used rdx, and the assembler told me that
movl %rdx, %eax wasn't allowed).

This is my working code; Flags is volatile, because otherwise the
compiler doesn't realise (at -O2) that Flags (0) has been touched.

ALso, note the Inputs line!

====
with System.Machine_Code; use System.Machine_Code;
with Interfaces; use Interfaces;
with Ada.Text_IO; use Ada.Text_IO;
procedure Nights is
   type Ff is array (0 .. 10) of Unsigned_32;
   Flags : aliased Ff := (others => 0) with Volatile;
begin
   Asm (
        "movq %0, %%rax" & ASCII.LF & ASCII.HT
          & "movl $1, (%%rax)",
        Inputs   => System.Address'Asm_Input ("g", Flags (Flags'First)'Address),
        Clobber  => "rax",
        Volatile => True
       );
   Put_Line ("Output:" & Flags(0)'Img);
end Nights;

^ permalink raw reply	[relevance 1%]

* Re: Extra information in the message string of exceptions.
  2022-06-08  8:04  0%       ` Dmitry A. Kazakov
@ 2022-06-09  2:39  0%         ` Jerry
  0 siblings, 0 replies; 200+ results
From: Jerry @ 2022-06-09  2:39 UTC (permalink / raw)


On Wednesday, June 8, 2022 at 1:04:32 AM UTC-7, Dmitry A. Kazakov wrote:
> On 2022-06-08 09:31, Jerry wrote: 
> > On Tuesday, June 7, 2022 at 8:56:00 AM UTC-7, Fabien Chouteau wrote: 
> >> On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote: 
> >>> But this feature could be activated with a switch only when needed. 
> >> Well, it turns our this is already implemented in GNAT ^^ 
> >> 
> >> Example here: https://godbolt.org/z/fcTEaq3xP 
> > Indeed. The switch is -GNATeE. It provides additional information for the program at that page, 
> > 
> > procedure Main is 
> > procedure Test (A : Integer) is 
> > type T is range 0 .. 42; 
> > begin 
> > Ada.Text_IO.Put_Line (T (A)'Img); 
> > end; 
> > begin 
> > Test (-1); 
> > end Main; 
> > 
> > But has no effect on this program; 
> > 
> > procedure CE_2 is 
> > i : Positive; 
> > j : Integer := 1; 
> > begin 
> > i := -j; 
> > end CE_2;
> The switches are -E for binder and -g for everything else. Try this: 
> 
> --- test_ce.gpr ---------------------------------------- 
> project Test_CE is 
> for Source_Files use ("test_ce.adb"); 
> for Main use ("test_ce.adb"); 
> 
> package Binder is 
> for Default_Switches ("ada") use ("-E"); 
> end Binder; 
> 
> package Builder is 
> for Default_Switches ("ada") use ("-g"); 
> end Builder; 
> 
> package Compiler is 
> for Default_Switches ("ada") use ("-g"); 
> end Compiler; 
> 
> package Linker is 
> for Default_Switches ("ada") use ("-g"); 
> end Linker; 
> 
> end Test_CE; 
> --- test_ce.adb ---------------------------------------- 
> with System.Exception_Traces; use System.Exception_Traces; 
> with System.Traceback.Symbolic; 
> 
> procedure Test_CE is
> i : Positive; 
> j : Integer := 1; 
> begin
> Trace_On (System.Exception_Traces.Unhandled_Raise); 
> Set_Trace_Decorator 
> ( System.Traceback.Symbolic.Symbolic_Traceback'Access 
> ); 
> i := -j; 
> end Test_CE; 
> 
> Notes: 
> 
> 1. You can just use Symbolic_Traceback whenever you want. E.g. you can 
> set an exception handler and dump traceback at the raising point. It is 
> slow as hell, of course. 
> 
> 2. There are problems getting symbolic traceback working on ARM. 
> 
> 3. This becomes pretty much useless with relocated libraries. I do not 
> know how to make it work with them. 
> 
> 4. Under Windows you will not get traceback from non-GCC compiled stuff 
> because it does not understand *.pdb files.
> -- 
> Regards, 
> Dmitry A. Kazakov 
> http://www.dmitry-kazakov.de
Hmm.... I get the same "Message" i.e. no extra information and only hex traceback info. Docs say -E is the same as -Ea meaning hex traceback, plus my set-up rejects -Ea (and -Es) as illegal switches. (Not sure at this point if we're chasing symbolic traceback or extra compiler information.)

^ permalink raw reply	[relevance 0%]

* Re: Extra information in the message string of exceptions.
  2022-06-08  7:31  1%     ` Jerry
@ 2022-06-08  8:04  0%       ` Dmitry A. Kazakov
  2022-06-09  2:39  0%         ` Jerry
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2022-06-08  8:04 UTC (permalink / raw)


On 2022-06-08 09:31, Jerry wrote:
> On Tuesday, June 7, 2022 at 8:56:00 AM UTC-7, Fabien Chouteau wrote:
>> On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote:
>>> But this feature could be activated with a switch only when needed.
>> Well, it turns our this is already implemented in GNAT ^^
>>
>> Example here: https://godbolt.org/z/fcTEaq3xP
> Indeed. The switch is -GNATeE. It provides additional information for the program at that page,
> 
> procedure Main is
>     procedure Test (A : Integer) is
>        type T is range 0 .. 42;
>     begin
>        Ada.Text_IO.Put_Line (T (A)'Img);
>     end;
> begin
>     Test (-1);
> end Main;
> 
> But has no effect on this program;
> 
> procedure CE_2 is
>      i : Positive;
>      j : Integer := 1;
> begin
>      i := -j;
> end CE_2;

The switches are -E for binder and -g for everything else. Try this:

--- test_ce.gpr ----------------------------------------
project Test_CE is
    for Source_Files use ("test_ce.adb");
    for Main use ("test_ce.adb");

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

    package Builder is
       for Default_Switches ("ada") use ("-g");
    end Builder;

    package Compiler is
       for Default_Switches ("ada") use ("-g");
    end Compiler;

    package Linker is
       for Default_Switches ("ada") use ("-g");
    end Linker;

end Test_CE;
--- test_ce.adb ----------------------------------------
with System.Exception_Traces;  use System.Exception_Traces;
with System.Traceback.Symbolic;

procedure Test_CE is
    i : Positive;
    j : Integer := 1;
begin
    Trace_On (System.Exception_Traces.Unhandled_Raise);
    Set_Trace_Decorator
    (  System.Traceback.Symbolic.Symbolic_Traceback'Access
    );
    i := -j;
end Test_CE;

Notes:

1. You can just use Symbolic_Traceback whenever you want. E.g. you can 
set an exception handler and dump traceback at the raising point. It is 
slow as hell, of course.

2. There are problems getting symbolic traceback working on ARM.

3. This becomes pretty much useless with relocated libraries. I do not 
know how to make it work with them.

4. Under Windows you will not get traceback from non-GCC compiled stuff 
because it does not understand *.pdb files.

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

^ permalink raw reply	[relevance 0%]

* Re: Extra information in the message string of exceptions.
  @ 2022-06-08  7:31  1%     ` Jerry
  2022-06-08  8:04  0%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Jerry @ 2022-06-08  7:31 UTC (permalink / raw)


On Tuesday, June 7, 2022 at 8:56:00 AM UTC-7, Fabien Chouteau wrote:
> On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote: 
> > But this feature could be activated with a switch only when needed.
> Well, it turns our this is already implemented in GNAT ^^ 
> 
> Example here: https://godbolt.org/z/fcTEaq3xP
Indeed. The switch is -GNATeE. It provides additional information for the program at that page, 

procedure Main is
   procedure Test (A : Integer) is
      type T is range 0 .. 42;
   begin
      Ada.Text_IO.Put_Line (T (A)'Img);
   end;
begin
   Test (-1);
end Main;

But has no effect on this program;

procedure CE_2 is
    i : Positive;
    j : Integer := 1;    
begin
    i := -j;
end CE_2;

Jerry

^ permalink raw reply	[relevance 1%]

* Question on in/out parameters
@ 2022-04-30  8:57  1% reinert
  0 siblings, 0 replies; 200+ results
From: reinert @ 2022-04-30  8:57 UTC (permalink / raw)


Hello,

I expected an "out" parameter in a procedure to be like declaring the parameter "from scratch" (with actual initial default value). For my compiler (GNAT Community Edition, May 2021) it seems like the out parameters brings in content from the calling procedure. Should it be like this?

Below is a test program to illustrate.

reinert

with Ada.Containers; use Ada.Containers;
with Ada.Containers.Vectors;
with Ada.Text_IO; use Ada.Text_IO;
procedure test2 is

   package Integer_Vectors is new Ada.Containers.Vectors
       (Index_Type   => Natural, Element_Type => Integer);
   use Integer_Vectors;

   V : Vector := 10 & 20;

   procedure rk_in_out(W : in out Vector) is
   begin
     W.Append(30); W.Append(40);
   end rk_in_out;

   procedure rk_out(W :    out Vector) is
   begin
     W.Clear;  -- I expected this statement to be redundant since W is "out parameter" (try to remove it and see if results remain the same.)?
     W.Append(30); W.Append(40);
   end rk_out;

begin

   New_Line;
   Put ("First V  : ");
   for e of V loop
       Put(e'Image & " ");
   end loop;

   rk_in_out(W => V);
   New_Line;
   Put ("Second V : ");
   for e of V loop
       Put(e'Image & " ");
   end loop;

   rk_out(W => V);
   New_Line;
   Put ("Third V :  ");
   for e of V loop
       Put(e'Image & " ");
   end loop;

end test2;


^ permalink raw reply	[relevance 1%]

* Re: use clauses
  2022-04-19  3:53  1%                       ` Thomas
@ 2022-04-19  5:59  1%                         ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2022-04-19  5:59 UTC (permalink / raw)


"Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message 
news:625e324c$0$18369$426a34cc@news.free.fr...
> In article <t357jt$v7n$1@dont-email.me>,
> "Randy Brukardt" <randy@rrsoftware.com> wrote:
>
>> "Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message
>> news:62560a6b$0$18724$426a74cc@news.free.fr...
>> > In article <s5vqq9$lou$1@franka.jacob-sparre.dk>,
>> > "Randy Brukardt" <randy@rrsoftware.com> wrote:
>> >
>> >> I personally
>> >> only use "use type" in new code (there's tons of old code for which 
>> >> that
>> >> doesn't work, of course, but that doesn't change the principle).
>> >
>> > what do you think about:
>> > - "use all type" clauses?
>>
>> This is OK; I don't use them mainly because I only use features 
>> implemented
>> in Janus/Ada, and "use all type" is not yet implemented there.
>>
>> The fundamental problem with "use" is that it makes everything visible, 
>> and
>> then deals with conflicts by making those things invisible again.
>
>
>> Since "use all type" only works on overloadable primitives (and things 
>> that
>> work rather like primitives), it's fairly safe. One could make an 
>> argument
>> that primitive operations should always be visible when the type is 
>> (that's
>> not the Ada rule, but argubly it would work better in most 
>> circumstances) --
>> and you should always know to look at primitives anyway when trying to 
>> find
>> something..
>
> are you speaking about a case like Ada.Text_IO.Unbounded_IO?

No, I was thinking more about typical ADTs (abstract data types), which 
usually come with most of their operations in a package. The containers, 
Text_IO, and Claw are all examples. Operations in packages like this are the 
ones that "use all type" make visible, and that's OK because that's where 
you would look for operations on the type anyway.

> i would say that these subprograms are not primitives, since they are
> not declared in the same package,

Correct.

> and i don't see in which case we could get a type visible but not its
> primitives.

The primitives and type are visible, but not directly visible (I hate that 
terminology). Which means you can use them with full names, but not 
directly. For types, I almost always use the full name anyway (since they 
aren't referenced that much). So if you have an object:

     Fyle : Ada.Text_IO.File_Type;

the type is visible (but not directly visible). It's annoying that you have 
to jump thru hoops (such as "use all type") in order to get them. Operators 
in particular should always work so long as the type is visible (even if not 
directly visible). But that would require restricting where they are 
declared, and it's too late to do that for Ada.

> in this case, the best thing to do that i found is:
>   use all type Ada.Text_IO.File_Type;
>   use Ada.Text_IO.Unbounded_IO;
> is there sth best?

I just write out such things.

    Ada.Text_IO.Unbounded_IO.Put (My_String);

If I had to use a lot of them in some code, I'd probably use a local rename. 
It's not great, but at least you can figure out where the thing is declared 
without having some giant IDE running all the time..

> BTW, i often get a repetition in the same declare bloc, like:
>   File       : Ada.Text_IO.File_Type;
>   use all type Ada.Text_IO.File_Type;

Yup.

> what do you think about generate an automatic "use all type" where the
> variable is declared?

For tagged objects, you already have it effectively with prefix notation. 
And who cares about antique stuff?? :-)

>> > - List.Clear? (could you remember me how you call that, please?)
>>
>> For tagged types, you can use prefix notation, so "My_List.Clear" is the
>> easiest. With "use all type List", you can write Clear(My_List).
>
> i asked for your opinion, because J-P. Rosen told me he doesn't like
> that. so i would like to know main usages, practicals, ...
>
> if i got it, you use prefix notation a lot, because you have no access
> to "use all type"?

Nope: Janus/Ada doesn't implement that yet, either (it was an Ada 2005 
feature). I personally write a lot of long-winded identifiers:

    Foobar (UString => Ada.Strings.Unbounded.To_Unbounded_String 
(My_Package.Data_Selector (Glarch, 3));

(Although that one often gets a special rename:

     function "+" (A : in String) return 
Ada.Strings.Unbounded.Unbounded_String renames
       Ada.Strings.Unbounded.To_Unbounded_String;

and then:

    Foobar (UString => + My_Package.Data_Selector (Glarch, 3));

I'd rather not do that, but this one gets to be too much... :-)

>> ["Clear" works well even when someone uses
>> everything in sight] (of course, they may have a hard time finding where
>> Clear is defined when debugging, but that's their choice).
>
> are you sure?
> i would say either there is only 1 Clear for the type List, and if it's
> a primitive it's easy to know where to find it, or there are many Clear
> for the type List, and they are not visibles.

The usual problem is that they didn't name their objects very well and thus 
don't know the type. Or it's maintenance and you don't know the code well 
enough to know the type. Or it's 40 years later and you've forgotten 
everything you knew about the code (my situation with Janus/Ada code :-). If 
you don't know the type or know where it it declared, it's hard to know 
where to look for primitives. And not all code is organized as ADTs 
(especially true in older code), so there may not be a lot of primitives.

>> > - List.Clear does work only if List is tagged?
>>
>> Right. There are a number of semantic issues for untagged types, the main
>> ones having to do with implicit dereference (which occurs in this 
>> notation,
>> as in any other selected_component notation). If you have a prefix of an
>> access type, it gets very messy to determine which dereference is which. 
>> And
>> just allowing composite types doesn't work well either: a private type 
>> that
>> is completed with an access type would *lose* operations when it had full
>> visibility -- that seems pretty weird.
>>
>> It originally got limited to tagged types as that was easy to do and 
>> didn't
>> have semantic issues.
>
> what's i don't understand is, there is sth which work better with tagged
> types than with untagged types, whereas tagged types are known to be
> more complex to give special functionnality, not to be simpler to use.
>
> could you give me a concrete example please, of a case where using
> prefix notation with an untagged type causes a particular problem, and
> then making the type tagged permits to resolve the problem?

Go read the AIs, I would have to do that to find the details, and I'd 
probably transcribe it wrong. The last discussion was in AI12-0257-1. (I 
looked that up in the AI index - see 
http://www.ada-auth.org/AI12-VOTING.HTML for the Ada 2012 one.)

>> We were going to look at generalizing the prefix
>> notation again (several people asked about it), but no one made a 
>> concrete
>> proposal and it never went anywhere for Ada 2022.
>
> (maybe i could make one if i understand enough? :-) )

That's a big if! :-)

                                Randy.


^ permalink raw reply	[relevance 1%]

* Re: use clauses
  @ 2022-04-19  3:53  1%                       ` Thomas
  2022-04-19  5:59  1%                         ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Thomas @ 2022-04-19  3:53 UTC (permalink / raw)


In article <t357jt$v7n$1@dont-email.me>,
 "Randy Brukardt" <randy@rrsoftware.com> wrote:

> "Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message 
> news:62560a6b$0$18724$426a74cc@news.free.fr...
> > In article <s5vqq9$lou$1@franka.jacob-sparre.dk>,
> > "Randy Brukardt" <randy@rrsoftware.com> wrote:
> >
> >> I personally
> >> only use "use type" in new code (there's tons of old code for which that
> >> doesn't work, of course, but that doesn't change the principle).
> >
> > what do you think about:
> > - "use all type" clauses?
> 
> This is OK; I don't use them mainly because I only use features implemented 
> in Janus/Ada, and "use all type" is not yet implemented there.
> 
> The fundamental problem with "use" is that it makes everything visible, and 
> then deals with conflicts by making those things invisible again.


> Since "use all type" only works on overloadable primitives (and things that 
> work rather like primitives), it's fairly safe. One could make an argument 
> that primitive operations should always be visible when the type is (that's 
> not the Ada rule, but argubly it would work better in most circumstances) --  
> and you should always know to look at primitives anyway when trying to find 
> something..

are you speaking about a case like Ada.Text_IO.Unbounded_IO?
i would say that these subprograms are not primitives, since they are 
not declared in the same package,
and i don't see in which case we could get a type visible but not its 
primitives.

in this case, the best thing to do that i found is:
   use all type Ada.Text_IO.File_Type;
   use Ada.Text_IO.Unbounded_IO;
is there sth best?


BTW, i often get a repetition in the same declare bloc, like:
   File       : Ada.Text_IO.File_Type;
   use all type Ada.Text_IO.File_Type;

what do you think about generate an automatic "use all type" where the 
variable is declared?


> 
> > - List.Clear? (could you remember me how you call that, please?)
> 
> For tagged types, you can use prefix notation, so "My_List.Clear" is the 
> easiest. With "use all type List", you can write Clear(My_List).

i asked for your opinion, because J-P. Rosen told me he doesn't like 
that. so i would like to know main usages, practicals, ...

if i got it, you use prefix notation a lot, because you have no access 
to "use all type"?


> ["Clear" works well even when someone uses 
> everything in sight] (of course, they may have a hard time finding where 
> Clear is defined when debugging, but that's their choice).

are you sure?
i would say either there is only 1 Clear for the type List, and if it's 
a primitive it's easy to know where to find it, or there are many Clear 
for the type List, and they are not visibles.


> 
> > - List.Clear does work only if List is tagged?
> 
> Right. There are a number of semantic issues for untagged types, the main 
> ones having to do with implicit dereference (which occurs in this notation, 
> as in any other selected_component notation). If you have a prefix of an 
> access type, it gets very messy to determine which dereference is which. And 
> just allowing composite types doesn't work well either: a private type that 
> is completed with an access type would *lose* operations when it had full 
> visibility -- that seems pretty weird.
> 
> It originally got limited to tagged types as that was easy to do and didn't 
> have semantic issues.

what's i don't understand is, there is sth which work better with tagged 
types than with untagged types, whereas tagged types are known to be 
more complex to give special functionnality, not to be simpler to use.

could you give me a concrete example please, of a case where using 
prefix notation with an untagged type causes a particular problem, and 
then making the type tagged permits to resolve the problem?


> We were going to look at generalizing the prefix 
> notation again (several people asked about it), but no one made a concrete 
> proposal and it never went anywhere for Ada 2022.

(maybe i could make one if i understand enough? :-) )

-- 
RAPID maintainer
http://savannah.nongnu.org/projects/rapid/

^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  @ 2022-04-07  1:30  1%               ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2022-04-07  1:30 UTC (permalink / raw)


"J-P. Rosen" <rosen@adalog.fr> wrote in message 
news:t2knpr$s26$1@dont-email.me...
...
> It was felt that in practice, being too strict in separating the types 
> would make things more difficult, without any practical gain. This has 
> been discussed - you may not agree with the outcome, but it was not made 
> out of pure lazyness

The problem with that, of course, is that it sends the wrong message 
vis-a-vis strong typing and interfaces. If we abandon it at the first sign 
of trouble, they we are saying that it isn't really that important.

In this particular case, the reason really came down to practicality: if you 
want to do anything string-like with a UTF-8 string, making it a separate 
type becomes painful. It wouldn't work with anything in Ada.Strings, 
Ada.Text_IO, or Ada.Directories, even though most of the operations are 
fine. And there was no political will to replace all of those things with 
versions to use with proper universal strings.

Moreover, if you really want to do that, you have to hide much of the array 
behavior of the Universal string. For instance, you can't allow willy-nilly 
slicing or replacement: cutting a character representation in half or 
setting an illegal representation has to be prohibited (operations that 
would turn a valid string into an invalid string should always raise an 
exception). That means you can't (directly) use built-in indexing and 
slicing -- those have to go through some sort of functions. So you do pretty 
much have to use a private type for universal strings (similar to 
Ada.Strings.Bounded would be best, I think).

If you had an Ada-like language that used a universal UTF-8 string 
internally, you then would have a lot of old and mostly useless operations 
supported for array types (since things like slices are mainly useful for 
string operations). So such a language should simplify the core 
substantially by dropping many of those obsolete features (especially as 
little of the library would be directly compatible anyway). So one should 
end up with a new language that draws from Ada rather than something in Ada 
itself. (It would be great if that language could make strings with 
different capacities interoperable - a major annoyance with Ada. And 
modernizing access types, generalizing resolution, and the like also would 
be good improvements IMHO.)

                                               Randy.


^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  @ 2022-04-04 23:52  1%             ` Randy Brukardt
  2023-03-31  3:06  1%               ` Thomas
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2022-04-04 23:52 UTC (permalink / raw)



"Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message 
news:fantome.forums.tDeContes-5E3B70.20370903042022@news.free.fr...
...
> as i said to Vadim Godunko, i need to fill a string type with an UTF-8
> litteral.but i don't think this string type has to manage various 
> conversions.
>
> from my point of view, each library has to accept 1 kind of string type
> (preferably UTF-8 everywhere),
> and then, this library has to make needed conversions regarding the
> underlying API. not the user.

This certainly is a fine ivory tower solution, but it completely ignores two 
practicalities in the case of Ada:

(1) You need to replace almost all of the existing Ada language defined 
packages to make this work. Things that are deeply embedded in both 
implementations and programs (like Ada.Exceptions and Ada.Text_IO) would 
have to change substantially. The result would essentially be a different 
language, since the resulting libraries would not work with most existing 
programs. They'd have to have different names (since if you used the same 
names, you change the failures from compile-time to runtime -- or even 
undetected -- which would be completely against the spirit of Ada), which 
means that one would have to essentially start over learning and using the 
resulting language. Calling it Ada would be rather silly, since it would be 
practically incompatible (and it would make sense to use this point to 
eliminate a lot of the cruft from the Ada design).

(2) One needs to be able to read and write data given whatever encoding the 
project requires (that's often decided by outside forces, such as other 
hardware or software that the project needs to interoperate with). That 
means that completely hiding the encoding (or using a universal encoding) 
doesn't fully solve the problems faced by Ada programmers. At a minimum, you 
have to have a way to specify the encoding of files, streams, and hardware 
interfaces (this sort of thing is not provided by any common target OS, so 
it's not in any target API). That will greatly complicate the interface and 
implementation of the libraries.

> ... of course, it would be very nice to have a more thicker language with 
> a garbage collector ...

I doubt that you will ever see that in the Ada family, as analysis and 
therefore determinism is a very important property for the language. Ada has 
lots of mechanisms for managing storage without directly doing it yourself 
(by calling Unchecked_Deallocation), yet none of them use any garbage 
collection in a traditional sense. I could see more such mechanisms (an 
ownership option on the line of Rust could easily manage storage at the same 
time, since any object that could be orphaned could never be used again and 
thus should be reclaimed), but standard garbage collection is too 
non-deterministic for many of the uses Ada is put to.

                                              Randy.


^ permalink raw reply	[relevance 1%]

* Re: Get_Immediate does not read CR in CRLF pairs
  2022-03-08 12:08  0%   ` Marius Amado-Alves
@ 2022-03-08 14:57  0%     ` Luke A. Guest
  0 siblings, 0 replies; 200+ results
From: Luke A. Guest @ 2022-03-08 14:57 UTC (permalink / raw)


On 08/03/2022 12:08, Marius Amado-Alves wrote:
> On Tuesday, 8 March 2022 at 07:46:53 UTC, Luke A. Guest wrote:
>> On 08/03/2022 07:45, Marius Amado-Alves wrote:
>>> Behaviour of Ada.Text_IO on GNAT/Windows 11:
>>>
>>> (1) Get_Immediate does not read the CR in CRLF pairs
>> Isn't this where you need to check for EOL and then Skip; when you hit it?
> 
> Sorry, Luke, I dont understand the question.

There is a procedure called Skip to get past the EOL/EOP.

^ permalink raw reply	[relevance 0%]

* Re: Get_Immediate does not read CR in CRLF pairs
  2022-03-08  7:46  0% ` Luke A. Guest
@ 2022-03-08 12:08  0%   ` Marius Amado-Alves
  2022-03-08 14:57  0%     ` Luke A. Guest
  0 siblings, 1 reply; 200+ results
From: Marius Amado-Alves @ 2022-03-08 12:08 UTC (permalink / raw)


On Tuesday, 8 March 2022 at 07:46:53 UTC, Luke A. Guest wrote:
> On 08/03/2022 07:45, Marius Amado-Alves wrote: 
> > Behaviour of Ada.Text_IO on GNAT/Windows 11: 
> > 
> > (1) Get_Immediate does not read the CR in CRLF pairs
> Isn't this where you need to check for EOL and then Skip; when you hit it?

Sorry, Luke, I dont understand the question.

^ permalink raw reply	[relevance 0%]

* Re: Get_Immediate does not read CR in CRLF pairs
  2022-03-08  7:45  1% Get_Immediate does not read CR in CRLF pairs Marius Amado-Alves
  2022-03-08  7:46  0% ` Luke A. Guest
  2022-03-08  8:03  0% ` Dmitry A. Kazakov
@ 2022-03-08  9:06  1% ` Jeffrey R.Carter
  2 siblings, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2022-03-08  9:06 UTC (permalink / raw)


On 2022-03-08 08:45, Marius Amado-Alves wrote:
> Behaviour of Ada.Text_IO on GNAT/Windows 11:
> 
> (1) Get_Immediate does not read the CR in CRLF pairs

Get_Immediate is only of interest for reading from Standard_Input, primarily 
when it is the keyboard. It's better to use Get for other cases.

Get_Immediate is not well defined for reading line terminators. Whatever the 
compiler decides to implement is probably correct, and implementation defined. 
Should it behave like Get, which ignores line terminators? ObjectAda 10.2 
ignores the Enter key (10.3 returns CR).

Get_Immediate returns the character corresponding to the key pressed. What is 
the character for the Enter key? GNAT has decided to return LF in that case. 
Should it behave differently if the input is from a file? Presumably, 
Get_Immediate should behave the same whether Standard_Input is the keyboard or 
redirected from a file.

> (2) Get_Immediate does not read the ending CRLF pair at all (in loop terminated upon End_Of_File)

End_Of_File is defined to return True if all that remains in the file is a line 
terminator followed by a page terminator (A.10.5). As such, it is broken, since, 
when reading a file with a null last line, it will return True before the last 
line is read. In practice, most compilers treat a final line terminator the 
same, to work with files produced by non-Ada programs.

> (3) an extra ending CRLF pair is output

Close is defined to call New_page if the file does not already end with a page 
terminator [ARM A.10.2(3), 
http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A-10-2.html], and a page 
is defined to be terminated by a line terminator followed by a page terminator 
(A.10). GNAT seems to use the same character sequence for line and page 
terminators, presumably so that text files output with Ada.Text_IO may be read 
by non-Ada programs. If you've output a single LF as the last thing in a file on 
Windows, that is not a page terminator, so Close adds one.

If you need to see all the bytes in a file, Sequential_IO or Stream_IO are the 
ways to go. Of course, there is no portable way to read Standard_Input using 
Sequential_IO.

-- 
Jeff Carter
"What's the amount of the insult?"
Never Give a Sucker an Even Break
104

^ permalink raw reply	[relevance 1%]

* Re: Get_Immediate does not read CR in CRLF pairs
  2022-03-08  7:45  1% Get_Immediate does not read CR in CRLF pairs Marius Amado-Alves
  2022-03-08  7:46  0% ` Luke A. Guest
@ 2022-03-08  8:03  0% ` Dmitry A. Kazakov
  2022-03-08  9:06  1% ` Jeffrey R.Carter
  2 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2022-03-08  8:03 UTC (permalink / raw)


On 2022-03-08 08:45, Marius Amado-Alves wrote:
> Behaviour of Ada.Text_IO on GNAT/Windows 11:
> 
> (1) Get_Immediate does not read the CR in CRLF pairs
> 
> (2) Get_Immediate does not read the ending CRLF pair at all (in loop terminated upon End_Of_File)
> 
> (3) an extra ending CRLF pair is output
> 
> Does this behaviour follow from the ARM?
> Do other compilers behave 'better'?
> 
> Sequential_IO instantiated with Character works correctly (so I am not blocked, just curious:-)

I guess this is a part of translation text I/O does and sequential and 
stream I/O do not.

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

^ permalink raw reply	[relevance 0%]

* Re: Get_Immediate does not read CR in CRLF pairs
  2022-03-08  7:45  1% Get_Immediate does not read CR in CRLF pairs Marius Amado-Alves
@ 2022-03-08  7:46  0% ` Luke A. Guest
  2022-03-08 12:08  0%   ` Marius Amado-Alves
  2022-03-08  8:03  0% ` Dmitry A. Kazakov
  2022-03-08  9:06  1% ` Jeffrey R.Carter
  2 siblings, 1 reply; 200+ results
From: Luke A. Guest @ 2022-03-08  7:46 UTC (permalink / raw)


On 08/03/2022 07:45, Marius Amado-Alves wrote:
> Behaviour of Ada.Text_IO on GNAT/Windows 11:
> 
> (1) Get_Immediate does not read the CR in CRLF pairs

Isn't this where you need to check for EOL and then Skip; when you hit it?

^ permalink raw reply	[relevance 0%]

* Get_Immediate does not read CR in CRLF pairs
@ 2022-03-08  7:45  1% Marius Amado-Alves
  2022-03-08  7:46  0% ` Luke A. Guest
                   ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: Marius Amado-Alves @ 2022-03-08  7:45 UTC (permalink / raw)


Behaviour of Ada.Text_IO on GNAT/Windows 11:

(1) Get_Immediate does not read the CR in CRLF pairs

(2) Get_Immediate does not read the ending CRLF pair at all (in loop terminated upon End_Of_File)

(3) an extra ending CRLF pair is output

Does this behaviour follow from the ARM?
Do other compilers behave 'better'?

Sequential_IO instantiated with Character works correctly (so I am not blocked, just curious:-)

Thanks.
______
with Ada.Text_IO; use Ada.Text_IO;

procedure Get_Immediate_Test is
   C: Character;
   F_In: File_Type;
   F_Out: File_Type;

   procedure Default_Files_With_End_Of_File is
   begin
      while not End_Of_File loop
         Get_Immediate (C);
         Put (Character'Pos (C)'Img);
      end loop;
   end;

   procedure Default_Files_With_Exception is
   begin
      loop
         Get_Immediate (C);
         Put (Character'Pos (C)'Img);
      end loop;
   exception
      when others => null;
   end;

   procedure Named_Files_With_End_Of_File is
   begin
      Open (F_In, In_File, "imm_test_in_file.txt");
      Create (F_Out, Out_File, "imm_test_out_file.txt");
      while not End_Of_File loop
         Get_Immediate (F_In, C);
         Put (F_Out, Character'Pos (C)'Img);
      end loop;
      Close (F_In);
      Close (F_Out);
   end;

   procedure Named_Files_With_Exception is
   begin
      Open (F_In, In_File, "imm_test_in_file.txt");
      Create (F_Out, Out_File, "imm_test_out_file.txt");
      begin
         loop
            Get_Immediate (F_In, C);
            Put (F_Out, Character'Pos (C)'Img);
         end loop;
      exception
         when others =>
            Close (F_In);
            Close (F_Out);
      end;
   end;

begin
   Named_Files_With_Exception;
end;

^ permalink raw reply	[relevance 1%]

* Re: Plugin with controlled variable for initialization.
  2022-02-02 17:21  1% Plugin with controlled variable for initialization hreba
@ 2022-02-02 18:05  0% ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2022-02-02 18:05 UTC (permalink / raw)


On 2022-02-02 18:21, hreba wrote:
> For the plugin scheme in my actual program I worked along the 
> corresponding gnat example, but while the original works, mine doesn't. 
> So I boiled it down to a minimum.
> 
> plugin.ads
> ----------
> 
> package Plugin is
>     procedure Empty;
> end Plugin;
> 
> plugin.adb
> ----------
> with Ada.Finalization;
> with Ada.Text_IO;
> 
> package body Plugin is
> 
>     type Life_Controller is new Ada.Finalization.Limited_Controlled with 
> null record;
>     overriding procedure Initialize (lc: in out Life_Controller);
>     overriding procedure Finalize (lc: in out Life_Controller);
> 
>     procedure Empty is
>     begin
>        null;
>     end Empty;
> 
>     overriding procedure Initialize (lc: in out Life_Controller) is
>     begin
>        Ada.Text_IO.Put_Line("Hello world!");
>     end Initialize;
> 
>     overriding procedure Finalize (lc: in out Life_Controller) is
>     begin
>        Ada.Text_IO.Put_Line("Bye world!");
>     end Finalize;
> 
>     lc:    Life_Controller;
> 
> end Plugin;
> 
> main.adb
> --------
> with System;
> with Interfaces.C.Strings;
> with Ada.Text_IO;
> 
> procedure Main is
> 
>     use type System.Address;
>     RTLD_LAZY:    constant := 1;
>     handle:    System.Address;
> 
>     function dlopen (Lib_Name: String; Mode: Interfaces.C.int)
>             return System.Address;
>     pragma Import (C, dlopen, "dlopen");
> 
> begin
>     handle:= dlopen ("../Plugin/lib/libplugin.so" & ASCII.NUL, RTLD_LAZY);
>     if handle = System.Null_Address then
>        Ada.Text_IO.Put_Line("unable to load plugin");
>     end if;
> end Main;
> 
> 
> Main executes without any output. My understanding is the following:
> 
>   - When plugin loading with dlopen fails, I get an error message.
>   - Otherwise, the controlled variable lc in plugin.adb comes to life and
>     I get an output from the Initialize procedure.
> 
> Where is my misconception?

Probably, you do not have automatic initialization of the Ada run-time.

    for Library_Auto_Init use "False";

Which is good, because under Windows would deadlock.

What you should do is:

1. Add an entry point to the library. Call it in order to return the 
expected minimum version of Main. It would add resilience. The 
implementation must be simple and not to require initialization. E.g.

    function get_required_version return Interfaces.C.unsigned;
    pragma Convention (C, get_required_version);

Use dlsym to get the address:

    type get_required_version_ptr is
       function return Interfaces.C.unsigned;
    pragma Convention (C, get_required_version_ptr);
    function dlsym
             (  handle : System.Address;
                symbol : char_array := "get_required_version" & NUL
             )  return get_required_version_ptr;
    pragma Import (C, dlsym);

2. Add another entry point like My_DLL_Init to call after version check. 
 From there first call to Ada run-time initialization. I believe it is named

    <library-name>init

After that you could do plug-in bookkeeping, calling registering 
subprograms etc.

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

^ permalink raw reply	[relevance 0%]

* Plugin with controlled variable for initialization.
@ 2022-02-02 17:21  1% hreba
  2022-02-02 18:05  0% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: hreba @ 2022-02-02 17:21 UTC (permalink / raw)


For the plugin scheme in my actual program I worked along the 
corresponding gnat example, but while the original works, mine doesn't. 
So I boiled it down to a minimum.

plugin.ads
----------

package Plugin is
    procedure Empty;
end Plugin;

plugin.adb
----------
with Ada.Finalization;
with Ada.Text_IO;

package body Plugin is

    type Life_Controller is new Ada.Finalization.Limited_Controlled with 
null record;
    overriding procedure Initialize (lc: in out Life_Controller);
    overriding procedure Finalize (lc: in out Life_Controller);

    procedure Empty is
    begin
       null;
    end Empty;

    overriding procedure Initialize (lc: in out Life_Controller) is
    begin
       Ada.Text_IO.Put_Line("Hello world!");
    end Initialize;

    overriding procedure Finalize (lc: in out Life_Controller) is
    begin
       Ada.Text_IO.Put_Line("Bye world!");
    end Finalize;

    lc:	Life_Controller;

end Plugin;

main.adb
--------
with System;
with Interfaces.C.Strings;
with Ada.Text_IO;

procedure Main is

    use type System.Address;
    RTLD_LAZY:	constant := 1;
    handle:	System.Address;

    function dlopen (Lib_Name: String; Mode: Interfaces.C.int)
		   return System.Address;
    pragma Import (C, dlopen, "dlopen");

begin
    handle:= dlopen ("../Plugin/lib/libplugin.so" & ASCII.NUL, RTLD_LAZY);
    if handle = System.Null_Address then
       Ada.Text_IO.Put_Line("unable to load plugin");
    end if;
end Main;


Main executes without any output. My understanding is the following:

  - When plugin loading with dlopen fails, I get an error message.
  - Otherwise, the controlled variable lc in plugin.adb comes to life and
    I get an output from the Initialize procedure.

Where is my misconception?
-- 
Frank Hrebabetzky, Kronach	+49 / 9261 / 950 0565

^ permalink raw reply	[relevance 1%]

* Generic formal ">"
@ 2022-01-26 16:54  1% Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2022-01-26 16:54 UTC (permalink / raw)


I have a generic with a formal private type Element_Type and a formal
function ">" (L, R : Element_Type) return Boolean. This gives me
puzzling and compiler-dependent behaviour when I instantiate with
">" => "<".

The output from the code below is

GCC 10.1.0:

   Data'Length: 2
   Data'Length > 1: TRUE
   Integer'(Data'Length) > 1: TRUE
   Standard.">" (Data'Length, 1): TRUE
   Standard.">" (Integer'(Data'Length), 1): TRUE

GCC 11.1.0:

   Data'Length: 2
   Data'Length > 1: FALSE
   Integer'(Data'Length) > 1: TRUE
   Standard.">" (Data'Length, 1): FALSE
   Standard.">" (Integer'(Data'Length), 1): TRUE

I don't know what version of ">" will be used when the unqualified
Data'Length is involved, but I would have expected that the overridden
("<") version would be used in the Integer'(Data'Length)
version. (Sorry, I don't think overridden is the right word).

GCC 10 uses the version from package standard even when given
integer-qualified data.

GCC 11 uses the version from package standard when given
integer-qualified data, and the overriding version when not.

Is it right that Standard.">" is getting overridden?

Have the rules changed in this area?

My "fix" was to compare Data'Length >= 2!

8X-------------------
with Ada.Text_IO; use Ada.Text_IO;
procedure Gen_Cmp is
   generic
      type Element_Type is private;
      type Index_Type is (<>);
      type Array_Type is array (Index_Type range <>) of Element_Type;
      with function ">" (Left, Right : Element_Type) return Boolean is <>;
   procedure Gen (Data: in out Array_Type);

   procedure Gen (Data: in out Array_Type) is
   begin
      Put_Line ("Data'Length:" & Data'Length'Image);
      Put_Line ("Data'Length > 1: "
                  & Boolean'Image (Data'Length > 1));
      Put_Line ("Integer'(Data'Length) > 1: "
                  & Boolean'Image (Integer'(Data'Length) > 1));
      Put_Line ("Standard."">"" (Data'Length, 1): "
                  & Boolean'Image (Standard.">" (Data'Length, 1)));
      Put_Line ("Standard."">"" (Integer'(Data'Length), 1): "
                  & Boolean'Image (Standard.">" (Integer'(Data'Length), 1)));
   end Gen;

   type Alpha is
     (A, B, C, D, E, F, G, H, I, J, K, L, M,
      N, O, P, Q, R, S, T, U, V, W, X, Y, Z);

   type My_Array is array (Alpha range <>) of Integer;

   procedure Chk_Down is new Gen (Element_Type => Integer,
                                  Index_Type   => Alpha,
                                  Array_Type   => My_Array,
                                  ">"          => "<");

   Data : My_Array (A .. B);
begin
   Chk_Down (Data);
end Gen_Cmp;

^ permalink raw reply	[relevance 1%]

* Re: Accessing Addresses in a Passed String
  @ 2022-01-01 20:57  1% ` Niklas Holsti
  0 siblings, 0 replies; 200+ results
From: Niklas Holsti @ 2022-01-01 20:57 UTC (permalink / raw)


On 2022-01-01 20:53, Pat Van Canada wrote:
> Hi Everyone.
> 
> Happy New Year!
> 
> I am stuck with a problem. I have an application were I must use 
> pointers despite the fact that I try to avoid them. >
> in the declarative section, I can write:
> 
>         str2 : aliased string( 1 .. 4 ) ;
> 
> and then I could potentially access the address of each character in the string.
> 
> However, I cannot use "aliased" in an argument list and worse yet,
> since it is effectively a character array, it will be passed by pointer.


While I agree with Dmitry that it would be better to find another 
solution to the root problem (whatever that is), here are some examples 
on how to do what you have tried to do, as an example program with some 
comments.


with Ada.Text_IO;

procedure AliChar
is

    type Astring is array (Positive range <>) of aliased Character;
    --
    -- If you want to set pointers to the elements, the elements must
    -- be marked "aliased"; it is not enough (nor needed) to mark the
    -- entire array (or type) as "aliased".
    --
    -- For this we have to define our own "string" type.

    A : Astring := "This is a string with aliased elements";

    type Char_Ptr is access all Character;

    C : constant Char_Ptr := A(4)'Access;

    B : Astring renames A(6 .. 11);

    BC : constant Char_Ptr := B(9)'Access;

    D : Char_Ptr;


    procedure PP (X : access Astring)
    --
    -- For a parameter, "aliased" is not enough to allow setting a
    -- non-local pointer to point at the parameter (or some part of
    -- it), but making the parameter "access" works. But then the
    -- actual parameter must be an access value; see below.
    --
    is
    begin
       D := X(X'First + 5)'Access;
    end PP;


    AA : aliased Astring := "An aliased string with aliased elements";
    --
    -- Since AA is itself aliased, we can take AA'Access.
    -- Since AA is an Astring, we can take AA(I)'Access for any valid I.

begin

    Ada.Text_IO.Put_Line (String (A));
    --
    -- The conversion to String is needed because Astring is not the
    -- same as String. However, they are similar enough for this
    -- conversion to work, in this direction at least.

    Ada.Text_IO.Put_Line (String (AA));

    Ada.Text_IO.Put_Line ("C.all = " & C.all & ", BC.all = " & BC.all);

    PP (AA'Access);

    Ada.Text_IO.Put_Line ("D.all = " & D.all);

    D.all := '?';

    Ada.Text_IO.Put_Line (String (AA));
    --
    -- The result is "An al?ased string with aliased elements".

end AliChar;


But, again agreeing with Dmitry, this is quite messy and should be the 
last-chance solution if nothing better is found. Your description (in a 
later post) of the root problem was not clear enough for me to suggest 
something better.

^ permalink raw reply	[relevance 1%]

* Ada.Numerics.Big_Numbers.Big_Integer has a limit of 300 digits?
@ 2021-12-22  5:57  1% Michael Ferguson
  0 siblings, 0 replies; 200+ results
From: Michael Ferguson @ 2021-12-22  5:57 UTC (permalink / raw)


I just started using the Big_Integer library that is a part of the 202X version of ADA.

It is repeatedly described as an "arbitrary precision library" that has user defined implementation.

I was under the impression that this library would be able to infinitely calculate numbers of any length, but there is clearly a default limit of 300 digits.

Is there any way to get rid of this problem?

Here is some example code:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Numerics.Big_Numbers.Big_Integers;
use Ada.Numerics.Big_Numbers.Big_Integers;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Test is
package Time_IO is new Fixed_IO(Duration);
start_time, end_time : Ada.Real_Time.Time;
elapsed_seconds : Ada.Real_Time.Time_Span;
solution : Unbounded_String;

rop : Big_Integer;
sum : Big_Integer := 0;

begin
start_time := Ada.Real_Time.Clock;

for i in 1..700 loop
rop := To_Big_Integer(i) ** Natural(i);
sum := sum + rop;
end loop;
solution := To_Unbounded_String(sum'Image);


end_time := Ada.Real_Time.Clock;
elapsed_seconds := end_time - start_time;
Put("Solution: " & solution'Image); New_Line; New_Line;
Put("Program completed in ");
Time_IO.Put(To_Duration(elapsed_seconds), Fore => 0, Aft => 3);
Put(" seconds");
end BigTest;

^ permalink raw reply	[relevance 1%]

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 23:10  1%     ` Jeffrey R.Carter
@ 2021-11-19  0:06  1%       ` Ken Roberts
  0 siblings, 0 replies; 200+ results
From: Ken Roberts @ 2021-11-19  0:06 UTC (permalink / raw)


Sorry for the delay in getting back - $DAYJOB and $ILLNESS combined.

On Mon, Nov 15, 2021 at 3:10 PM Jeffrey R.Carter <deleted> wrote:
On 2021-11-15 23:09, Ken Roberts wrote:
> I was going to add before your reply that I'm trying to get output without the extra padding of showing the base.

Ada.Text_IO.Integer_IO and Ada.Text_IO.Modular_IO both declare

      Default_Base  : Number_Base := 10;

This is a variable, so you can change it.

However, that outputs in based-literal format.

You can use PragmARC.Images (https://github.com/jrcarter/PragmARC) to
obtain images in any base without the base information. Image width and
zero filling are also provided.

--
Jeff Carter

Hmmm. After testing by setting the base manually after instantiation, still adds the based-literal information as noted.

So, it's either copy Modular_IO into my project (with renaming) and change the default base, or add another package to monitor for updates.

Fun either way.

Thanks for the help both Jeff and Ben. (Sincerely, not ironically).

^ permalink raw reply	[relevance 1%]

* Re: Integer_IO or Modular_IO with different base as default
  @ 2021-11-15 23:10  1%     ` Jeffrey R.Carter
  2021-11-19  0:06  1%       ` Ken Roberts
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2021-11-15 23:10 UTC (permalink / raw)


On 2021-11-15 23:09, Ken Roberts wrote:
> I was going to add before your reply that I'm trying to get output without the extra padding of showing the base.

Ada.Text_IO.Integer_IO and Ada.Text_IO.Modular_IO both declare

      Default_Base  : Number_Base := 10;

This is a variable, so you can change it.

However, that outputs in based-literal format.

You can use PragmARC.Images (https://github.com/jrcarter/PragmARC) to 
obtain images in any base without the base information. Image width and 
zero filling are also provided.

-- 
Jeff Carter
"I spun around, and there I was, face to face with a
six-year-old kid. Well, I just threw my guns down and
walked away. Little bastard shot me in the ass."
Blazing Saddles
40

^ permalink raw reply	[relevance 1%]

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 21:27  1% Integer_IO or Modular_IO with different base as default Ken Roberts
  2021-11-15 21:40  0% ` Simon Wright
@ 2021-11-15 22:13  1% ` Ben Bacarisse
  1 sibling, 0 replies; 200+ results
From: Ben Bacarisse @ 2021-11-15 22:13 UTC (permalink / raw)


Ken Roberts <alisonken1@gmail.com> writes:

> Does anyone have an idea on how to instantiate Integer_IO (or
> Modular_IO) with Default_Base := 8 ?

Instantiate Integer_IO and then assign Default_Base := 8:

with Ada.Text_IO; use Ada.Text_IO;
procedure Oct is
  package Oct_IO is new Integer_IO(Integer);
begin
  Oct_IO.Default_Base := 8;
  Oct_IO.Put(16);
end Oct;

(Add "use Oct_IO;" if you prefer.)

I don't think there is a way to do this on instantiation so that
Default_Base is 8 and can't be changed, which would be nice.  (Note: my
Ada is /very/ rusty.  Take /anyone's/ answer over mine about this!)

-- 
Ben.

^ permalink raw reply	[relevance 1%]

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 21:27  1% Integer_IO or Modular_IO with different base as default Ken Roberts
@ 2021-11-15 21:40  0% ` Simon Wright
    2021-11-15 22:13  1% ` Ben Bacarisse
  1 sibling, 1 reply; 200+ results
From: Simon Wright @ 2021-11-15 21:40 UTC (permalink / raw)


Ken Roberts <alisonken1@gmail.com> writes:

> I've been trying to look at how to instantiate Ada.Text_IO.Integer_IO
> and Ada.Text_IO.Modular_IO with a different base as default (base 8
> for a project I'm playing with while learning).
>
> So far, the only thing I can find is instantiate with a different
> integer (or mod number), but the base is always defined as 10.
>
> I'd like to output numbers for the project in base 8 (octal) in
> keeping with the documentation on how the digital system works.

You can't change Default_Base, but you can specify the base in which to
output the number, as in ARM A.10.8(11):

   procedure Put(File  : in File_Type;
                 Item  : in Num;
                 Width : in Field := Default_Width;
                 Base  : in Number_Base := Default_Base);

   procedure Put(Item  : in Num;
                 Width : in Field := Default_Width;
                 Base  : in Number_Base := Default_Base);

e.g.

   Put (10, Base => 8);

outputs

   8#12#

^ permalink raw reply	[relevance 0%]

* Integer_IO or Modular_IO with different base as default
@ 2021-11-15 21:27  1% Ken Roberts
  2021-11-15 21:40  0% ` Simon Wright
  2021-11-15 22:13  1% ` Ben Bacarisse
  0 siblings, 2 replies; 200+ results
From: Ken Roberts @ 2021-11-15 21:27 UTC (permalink / raw)


I've been trying to look at how to instantiate Ada.Text_IO.Integer_IO and Ada.Text_IO.Modular_IO with a different base as default (base 8 for a project I'm playing with while learning).

So far, the only thing I can find is instantiate with a different integer (or mod number), but the base is always defined as 10.

I'd like to output numbers for the project in base 8 (octal) in keeping with the documentation on how the digital system works.

Does anyone have an idea on how to instantiate Integer_IO (or Modular_IO) with Default_Base := 8 ?

So far, the only thing I've been able to work with is copy Ada.Text_IO.Integer_IO (or Modular_IO) in my project as a different package with the only change being the Default_Base parameter.

Any help with noob questions would be appreciated.

^ permalink raw reply	[relevance 1%]

* Re: Beginners question
  2021-11-12 15:24  0% ` Niklas Holsti
@ 2021-11-12 15:44  0%   ` uq5huo...@gmail.com
  0 siblings, 0 replies; 200+ results
From: uq5huo...@gmail.com @ 2021-11-12 15:44 UTC (permalink / raw)


Niklas Holsti schrieb am Freitag, 12. November 2021 um 16:24:20 UTC+1:
> On 2021-11-12 16:32, uq5huo...@gmail.com wrote: 
> > Hi, 
> > 
> > I'm beginning to play with Ada, and run into this 
> > 
> > with Ada.Text_IO; use Ada.Text_IO; 
> > procedure Learn is 
> > subtype Alphabet is Character range 'A' .. 'Z'; 
> > begin 
> > Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last); 
> > end Learn; 
> > 
> > Now I want to play a bit with the code ... and this fails and I don't get why and how to solve. 
> > 
> > Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last-1); 
> > or 
> > Put_Line ("Learning Ada from " & Alphabet'First & " to " & (Alphabet'Last-1)); 
> > 
> > Anyone more expirienced can explain this to my, please?
> The Character type is not an integer type (unlike "char" in C), so you 
> cannot subtract 1 from a Character (or an Alphabet value). Character is 
> an enumeration type in Ada. 
> 
> To get the Alphabet value immediately preceding Alphabet'Last, use the 
> Pred ("predecessor") attribute function: 
> 
> Alphabet'Pred (Alphabet'Last) 
> 
> If you need to take larger strides in the Alphabet enumeration, you can 
> use the Pos and Val attribute functions. Pos returns the "position 
> number" of its argument, and that is an integer. Val performs the 
> opposite mapping. For example, to get the Alphabet value that is three 
> positions before Alphabet'Last, you can do 
> 
> Alphabet'Val (Alphabet'Pos (Alphabet'Last) - 3)

Dear Niklas, 
thanks for the explanation. So I run into the strong typing and Ada prevents me to programm C-like. I really like that. :-) 
I will read more onto the  attributes to get familar with this. 

^ permalink raw reply	[relevance 0%]

* Re: Beginners question
  2021-11-12 14:32  1% Beginners question uq5huo...@gmail.com
@ 2021-11-12 15:24  0% ` Niklas Holsti
  2021-11-12 15:44  0%   ` uq5huo...@gmail.com
  0 siblings, 1 reply; 200+ results
From: Niklas Holsti @ 2021-11-12 15:24 UTC (permalink / raw)


On 2021-11-12 16:32, uq5huo...@gmail.com wrote:
> Hi,
> 
> I'm beginning to play with Ada, and run into this
> 
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Learn is
>     subtype Alphabet is Character range 'A' .. 'Z';
> begin
>     Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last);
> end Learn;
> 
> Now I want to play a bit with the code ... and this fails and I don't get why and how to solve.
> 
> Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last-1);
> or
> Put_Line ("Learning Ada from " & Alphabet'First & " to " & (Alphabet'Last-1));
> 
> Anyone more expirienced can explain this to my, please?


The Character type is not an integer type (unlike "char" in C), so you 
cannot subtract 1 from a Character (or an Alphabet value). Character is 
an enumeration type in Ada.

To get the Alphabet value immediately preceding Alphabet'Last, use the 
Pred ("predecessor") attribute function:

    Alphabet'Pred (Alphabet'Last)

If you need to take larger strides in the Alphabet enumeration, you can 
use the Pos and Val attribute functions. Pos returns the "position 
number" of its argument, and that is an integer. Val performs the 
opposite mapping. For example, to get the Alphabet value that is three 
positions before Alphabet'Last, you can do

    Alphabet'Val (Alphabet'Pos (Alphabet'Last) - 3)

^ permalink raw reply	[relevance 0%]

* Beginners question
@ 2021-11-12 14:32  1% uq5huo...@gmail.com
  2021-11-12 15:24  0% ` Niklas Holsti
  0 siblings, 1 reply; 200+ results
From: uq5huo...@gmail.com @ 2021-11-12 14:32 UTC (permalink / raw)


Hi, 

I'm beginning to play with Ada, and run into this

with Ada.Text_IO; use Ada.Text_IO;
procedure Learn is
   subtype Alphabet is Character range 'A' .. 'Z';
begin
   Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last);
end Learn;

Now I want to play a bit with the code ... and this fails and I don't get why and how to solve. 

Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last-1);
or 
Put_Line ("Learning Ada from " & Alphabet'First & " to " & (Alphabet'Last-1));

Anyone more expirienced can explain this to my, please?

^ permalink raw reply	[relevance 1%]

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23 10:22  2% ` Jeffrey R.Carter
  2021-10-23 12:28  1%   ` reinert
@ 2021-10-24 20:51  1%   ` Keith Thompson
  1 sibling, 0 replies; 200+ results
From: Keith Thompson @ 2021-10-24 20:51 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
> On 10/23/21 10:06, reinert wrote:
>> So how can I test if "file1" referes to the terminal using the
>> lastest GNAT Community Edition?
>
> Have you tried
>
> Ada.Text_IO.Name (File1) = Ada.Text_IO.Name (Ada.Text_IO.Standard_Input)
>
> ? (I haven't.)

That might well serve reinert's needs, but strictly speaking it doesn't
tell you whether File1 refers to the terminal.  At best it might tell
you whether File1 and Standard_Input refer to the same external file --
which may not even be a terminal if standard input was redirected.

GNAT apparently uses "*stdin" as the Name of Standard_Input, regardless
of what actual file it refers to.  There could be an actual file with
that name.  It's not likely, but it means that this method could be
broken maliciously.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[relevance 1%]

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23 12:28  1%   ` reinert
@ 2021-10-23 15:40  2%     ` Gautier write-only address
  0 siblings, 0 replies; 200+ results
From: Gautier write-only address @ 2021-10-23 15:40 UTC (permalink / raw)


Le samedi 23 octobre 2021 à 14:28:24 UTC+2, reinert a écrit :
> Yes, now it compiles ! 

Interesting to see what name GNAT gives to Standard_Input:

with Ada.Text_IO;

procedure SIO is
begin
  Ada.Text_IO.Put_Line ('[' & Ada.Text_IO.Name (Ada.Text_IO.Standard_Input) & ']');
  Ada.Text_IO.Put_Line ('[' & Ada.Text_IO.Name (Ada.Text_IO.Standard_Error) & ']');
end;

[*stdin]
[*stderr]

^ permalink raw reply	[relevance 2%]

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23 10:22  2% ` Jeffrey R.Carter
@ 2021-10-23 12:28  1%   ` reinert
  2021-10-23 15:40  2%     ` Gautier write-only address
  2021-10-24 20:51  1%   ` Keith Thompson
  1 sibling, 1 reply; 200+ results
From: reinert @ 2021-10-23 12:28 UTC (permalink / raw)


Yes, now it compiles !

reinert

lørdag 23. oktober 2021 kl. 12:22:40 UTC+2 skrev Jeffrey R.Carter:
> On 10/23/21 10:06, reinert wrote: 
> > 
> > So how can I test if "file1" referes to the terminal using the lastest GNAT Community Edition?
> Have you tried 
> 
> Ada.Text_IO.Name (File1) = Ada.Text_IO.Name (Ada.Text_IO.Standard_Input) 
> 
> ? (I haven't.) 
> 
> -- 
> Jeff Carter 
> "C++: The power, elegance and simplicity of a hand grenade." 
> Ole-Hjalmar Kristensen 
> 90

^ permalink raw reply	[relevance 1%]

* Re: How to test if file = Ada.Text_IO.Standard_Input ?
  2021-10-23  8:06  2% How to test if file = Ada.Text_IO.Standard_Input ? reinert
@ 2021-10-23 10:22  2% ` Jeffrey R.Carter
  2021-10-23 12:28  1%   ` reinert
  2021-10-24 20:51  1%   ` Keith Thompson
  0 siblings, 2 replies; 200+ results
From: Jeffrey R.Carter @ 2021-10-23 10:22 UTC (permalink / raw)


On 10/23/21 10:06, reinert wrote:
> 
> So how can I test if "file1" referes to the terminal using the lastest GNAT Community Edition?

Have you tried

Ada.Text_IO.Name (File1) = Ada.Text_IO.Name (Ada.Text_IO.Standard_Input)

? (I haven't.)

-- 
Jeff Carter
"C++: The power, elegance and simplicity of a hand grenade."
Ole-Hjalmar Kristensen
90

^ permalink raw reply	[relevance 2%]

* How to test if file = Ada.Text_IO.Standard_Input ?
@ 2021-10-23  8:06  2% reinert
  2021-10-23 10:22  2% ` Jeffrey R.Carter
  0 siblings, 1 reply; 200+ results
From: reinert @ 2021-10-23  8:06 UTC (permalink / raw)


Hello,

the following program:

  procedure test1 (file1 : in Ada.Text_IO.File_Type) is
      term1 : constant Boolean := file1 in Ada.Text_IO.Standard_Input;
   begin
      null;
   end test1;

compiles under gnat-10 (debian). The point here is to test if "file1" represents the terminal.

However, when I try to compile using the current GNAT Community Edition from AdaCore, I get the error:

test7.adb:38:41: error: invalid operand types for operator "="
test7.adb:38:41: error: left operand has private type "Ada.Text_Io.File_Type"
test7.adb:38:41: error: right operand has type "Ada.Text_Io.File_Access"
gnatmake: "test7.adb" compilation error

So how can I test if "file1" referes to the terminal using the lastest GNAT Community Edition?

reinert

^ permalink raw reply	[relevance 2%]

* Re: On absurdity of collections 7.6.1 (11.1/3)
  2021-09-29 21:38  1%     ` Simon Wright
@ 2021-09-30  8:07  0%       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-09-30  8:07 UTC (permalink / raw)


On 2021-09-29 23:38, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On 2021-09-29 13:05, Simon Wright wrote:
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>>
>>>>         type Item_Ptr is access all Item;
>>>>         function New_Item
>>>>                  (  Pool : in out Root_Storage_Pool'Class;
>>>>                     Text : String
>>>>                  )  return Item_Ptr;
>>> What I don't see is how you can implement this, never mind any other
>>> problems.
>>
>> A naive, but wrong due to 7.6.1 (11.1/3) nonsense, implementation would be:
>>
>>       function New_Item
>>                (  Pool : in out Root_Storage_Pool'Class;
>>                   Text : String
>>                )  return Item_Ptr is
>>          type Ptr is access Item;
>>          for Ptr'Storage_Pool use Pool;
>>          Object : Ptr := new Item (Text'Length);
>>       begin
>>          Object.Text := Text;
>>          return Object.all'Unchecked_Access;
>>       end New_Item;
> 
> OK, that code compiles.
> 
> What you'd need to happen when the returned Item_Ptr is freed would be
> for the mechanism of the actual pool to be invoked. But Item_Ptr was
> declared without any pool specified, so uses the default, and when the
> returned Item_Ptr is freed it uses the default pool's mechanism.

That would be another language bug, if true, because 13.11.2 is silent 
about that. But the first bug is that New_Item is not implementable, 
well it actually is, but in a very clumsy way (see my answer to Randy).

> But of course what actually happens with this code is that the returned
> Item_Ptr is left dangling; my test
> 
>     with P;
>     with System.Pool_Local;   -- GNAT special
>     with Ada.Text_IO; use Ada.Text_IO;
>     procedure Test is
>        use P;
>        Pool : System.Pool_Local.Unbounded_Reclaim_Pool;
>        Ptr : Item_Ptr := New_Item (Pool, "hello");
>     begin
>        Put_Line (Ptr.Text);
>        Free (Ptr);
>     end Test;
> 
> manages flukily to print "hello" before crashing at the Free (Ptr).

It should print it twice, because Finalize must be called twice. Once 
inside New_Item, then in Free.

> I don't see how what you want can be achieved without every access type
> containing a reference to the pool the object was allocated from.

Yes, every general access type that permits instantiation of 
Unchecked_Dellocation must indicate the target object's pool, directly, 
e.g. per fat pointer, or indirectly by some other schema. I see nothing 
in RM that allows a different implementation. But it is could be a bug 
by omission and I am not a language lawyer anyway.

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

^ permalink raw reply	[relevance 0%]

* Re: On absurdity of collections 7.6.1 (11.1/3)
  @ 2021-09-29 21:38  1%     ` Simon Wright
  2021-09-30  8:07  0%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2021-09-29 21:38 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2021-09-29 13:05, Simon Wright wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> 
>>>        type Item_Ptr is access all Item;
>>>        function New_Item
>>>                 (  Pool : in out Root_Storage_Pool'Class;
>>>                    Text : String
>>>                 )  return Item_Ptr;
>> What I don't see is how you can implement this, never mind any other
>> problems.
>
> A naive, but wrong due to 7.6.1 (11.1/3) nonsense, implementation would be:
>
>      function New_Item
>               (  Pool : in out Root_Storage_Pool'Class;
>                  Text : String
>               )  return Item_Ptr is
>         type Ptr is access Item;
>         for Ptr'Storage_Pool use Pool;
>         Object : Ptr := new Item (Text'Length);
>      begin
>         Object.Text := Text;
>         return Object.all'Unchecked_Access;
>      end New_Item;

OK, that code compiles.

What you'd need to happen when the returned Item_Ptr is freed would be
for the mechanism of the actual pool to be invoked. But Item_Ptr was
declared without any pool specified, so uses the default, and when the
returned Item_Ptr is freed it uses the default pool's mechanism.

But of course what actually happens with this code is that the returned
Item_Ptr is left dangling; my test

   with P;
   with System.Pool_Local;   -- GNAT special
   with Ada.Text_IO; use Ada.Text_IO;
   procedure Test is
      use P;
      Pool : System.Pool_Local.Unbounded_Reclaim_Pool;
      Ptr : Item_Ptr := New_Item (Pool, "hello");
   begin
      Put_Line (Ptr.Text);
      Free (Ptr);
   end Test;

manages flukily to print "hello" before crashing at the Free (Ptr).

I don't see how what you want can be achieved without every access type
containing a reference to the pool the object was allocated from.

^ permalink raw reply	[relevance 1%]

* Oddity with function returning image of fixed point type
@ 2021-09-02 10:25  1% Jesper Quorning
  0 siblings, 0 replies; 200+ results
From: Jesper Quorning @ 2021-09-02 10:25 UTC (permalink / raw)


Is something odd going on here?
I did not expect Image_Odd1/2 to return floating point images.


with Ada.Text_Io;     use Ada.Text_Io;

procedure Fpt_Last is

   type Fpt is delta 0.01 digits 4;

   Image_Last : constant String := Fpt'Image (Fpt'Last);

   function Image_Ok return String is
   begin
      return Fpt'Last'Image;
      --  return Fpt'Image (Fpt'Last); -- Also ok
   end Image_Ok;

   Last : constant Fpt := Fpt'Last;

   function Image_Odd_1 return String is (Fpt'Last'Img);
   function Image_Odd_2 return String is (Fpt'Last'Image);
   function Image_Ok_2  return String is (Fpt'Image (FPT'Last));
   function Image_Ok_3  return String is (Last'Image);

begin
   Put_Line ("Image_Last  : " & Image_Last);
   Put_Line ("Image_Ok    : " & Image_Ok);
   Put_Line ("Image_Odd_1 : " & Image_Odd_1);
   Put_Line ("Image_Odd_2 : " & Image_Odd_2);
   Put_Line ("Image_Ok_2  : " & Image_Ok_2);
   Put_Line ("Image_Ok_3  : " & Image_Ok_3);
end Fpt_Last;


Output:

Image_Last  :  99.99
Image_Ok    :  99.99
Image_Odd_1 :  9.99900000000000000E+01
Image_Odd_2 :  9.99900000000000000E+01
Image_Ok_2  :  99.99
Image_Ok_3  :  99.99

Compiled with gnatmake version 10.3.0 or CE 2020 on macOS 10.13.6.


/Jesper

^ permalink raw reply	[relevance 1%]

* Re: Get_Line skip input
  2021-08-26  9:09  1% ` Jeffrey R. Carter
@ 2021-08-27  2:55  0%   ` Richard Iswara
  0 siblings, 0 replies; 200+ results
From: Richard Iswara @ 2021-08-27  2:55 UTC (permalink / raw)


On 26/08/2021 16.09, Jeffrey R. Carter wrote:
> On 8/26/21 7:36 AM, Richard Iswara wrote:
>>
>> So on the terminal it shows like this:
>> Keywords number 1 =  Enter Multiplier for keyword <here cursor wait 
>> for entry>
>> Keywords number 2 =  Enter Multiplier for keyword <here cursor wait 
>> for entry>
> 
> I set Kw_Numbers to 3 and added an output loop after the input loop:
> 
>     for I in Key_Words'Range loop
>        Ada.Text_IO.Put_Line (Item => I'Image & ' ' &
>                                      Key_Words (I) (1 .. W_Len (I) ) &
>                                      Multiplier (I)'Image);
>     end loop;
> 
> I am unable to duplicate this behavior:
> 
> ~/Code$ ./kw_test
> Enter keywords less than 10 characters.
> Keywords number 1 = one
> Enter multiplier for keyword 7
> 
> Keywords number 2 = Enter multiplier for keyword 6
> 
> Keywords number 3 = Enter multiplier for keyword 3
> 
>   1 one 7
>   2  6
>   3  3
> 
> As Holsti explained, this behavior is due to Ada.Integer_Text_IO.Get 
> behaving as specified, leaving the rest of the line available to Get_Line:
> 
> ~/Code$ ./kw_test
> Enter keywords less than 10 characters.
> Keywords number 1 = one
> Enter multiplier for keyword 7
> 
> Keywords number 2 = Enter multiplier for keyword 6
> 
> Keywords number 3 = Enter multiplier for keyword 3
> 
>   1 one 7
>   2  6
>   3  3
> ~/Code$ ./kw_test
> Enter keywords less than 10 characters.
> Keywords number 1 = one
> Enter multiplier for keyword 7two
> 
> Keywords number 2 = Enter multiplier for keyword 6three
> 
> Keywords number 3 = Enter multiplier for keyword 3
> 
>   1 one 7
>   2 two 6
>   3 three 3
> 
> In general, I recommend obtaining a complete line and parsing it, rather 
> than inputting values with Get:
> 
> Get_Mult : loop
>     Ada.Text_IO.Put (Item => "Enter multiplier for keyword ");
> 
>     One_Mult : declare
>        Line : constant String := Ada.Text_IO.Get_Line;
>     begin -- One_Mult
>        Multiplier (I) := Integer'Value (Line);
> 
>        exit Get_Mult;
>     exception -- One_Mult
>     when others =>
>        Ada.Text_IO.Put_Line (Item => "Enter an non-negative integer");
>     end One_Mult;
> end loop Get_Mult;
> 
> In general such code has to handle errors in the input. Users will input 
> key words > the specified max and non-numeric multipliers. Error 
> handling is simplified if one obtains complete lines (using the Get_Line 
> function) and deals with them.
> 
> Back in the Good Old Days (TM), I started off using FORTRAN 66 (it was 
> always written FORTRAN because the keypunches only had capital letters), 
> where the only data structure was the array. Things that would be an 
> array of records in a decent language were represented as groups of 
> parallel arrays. That seems to be what you're doing here.
> 
> subtype KW_Name_Length is Integer range 0 .. 10;
> 
> type Key_Word_Info (Length : KW_Name_Length := 0) is record
>     Name : String (1 .. Length);
>     Multiplier : Natural;
> end record;
> 
> Num_KW : constant := 3;
> 
> type KW_List is array (1 .. Num_KW) of Key_Word_Info;
> 
> Key_Word : KW_List;
> 
Thank you Niklas and Jeffrey for the explanation and the better way to 
do an input message.
Regards,
Richard.

^ permalink raw reply	[relevance 0%]

* Re: Get_Line skip input
  2021-08-26  5:36  1% Get_Line skip input Richard Iswara
  2021-08-26  7:56  1% ` Niklas Holsti
@ 2021-08-26  9:09  1% ` Jeffrey R. Carter
  2021-08-27  2:55  0%   ` Richard Iswara
  1 sibling, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2021-08-26  9:09 UTC (permalink / raw)


On 8/26/21 7:36 AM, Richard Iswara wrote:
> 
> So on the terminal it shows like this:
> Keywords number 1 =  Enter Multiplier for keyword <here cursor wait for entry>
> Keywords number 2 =  Enter Multiplier for keyword <here cursor wait for entry>

I set Kw_Numbers to 3 and added an output loop after the input loop:

    for I in Key_Words'Range loop
       Ada.Text_IO.Put_Line (Item => I'Image & ' ' &
                                     Key_Words (I) (1 .. W_Len (I) ) &
                                     Multiplier (I)'Image);
    end loop;

I am unable to duplicate this behavior:

~/Code$ ./kw_test
Enter keywords less than 10 characters.
Keywords number 1 = one
Enter multiplier for keyword 7

Keywords number 2 = Enter multiplier for keyword 6

Keywords number 3 = Enter multiplier for keyword 3

  1 one 7
  2  6
  3  3

As Holsti explained, this behavior is due to Ada.Integer_Text_IO.Get behaving as 
specified, leaving the rest of the line available to Get_Line:

~/Code$ ./kw_test
Enter keywords less than 10 characters.
Keywords number 1 = one
Enter multiplier for keyword 7

Keywords number 2 = Enter multiplier for keyword 6

Keywords number 3 = Enter multiplier for keyword 3

  1 one 7
  2  6
  3  3
~/Code$ ./kw_test
Enter keywords less than 10 characters.
Keywords number 1 = one
Enter multiplier for keyword 7two

Keywords number 2 = Enter multiplier for keyword 6three

Keywords number 3 = Enter multiplier for keyword 3

  1 one 7
  2 two 6
  3 three 3

In general, I recommend obtaining a complete line and parsing it, rather than 
inputting values with Get:

Get_Mult : loop
    Ada.Text_IO.Put (Item => "Enter multiplier for keyword ");

    One_Mult : declare
       Line : constant String := Ada.Text_IO.Get_Line;
    begin -- One_Mult
       Multiplier (I) := Integer'Value (Line);

       exit Get_Mult;
    exception -- One_Mult
    when others =>
       Ada.Text_IO.Put_Line (Item => "Enter an non-negative integer");
    end One_Mult;
end loop Get_Mult;

In general such code has to handle errors in the input. Users will input key 
words > the specified max and non-numeric multipliers. Error handling is 
simplified if one obtains complete lines (using the Get_Line function) and deals 
with them.

Back in the Good Old Days (TM), I started off using FORTRAN 66 (it was always 
written FORTRAN because the keypunches only had capital letters), where the only 
data structure was the array. Things that would be an array of records in a 
decent language were represented as groups of parallel arrays. That seems to be 
what you're doing here.

subtype KW_Name_Length is Integer range 0 .. 10;

type Key_Word_Info (Length : KW_Name_Length := 0) is record
    Name : String (1 .. Length);
    Multiplier : Natural;
end record;

Num_KW : constant := 3;

type KW_List is array (1 .. Num_KW) of Key_Word_Info;

Key_Word : KW_List;

-- 
Jeff Carter
"Why don't you bore a hole in yourself and let the sap run out?"
Horse Feathers
49

^ permalink raw reply	[relevance 1%]

* Re: Get_Line skip input
  2021-08-26  5:36  1% Get_Line skip input Richard Iswara
@ 2021-08-26  7:56  1% ` Niklas Holsti
  2021-08-26  9:09  1% ` Jeffrey R. Carter
  1 sibling, 0 replies; 200+ results
From: Niklas Holsti @ 2021-08-26  7:56 UTC (permalink / raw)


On 2021-08-26 8:36, Richard Iswara wrote:
> Why do Get_Line skipped the input? I have the following code:
> 
>     -- late declaration of Key words string array
>     declare
>        type Kw_Array is array (1 .. Kw_Numbers) of String (1 .. 10);
>        Key_Words : Kw_Array;
>        type W_Len_Array is array (1 .. Kw_Numbers) of Natural;
>        W_Len, Multiplier : W_Len_Array;
> 
>     begin
>        Ada.Text_IO.Put_Line ("Enter keywords less than 10 characters.");
>        for i in 1 .. Kw_Numbers loop
>           Ada.Text_IO.Put ("Keywords number ");
>           Ada.Integer_Text_IO.Put (i, 1);
>           Ada.Text_IO.Put (" = ");
> +         Ada.Text_IO.Get_Line (Key_Words (i), W_Len (i));
>  >         Ada.Text_IO.Put("Enter multiplier for keyword ");
>  >         Ada.Integer_Text_IO.Get(Multiplier(i),1);


Integer_Text_IO.Get does not read the /whole/ line that contains the 
multiplier -- it only reads the multiplier, but not the "end of line".
Insert this to skip (ignore) the rest of that input line and advance to 
the start of the next input line (which will hold the next keyword):

             Ada.Text_IO.Skip_Line;

>           Ada.Text_IO.New_Line;
>        end loop;
>     end;


As it was, because Integer_Text_IO.Get left the input pointer on the 
multiplier line, the next Get_Line read an empty next keyword (or 
whatever you typed on the multiplier line /after/ the multiplier 
digits), without needing more user input. Skip_Line should correct that.

^ permalink raw reply	[relevance 1%]

* Get_Line skip input
@ 2021-08-26  5:36  1% Richard Iswara
  2021-08-26  7:56  1% ` Niklas Holsti
  2021-08-26  9:09  1% ` Jeffrey R. Carter
  0 siblings, 2 replies; 200+ results
From: Richard Iswara @ 2021-08-26  5:36 UTC (permalink / raw)


Why do Get_Line skipped the input? I have the following code:

    -- late declaration of Key words string array
    declare
       type Kw_Array is array (1 .. Kw_Numbers) of String (1 .. 10);
       Key_Words : Kw_Array;
       type W_Len_Array is array (1 .. Kw_Numbers) of Natural;
       W_Len, Multiplier : W_Len_Array;

    begin
       Ada.Text_IO.Put_Line ("Enter keywords less than 10 characters.");
       for i in 1 .. Kw_Numbers loop
          Ada.Text_IO.Put ("Keywords number ");
          Ada.Integer_Text_IO.Put (i, 1);
          Ada.Text_IO.Put (" = ");
+         Ada.Text_IO.Get_Line (Key_Words (i), W_Len (i));
 >         Ada.Text_IO.Put("Enter multiplier for keyword ");
 >         Ada.Integer_Text_IO.Get(Multiplier(i),1);
          Ada.Text_IO.New_Line;
       end loop;
    end;

Before I put the two lines marked above, the executable only skipped the 
first instance of keyword entry.
After I put those two lines, the executable completely skipped the 
Get_Line part.
So on the terminal it shows like this:
Keywords number 1 =  Enter Multiplier for keyword <here cursor wait for 
entry>
Keywords number 2 =  Enter Multiplier for keyword <here cursor wait for 
entry>

If I modifies the line marked + into Get (Key_Words (i) (1..W_Len(i))) 
the compiler complain I did not assign W_Len. Most likely I get the 
syntax incorrect.

What do I do wrong on the original code?

^ permalink raw reply	[relevance 1%]

* Re: Building the 2021 source release of GnatStudio
  @ 2021-07-31 12:29  1%                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-07-31 12:29 UTC (permalink / raw)


On 2021-07-31 13:58, Stéphane Rivière wrote:
>> The HAC script must take Argument, call Square (accessible via the
>> module), return the result of Square (Argument).
> 
> API HAC has Argument, Argument_Count and Set_Exit_Status, and the result
> can be piped.

Whatever, you could post a complete example, when ready (:-)).

E.g. here is a lesser sample in Julia, an Ada subprogram is called from 
Julia back when Julia is called from Ada:
----------------------------------------------------------
with Ada.Text_IO;   use Ada.Text_IO;
with Interfaces.C;  use Interfaces.C;
with Julia;         use Julia;

procedure Ada_Call is
    Bin : constant String := "D:\Julia-1.2.0\bin";
begin
    Load (Bin & "\libjulia.dll");  -- Load library
    Init_With_Image (Bin);    -- Initialize environment

    declare
       function Increment (X : Double) return Double;
       pragma Convention (C, Increment);

       function Increment (X : Double) return Double is
       begin
          return X + 1.0;
       end Increment;
    begin
       Eval_String
       (  "println(ccall("
       &  CCall_Address (Increment'Address)
       &  ",Cdouble,(Cdouble,),10.0))"
       );
    end;

    AtExit_Hook;  -- Finalize environment
end Ada_Call;

Note, there is only one process!
-----------------------------------------------------------
> However, I do not state HAC is production ready for GNATStudio... But
> HAC is well written and easily hackable (I speak for Gautier ;)

That is not the point. The point is that AFAIK it cannot be used for 
scripting unless examples as above provided.

>> What AdaCore *must* do is to remove static linking to Python. The GPS
>> user should choose the script language per preferences that would look
>> for the corresponding script run-time e.g. Python or HAC or whatever.
> 
> Freedom choice. I agree. But I guess Adacore ressources are limited and
> this is like reinventing the wheel.

It is a minimal requirement to replace static linking with dynamic.

Moreover, whatever resources AdaCore has it does not make any sense to 
call internal GPS functions implemented in Ada from Ada code via Python 
scripts! So, no work involved.

> The biggest complaint I had about GNATStudio was its instability. I
> think that Adacore has made great progress now. It's now a pleasure to
> work with.

Yes, but each new version of GTK can change that. GTK is unstable on 
both Windows and Linux, it is just as it is. AdaCore can at best work 
around GTK bugs.

Though Python is 100% self-inflicted damage. AdaCore could easily 
implement some Ada script, again, not to confuse with shell. They did it 
partially with GPR. The GPR compiler could be extended to support a 
larger variety of expressions.

Customers wanting Python will use Eclipse instead of GPS anyway, so that 
is not an argument either.

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

^ permalink raw reply	[relevance 1%]

* Re: Building the 2021 source release of GnatStudio
  @ 2021-07-31 10:30  1%             ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2021-07-31 10:30 UTC (permalink / raw)


On 2021-07-30 13:29, Stéphane Rivière wrote:
>> For scripting an Ada application one needs support of
> 
> I don't see anything that HAC couldn't do, natively or with adaptations,
> both on the side of HAC and GNATStudio, considering the enormous amount
> of time that has been spent to integrate Python into GNATStudio.

It would help to provide a minimal example:
--------------------------------------------
with Ada.Text_IO;  use Ada.Text_IO;
procedure Scripwriter is
    function Square (X : Float) return Float is
    begin
       return X*X;
    end Square;
    Argument : constant Float := 2.0;
    Result   : Float;
begin
    Load_HAC_Module (...); -- Load custom module making Square callable
    Result := Call_HAC (..., Argument); -- Call script with Argument
    Put_Line
    (  "Square of" & Float'Image (Argument) &
       " =" & Float'Image (Result)
    );
end Scripwriter ;
--------------------------------------------
The script would be sort of:
--------------------------------------------
with Custom_Module;
procedure Whatever (X : Float) is
begin
    return Custom_Module.Square (X);
end Whatever;
--------------------------------------------
The HAC script must take Argument, call Square (accessible via the 
module), return the result of Square (Argument).

> But, imho, this is all history, GNATStudio is scriptable in Python,
> GNATStudio is very difficult to build, Adacore is known to love Python
> and GNAT CE, as a whole, is a wonderful tool. We have to live with it ;)

For AdaCore it is not really much work, they only have to provide a 
module to interface GPS engine. Their customers would decide witch 
script they would use.

What AdaCore *must* do is to remove static linking to Python. The GPS 
user should choose the script language per preferences that would look 
for the corresponding script run-time e.g. Python or HAC or whatever.

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

^ permalink raw reply	[relevance 1%]

* Re: XMLAda & unicode symbols
  2021-06-21 18:33  1%       ` Emmanuel Briot
@ 2021-06-21 20:06  0%         ` 196...@googlemail.com
  0 siblings, 0 replies; 200+ results
From: 196...@googlemail.com @ 2021-06-21 20:06 UTC (permalink / raw)


On Monday, 21 June 2021 at 19:33:58 UTC+1, briot.e...@gmail.com wrote:
> > A scan through XML/Ada shows that the only uses of Unicode_Char are in 
> > the SAX subset. I don't see any way in the DOM subset of XML/Ada of 
> > using them - someone please prove me wrong!
> Those two subsets are not independent, in fact the DOM subset is entirely based on the SAX one. 
> So anything that applies to SAX also applies to DOM. 
> 
> That said, the DOM standard (at the time I built XML/Ada, which is 20 years ago whereabouts) likely 
> did not have standard functions that receives unicode characters, only strings. 
> DOM implementations are free to use any internal representation they want, and I think they did not 
> have to accept any random encoding. XML/Ada is not user-friendly, it really is only a fairly low-level 
> implementation of the DOM standard. Using DOM without high-level things like XPath is a real 
> pain. At the time, someone else had done an XPath implementation, so I never took the time to 
> duplicate that effort. 
> 
> Conversion between various encodings (8bit, unicode utf-8, utf-16 or utf-32) is done via the 
> `unicode` module of XML/Ada, namely for instance `unicode-ces-utf8.ads`. They all provide a similar API. In this case 
> you want the `Encode` procedure. This is not a function (so doesn't return a Byte_Sequence directly) for efficiency 
> reason, even if it would be convenient for end-users, admittedly. 
> 
> As someone rightly mentioned, it doesn't really make sense to use XML/Ada to build a tree in memory just for the 
> sake of printing it, though. Ada.Text_IO or streams will be much much more efficient. XML/Ada is only useful 
> to parse XML streams (in which case you never have to yourself encode a character to a byte sequence in 
> general).
> > > we need to convert it, then let us do so outside of it. 
> > That is *exactly* what you have to do (convert outside, not throw any 
> > old sequence of octets and 32-bit values somehow mashed together at 
> > it
> Well said Simon, thanks. Basically, the whole application should be utf-8 if you at all care about international 
> characters (if you don't, feel free to use latin-1, or any encoding your terminal supports). So conversion should not 
> occur just at the interface to XML/Ada, but only on input and output of your program. 
> XML/Ada just assumes a string is a sequence of bytes. The actual encoding has to be known by the application, 
> and be consistent. 
> If for some reason (Windows ?) you prefer utf-16 internally, you can change `sax-encodings.ads` and recompile. 
> (would have been neater to use generic traits packages, but I did not realize about them until a few years later). 
> 
> It would also have been nicer to use a string type that knows about the encoding. I wrote GNATCOLL.Strings for 
> that purpose several years alter too. XML/Ada was never used extensively, so it was never a priority for AdaCore 
> to update it to use all these packages, at the risk of either breaking backward compatibility, or duplicating the 
> whole API to allow for the various string types. Not worth it. 
> 
> Emmanuel

Okay, now I think I am getting somewhere. A push and a prod is always welcome.

^ permalink raw reply	[relevance 0%]

* Re: XMLAda & unicode symbols
  @ 2021-06-21 18:33  1%       ` Emmanuel Briot
  2021-06-21 20:06  0%         ` 196...@googlemail.com
  0 siblings, 1 reply; 200+ results
From: Emmanuel Briot @ 2021-06-21 18:33 UTC (permalink / raw)


> A scan through XML/Ada shows that the only uses of Unicode_Char are in 
> the SAX subset. I don't see any way in the DOM subset of XML/Ada of 
> using them - someone please prove me wrong! 

Those two subsets are not independent, in fact the DOM subset is entirely based on the SAX one.
So anything that applies to SAX also applies to DOM.

That said, the DOM standard (at the time I built XML/Ada, which is 20 years ago whereabouts) likely
did not have standard functions that receives unicode characters, only strings.
DOM implementations are free to use any internal representation they want, and I think they did not
have to accept any random encoding. XML/Ada is not user-friendly, it really is only a fairly low-level
implementation of the DOM standard. Using DOM without high-level things like XPath is a real
pain. At the time, someone else had done an XPath implementation, so I never took the time to
duplicate that effort.

Conversion between various encodings (8bit, unicode utf-8, utf-16 or utf-32) is done via the
`unicode` module of XML/Ada, namely for instance `unicode-ces-utf8.ads`. They all provide a similar API. In this case
you want the `Encode` procedure. This is not a function (so doesn't return a Byte_Sequence directly) for efficiency
reason, even if it would be convenient for end-users, admittedly.

As someone rightly mentioned, it doesn't really make sense to use XML/Ada to build a tree in memory just for the
sake of printing it, though. Ada.Text_IO or streams will be much much more efficient. XML/Ada is only useful
to parse XML streams (in which case you never have to yourself encode a character to a byte sequence in
general).

> > we need to convert it, then let us do so outside of it.
> That is *exactly* what you have to do (convert outside, not throw any 
> old sequence of octets and 32-bit values somehow mashed together at 
> it

Well said Simon, thanks. Basically, the whole application should be utf-8 if you at all care about international
characters (if you don't, feel free to use latin-1, or any encoding your terminal supports). So conversion should not
occur just at the interface to XML/Ada, but only on input and output of your program.
XML/Ada just assumes a string is a sequence of bytes. The actual encoding has to be known by the application,
and be consistent.
If for some reason (Windows ?) you prefer utf-16 internally, you can change `sax-encodings.ads` and recompile.
(would have been neater to use generic traits packages, but I did not realize about them until a few years later).

It would also have been nicer to use a string type that knows about the encoding. I wrote GNATCOLL.Strings for
that purpose several years alter too. XML/Ada was never used extensively, so it was never a priority for AdaCore
to update it to use all these packages, at the risk of either breaking backward compatibility, or duplicating the
whole API to allow for the various string types. Not worth it.

Emmanuel

^ permalink raw reply	[relevance 1%]

* Re: XMLAda & unicode symbols
  2021-06-19 21:24  1% ` Simon Wright
@ 2021-06-20 17:10  0%   ` 196...@googlemail.com
    0 siblings, 1 reply; 200+ results
From: 196...@googlemail.com @ 2021-06-20 17:10 UTC (permalink / raw)


On Saturday, 19 June 2021 at 22:24:47 UTC+1, Simon Wright wrote:
> "196...@googlemail.com" <196...@googlemail.com> writes: 
> 
> > I'm creating SVG files with XMLAda and I need to have a degree symbol 
> > within some text. 
> > 
> > I have: 
> > procedure Add_Min_Max (Min_Max_Str : String; X_Pos : String; Y_Pos : String) is 
> > Text_Node : DOM.Core.Element; 
> > Text : DOM.Core.Text; 
> > begin 
> > Text_Node := DOM.Core.Documents.Create_Element (LDocument, "text"); 
> > DOM.Core.Elements.Set_Attribute (Text_Node, "x", X_Pos); 
> > DOM.Core.Elements.Set_Attribute (Text_Node, "y", Y_Pos); 
> > DOM.Core.Elements.Set_Attribute (Text_Node, "class", "def-maroon"); 
> > DOM.Core.Elements.Set_Attribute (Text_Node, "text-anchor", "left"); 
> > Text_Node := DOM.Core.Nodes.Append_Child (Root_Node, Text_Node); 
> > Text := DOM.Core.Documents.Create_Text_Node (LDocument, Min_Max_Str); 
> > Text := DOM.Core.Nodes.Append_Child (Text_Node, Text); 
> > end Add_Min_Max; 
> > 
> > and I just pass a string in. The degree symbol is unicode 00B0 and you 
> > would then normally have it as &#00B0, except if I do, then XMLAda 
> > changes that initial '&' to '&amp' and so what is then coded is 
> > '&amp#00B0' and it fails to display properly. 
> > 
> > Nor can I apply Unicode.Names.Latin_1_Supplement.Degree_Sign to the 
> > string, since, well, strict typing... 
> > 
> > To me it seems like XMLAda is being far too eager and is not willing 
> > to just publish what I enter. 
> > 
> > I raised a call on the github repository, but it was closed saying 
> > basically use the unicode name, which fails.
> Set_Attribute takes a Dom_String, which is a subtype of 
> Unicode.CES.Byte_Sequence, which is a subtype of String. The question 
> is, what encoding? I suspect it's utf-8, so we need to encode 
> Ada.Characters.Latin_1.Degree_Sign in utf-8, & this code using XML/Ada 
> support seems to do the trick: 
> 
> with Ada.Characters.Latin_1; 
> with Ada.Text_IO; 
> with Unicode.CES; 
> with Unicode.Encodings; 
> procedure Conversion is 
> Fifty_Degrees_Latin1 : constant String 
> := "50" & Ada.Characters.Latin_1.Degree_Sign; 
> Fifty_Degrees_UTF8 : constant Unicode.CES.Byte_Sequence 
> := "50" 
> & Unicode.Encodings.Convert 
> ((1 => Ada.Characters.Latin_1.Degree_Sign), 
> From => Unicode.Encodings.Get_By_Name ("iso-8859-15"), 
> To => Unicode.Encodings.Get_By_Name ("utf-8")); 
> begin 
> Ada.Text_IO.Put_Line (Fifty_Degrees_Latin1); 
> Ada.Text_IO.Put_Line (Fifty_Degrees_UTF8); 
> end Conversion; 
> 
> (note that Convert's From and To parameters are the default). On this 
> Mac (Terminal displays utf-8 text) the first line is garbage, the second 
> fine. 
> 
> I'm So Wildly Impressed (maybe "cast down" would be more accurate) by 
> all that subtyping in our wondrously safe language. 
> 
> I also agree with you that suggesting you use a Unicode_Char 
> (Wide_Wide_Character) without saying *how* is less helpful than it could 
> be.

Asking for the degree sign, was probably a slight mistake. There is Degree_Celsius and also Degree_Fahrenheit for those who have not yet embraced metric. These are the "correct" symbols.

Both of these exist in Unicode.Names.Letterlike_Symbols, and probably elsewhere,but trying to shoehorn these in seems impossible.

I just wish XMLAda could just accept whatever we throw at it, and if we need to convert it, then let us do so outside of it.

Using Text_IO is fine, but not where XMLAda is concerned.


B

^ permalink raw reply	[relevance 0%]

* Re: XMLAda & unicode symbols
  @ 2021-06-19 21:24  1% ` Simon Wright
  2021-06-20 17:10  0%   ` 196...@googlemail.com
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2021-06-19 21:24 UTC (permalink / raw)


"196...@googlemail.com" <1963bib@googlemail.com> writes:

> I'm creating SVG files with XMLAda and I need to have a degree symbol
> within some text.
>
> I have:
> procedure Add_Min_Max (Min_Max_Str : String; X_Pos : String; Y_Pos : String) is
>       Text_Node : DOM.Core.Element;
>       Text      : DOM.Core.Text;
>    begin
>       Text_Node := DOM.Core.Documents.Create_Element (LDocument, "text");
>       DOM.Core.Elements.Set_Attribute (Text_Node, "x", X_Pos);
>       DOM.Core.Elements.Set_Attribute (Text_Node, "y", Y_Pos);
>       DOM.Core.Elements.Set_Attribute (Text_Node, "class", "def-maroon");
>       DOM.Core.Elements.Set_Attribute (Text_Node, "text-anchor", "left");
>       Text_Node := DOM.Core.Nodes.Append_Child (Root_Node, Text_Node);
>       Text := DOM.Core.Documents.Create_Text_Node (LDocument, Min_Max_Str);
>       Text := DOM.Core.Nodes.Append_Child (Text_Node, Text);
>    end Add_Min_Max;
>
> and I just pass a string in. The degree symbol is unicode 00B0 and you
> would then normally have it as &#00B0, except if I do, then XMLAda
> changes that initial '&' to '&amp' and so what is then coded is
> '&amp#00B0' and it fails to display properly.
>
> Nor can I apply Unicode.Names.Latin_1_Supplement.Degree_Sign to the
> string, since, well, strict typing...
>
> To me it seems like XMLAda is being far too eager and is not willing
> to just publish what I enter.
>
> I raised a call on the github repository, but it was closed saying
> basically use the unicode name, which fails.

Set_Attribute takes a Dom_String, which is a subtype of
Unicode.CES.Byte_Sequence, which is a subtype of String. The question
is, what encoding? I suspect it's utf-8, so we need to encode
Ada.Characters.Latin_1.Degree_Sign in utf-8, & this code using XML/Ada
support seems to do the trick:

   with Ada.Characters.Latin_1;
   with Ada.Text_IO;
   with Unicode.CES;
   with Unicode.Encodings;
   procedure Conversion is
      Fifty_Degrees_Latin1 : constant String
        := "50" & Ada.Characters.Latin_1.Degree_Sign;
      Fifty_Degrees_UTF8 : constant Unicode.CES.Byte_Sequence
        := "50"
          & Unicode.Encodings.Convert
            ((1 => Ada.Characters.Latin_1.Degree_Sign),
             From => Unicode.Encodings.Get_By_Name ("iso-8859-15"),
             To => Unicode.Encodings.Get_By_Name ("utf-8"));
   begin
      Ada.Text_IO.Put_Line (Fifty_Degrees_Latin1);
      Ada.Text_IO.Put_Line (Fifty_Degrees_UTF8);
   end Conversion;

(note that Convert's From and To parameters are the default). On this
Mac (Terminal displays utf-8 text) the first line is garbage, the second
fine.

I'm So Wildly Impressed (maybe "cast down" would be more accurate) by
all that subtyping in our wondrously safe language.

I also agree with you that suggesting you use a Unicode_Char
(Wide_Wide_Character) without saying *how* is less helpful than it could
be.

^ permalink raw reply	[relevance 1%]

* non-preemptive tasking on GNAT 2020 Windows 10 multicore AMD
@ 2021-06-12 12:51  1% Dan Winslow
  0 siblings, 0 replies; 200+ results
From: Dan Winslow @ 2021-06-12 12:51 UTC (permalink / raw)


I am trying to achieve true non-preemptive tasking using gnat 2020 CE on a windows 10 environment. I have placed this in the gnat.adc file:

pragma Task_Dispatching_Policy(Non_Preemptive_FIFO_Within_Priorities);

Without this gnat.adc setting, the tasks switched back and forth a great deal, as you would expect with preemptive tasking. Putting the pragma in the gnat.adc file seemed to affect the granularity of the task switching on my test program below, in that it lengthened the time that each task executed consecutive loops, but they still switched over to each other eventually. Here is the test program:


with Ada.Text_IO; Use Ada.Text_Io;
 
procedure Test is


   Task Type One is
   End;  

   Task Type Two;

   Task body One is
     x : Integer := 0;
   Begin
     put_line("one");
     Loop
       x:=x+1;
       if x > 10000000 Then
         exit;
       end if;  
     End Loop;
     Put_line("Task one done, x=" & x'img);
   End;

   Task body Two is
     x : Integer := 0;
   Begin
     put_line("two");
     Loop
       x:=x+1;
       if x > 1000 Then
         exit;
       end if;  
     End Loop;
     Put_line("Task two done, x=" & x'img);
   End;

  a : One;
  B : two;
begin
   
  Null;
End;

Here is the compile line:

gnatmake -gnat2012 -gnatX -f -g test.adb -gnatwA -I. -I..  -D obj


And here is the output:

one
two
Task two done, x= 1001
Task one done, x= 10000001


I expected the opposite, that task one would execute first, which it did, but that it would also finish first because there's no reason for it to yield to two without preemption. It looks to me like I am not actually getting non-preemptive tasking, and I would like to know why.

After some looking I found the 2012 attribute 'with CPU', and produced test code :

With System.Multiprocessors;     use System.Multiprocessors;

with Ada.Text_IO; Use Ada.Text_Io;
 
procedure Test is

   Task Type One with Cpu=>1 is
   End;  

   Task Type Two with Cpu=> 1 is
   end;
   
   x,y : integer := 0;
   limit : integer := 1000000;

   Task body One is
   Begin
     put_line("one");
     Loop
       if y > 0 then 
         raise tasking_error;
       end if;  
       x:=x+1;
       if x > limit Then
         exit;
       end if;  
     End Loop;
     Put_line("Task one done, x=" & x'img);
   Exception
     When others =>
     put_line("task one died, x=" & x'img);  
   End;

   Task body Two is
   Begin
     put_line("two");
     Loop
       y:=y+1;
       if y > limit Then
         exit;
       end if;  
     End Loop;
     Put_line("Task two done, y=" & y'img);
   Exception
     When others =>
     put_line("task two died");  
   End;

  a : One;
  B : two;
begin
  put_line(Number_Of_CPUs'img & " cpu's"); 
  While (x < limit+1) or (y < limit+1) loop
    Delay 0.0;
  End Loop;  
  put_line("main done, x " & x'img & " y " & y'img);
End;


which produces output


one
two
 24 cpu's
task one died, x= 310528
Task two done, y= 1000001
^C

(of course, I have to ctl-c out since main never finishes.)

This happens whether or not I have the scheduling pragma in gnat.adc. Does Windows just not respect processor assignment and/or the scheduling pragma?

(Sorry for no code blocks, not sure how to do that here)

^ permalink raw reply	[relevance 1%]

* Re: Is it possible to redirect text output to a String or Unbounded_String?
  2021-06-10  7:00  1% ` Dmitry A. Kazakov
@ 2021-06-11 13:07  1%   ` Stephane Carrez
  0 siblings, 0 replies; 200+ results
From: Stephane Carrez @ 2021-06-11 13:07 UTC (permalink / raw)


Hi!

Le jeudi 10 juin 2021 à 09:00:31 UTC+2, Dmitry A. Kazakov a écrit :
> On 2021-06-10 04:17, Jerry wrote: 
> > Is it possible to redirect text output to a String or Unbounded_String rather than to a file?
> From Ada.Text_IO? No you cannot, File_Type is not tagged. For a stream 
> you could.

Tero Koskinen has made an interesting implementation in Ahven for that.

Basically he redirects the standard output to a file for the execution of the unit test method.
The unit test method executes and can use the Ada.Text_IO without change.
After the unit test completion, it reads the file.

If I'm not wrong, have a look at the Ahven.Temporary_Output package:

https://hg.sr.ht/~tkoskine/ahven/browse/src/ahven-temporary_output.ads?rev=tip
https://hg.sr.ht/~tkoskine/ahven/browse/src/ahven-temporary_output.adb?rev=tip

Best regards,

Stephane

^ permalink raw reply	[relevance 1%]

* Re: Is it possible to redirect text output to a String or Unbounded_String?
                     ` (2 preceding siblings ...)
  2021-06-10  8:31  1% ` ytomino
@ 2021-06-10 21:12  1% ` Shark8
  3 siblings, 0 replies; 200+ results
From: Shark8 @ 2021-06-10 21:12 UTC (permalink / raw)


On Wednesday, June 9, 2021 at 8:17:20 PM UTC-6, Jerry wrote:
> Is it possible to redirect text output to a String or Unbounded_String rather than to a file? 
> 
> I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal. 
> 
> I suppose I could redirect text to a file and then somehow read it back in as one string but that seems like a kludge. 
> 
> Jerry
Well...
------------------------------------
    Generic
        Type FILE_TYPE(<>) is limited private;
        Type FILE_MODE     is (<>);
        Type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
        with Procedure Indirect_Put_Line(Item : String);
        -- put all the subprograms you need here; prefix with Indirect_
        Object : in out FILE_TYPE;
        Stream : in Stream_Access;
    Package Duplicating_IO is
        -- Declare all the subprograms used above w/o Indirect_
        Procedure Put_Line(Item : String);
    End Duplicating_IO;
------------------------------------
    Package Body Duplicating_IO is
        -- Implementations; if there's a lot consider generics+renames.
        Procedure Put_Line(Item : String) is
        Begin
            String'Output( Stream, Item );
            Indirect_Put_Line( Item );
        End Put_Line;
    End Duplicating_IO;
------------------------------------    
    OBJ : Ada.Text_IO.File_Type:= Ada.Text_IO.Standard_Output;
    STR : Ada.Text_IO.Text_Streams.Stream_Access renames
      Ada.Text_IO.Text_Streams.Stream( OBJ );
------------------------------------
    Package Split_IO is new Duplicating_IO
      (
       File_Type         => File_Type,
       File_Mode         => File_Mode,
       Stream_Access     => Ada.Text_IO.Text_Streams.Stream_Access,
       Indirect_Put_Line => Put_Line,
        Object           => OBJ,
        Stream           => STR
      );

^ permalink raw reply	[relevance 1%]

* Re: Is it possible to redirect text output to a String or Unbounded_String?
    2021-06-10  6:50  1% ` Simon Wright
  2021-06-10  7:00  1% ` Dmitry A. Kazakov
@ 2021-06-10  8:31  1% ` ytomino
  2021-06-10 21:12  1% ` Shark8
  3 siblings, 0 replies; 200+ results
From: ytomino @ 2021-06-10  8:31 UTC (permalink / raw)


On Thursday, June 10, 2021 at 11:17:20 AM UTC+9, Jerry wrote:
> Is it possible to redirect text output to a String or Unbounded_String rather than to a file? 
> 
> I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal. 
> 
> I suppose I could redirect text to a file and then somehow read it back in as one string but that seems like a kludge. 
> 
> Jerry

If you are not particular about use of String or Unbounded_String, how about open_memstream(3) of libc?
Import and call open_memstream to create a C-style on-memory file at first, then you can create an Ada-style File_Type from it with Ada.Text_IO.C_Streams.Open.

^ permalink raw reply	[relevance 1%]

* Re: Is it possible to redirect text output to a String or Unbounded_String?
    2021-06-10  6:50  1% ` Simon Wright
@ 2021-06-10  7:00  1% ` Dmitry A. Kazakov
  2021-06-11 13:07  1%   ` Stephane Carrez
  2021-06-10  8:31  1% ` ytomino
  2021-06-10 21:12  1% ` Shark8
  3 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2021-06-10  7:00 UTC (permalink / raw)


On 2021-06-10 04:17, Jerry wrote:
> Is it possible to redirect text output to a String or Unbounded_String rather than to a file?

 From Ada.Text_IO? No you cannot, File_Type is not tagged. For a stream 
you could.

> I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal.

I would say that one should never use anything but Put_Line and never 
instantiate any I/O packages. First format an output line in a string, 
and then output the string.

I would suggest to define logging/tracing package, instead of doing 
direct output. It always pays off.

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

^ permalink raw reply	[relevance 1%]

* Re: Is it possible to redirect text output to a String or Unbounded_String?
  @ 2021-06-10  6:50  1% ` Simon Wright
  2021-06-10  7:00  1% ` Dmitry A. Kazakov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 200+ results
From: Simon Wright @ 2021-06-10  6:50 UTC (permalink / raw)


Jerry <list_email@icloud.com> writes:

> Is it possible to redirect text output to a String or Unbounded_String
> rather than to a file?

I think you could use Ada.Text_IO.Text_Streams, except it's the wrong
way round (treat a file as a stream). If you could treat a stream as a
file you could use Text_IO to write to the file view and suck the stream
view out into whatever format you wanted. Maybe.

^ permalink raw reply	[relevance 1%]

* Re: Better way to fill Storage_IO?
  2021-05-18 20:39  0%     ` Simon Wright
@ 2021-05-19  6:24  0%       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-05-19  6:24 UTC (permalink / raw)


On 2021-05-18 22:39, Simon Wright wrote:
> Michael Hardeman <mhardeman25@gmail.com> writes:
> 
>> I was kind of hoping there would be an interface like
>> Ada.Text_IO.Text_Streams, where you could just directly stream from
>> the variable's address or access without having to write the variable
>> into the stream first. I'm not sure, but the writing part seems a bit
>> like an extra step.
> [...]
>> I was kind of trying to show you could move through the stream like a
>> parser instead of just consuming the whole thing. i.e. like if you
>> wanted to parse the hex into an array of Unsigned_32 or Unsigned_64
>> for some algorithm.
> 
> I don't understand the scenario.
> 
>    Source   >>   Stream   >>   Destination
> 
> If Source and Destination are in the same process, there's no need to
> involve streams at all.

The picture actually is:

    Producer -> Output stream = Input Stream -> Consumer

The producer could be a code generator, the consumer could be a parser.

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

^ permalink raw reply	[relevance 0%]

* Re: Better way to fill Storage_IO?
  2021-05-17 19:23  1%   ` Michael Hardeman
@ 2021-05-18 20:39  0%     ` Simon Wright
  2021-05-19  6:24  0%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2021-05-18 20:39 UTC (permalink / raw)


Michael Hardeman <mhardeman25@gmail.com> writes:

> I was kind of hoping there would be an interface like
> Ada.Text_IO.Text_Streams, where you could just directly stream from
> the variable's address or access without having to write the variable
> into the stream first. I'm not sure, but the writing part seems a bit
> like an extra step.
[...]
> I was kind of trying to show you could move through the stream like a
> parser instead of just consuming the whole thing. i.e. like if you
> wanted to parse the hex into an array of Unsigned_32 or Unsigned_64
> for some algorithm.

I don't understand the scenario.

  Source   >>   Stream   >>   Destination

If Source and Destination are in the same process, there's no need to
involve streams at all.

If Source and Destination are separated - different processes on the
same computer, different computers (possibly with different endianness),
different times - we have to agree on a protocol as to what's sent over
the stream. For a String Z, perhaps the first 4 bytes are the
little-endian Z'First, the next are Z'Last, then the actual bytes of Z.

That's what streams are for (and that's what String'Output does).

Once you have the stream, you can go through it in any way you need to;
you must know what to expect so as to make sense of it. In your example,
you have to know that the bytes in the stream are hex characters.

==========

As to creating the stream: I suppose there could be something like
'Image, where the attribute could originally only be applied to a type:
you used to have to say

   Integer'Image (An_Integer)

whereas now you can say just

   An_Integer'Image

so as well as the current ARM 13.13.2(4), for subtype S of type T

   procedure S'Write(
      Stream : not null access Ada.Streams.Root_Stream_Type'Class;
      Item : in T)

one could have for an object O

   procedure O'Write(
      Stream : not null access Ada.Streams.Root_Stream_Type'Class)

but we don't, not even in Ada 202x.

^ permalink raw reply	[relevance 0%]

* Re: Better way to fill Storage_IO?
  2021-05-17 19:14  1% ` Simon Wright
@ 2021-05-17 19:23  1%   ` Michael Hardeman
  2021-05-18 20:39  0%     ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Michael Hardeman @ 2021-05-17 19:23 UTC (permalink / raw)


On Monday, May 17, 2021 at 3:14:43 PM UTC-4, Simon Wright wrote:
> 
> 'Output writes the discriminants of the object, if any, then the object; 
> 'Input uses them to reconstruct the object, so in this case that means 
> the bounds, and hence the length.
> > I was wondering if we could find a better way to fill the stream other 
> > than writing the variables into it? Can anyone figure out a good way 
> > to just stream a variable's bytes directly?
> This *is* the way to just stream the variable's bytes directly. What 
> sort of syntax were you hoping for?

I was kind of hoping there would be an interface like Ada.Text_IO.Text_Streams, where you could just directly stream from the variable's address or access without having to write the variable into the stream first. I'm not sure, but the writing part seems a bit like an extra step.

This would be my version: 
> 
> with Ada.Text_IO; use Ada.Text_IO; 
> with Ada.Streams.Storage.Unbounded; 
> 
> procedure Test is 
> Test : constant String := "040b2cec765b4bbbdb29d83b6dcaf776"; 
> Test_Stream : aliased Ada.Streams.Storage.Unbounded.Stream_Type; 
> begin 
> String'Output (Test_Stream'Access, Test); 
> declare 
> S : constant String := String'Input (Test_Stream'Access); 
> begin 
> Put_Line (S); 
> end; 
> end Test; 

I was kind of trying to show you could move through the stream like a parser instead of just consuming the whole thing. i.e. like if you wanted to parse the hex into an array of Unsigned_32 or Unsigned_64 for some algorithm.

^ permalink raw reply	[relevance 1%]

* Re: Better way to fill Storage_IO?
  2021-05-17 18:44  1% Better way to fill Storage_IO? Michael Hardeman
@ 2021-05-17 19:14  1% ` Simon Wright
  2021-05-17 19:23  1%   ` Michael Hardeman
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2021-05-17 19:14 UTC (permalink / raw)


Michael Hardeman <mhardeman25@gmail.com> writes:

> So I've been messing around with the new Ada 2020 package
> Ada.Streams.Storage.Bounded/Unbounded; and if I'm understand it
> correctly it allows you to treat your program's memory like a stream
> without having to open file descriptors (which should make it
> faster?). That seems like a powerful abstraction to me and a great
> addition to the language.

This would be my version:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Streams.Storage.Unbounded;

procedure Test is
  Test : constant String := "040b2cec765b4bbbdb29d83b6dcaf776";
  Test_Stream : aliased Ada.Streams.Storage.Unbounded.Stream_Type;
begin
   String'Output (Test_Stream'Access, Test);
   declare
      S : constant String := String'Input (Test_Stream'Access);
   begin
      Put_Line (S);
   end;
end Test;

'Output writes the discriminants of the object, if any, then the object;
'Input uses them to reconstruct the object, so in this case that means
the bounds, and hence the length.

> I was wondering if we could find a better way to fill the stream other
> than writing the variables into it? Can anyone figure out a good way
> to just stream a variable's bytes directly?

This *is* the way to just stream the variable's bytes directly. What
sort of syntax were you hoping for?

^ permalink raw reply	[relevance 1%]

* Better way to fill Storage_IO?
@ 2021-05-17 18:44  1% Michael Hardeman
  2021-05-17 19:14  1% ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Michael Hardeman @ 2021-05-17 18:44 UTC (permalink / raw)


So I've been messing around with the new Ada 2020 package Ada.Streams.Storage.Bounded/Unbounded; and if I'm understand it correctly it allows you to treat your program's memory like a stream without having to open file descriptors (which should make it faster?). That seems like a powerful abstraction to me and a great addition to the language.

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Streams; use Ada.Streams;
with Ada.Streams.Storage.Unbounded; use Ada.Streams.Storage.Unbounded;

procedure Test is
  Test : String := "040b2cec765b4bbbdb29d83b6dcaf776";
  Test_Stream : aliased Stream_Type;
begin
  String'Write(Test_Stream'Access, Test);
  for I in 1 .. Element_Count (Test_Stream) loop
    declare
      C : Character;
    begin
      Character'Read (Test_Stream'Access, C);
      Put (C);
    end;
  end loop;
end Test;

I was wondering if we could find a better way to fill the stream other than writing the variables into it? Can anyone figure out a good way to just stream a variable's bytes directly?

^ permalink raw reply	[relevance 1%]

* Re: [Ada95] Private non-generic children of generics not allowed
  2021-04-29 11:02  1%     ` Egil H H
@ 2021-04-29 17:17  0%       ` Vincent Marciante
  0 siblings, 0 replies; 200+ results
From: Vincent Marciante @ 2021-04-29 17:17 UTC (permalink / raw)


On Thursday, April 29, 2021 at 7:02:02 AM UTC-4, ehh.p...@gmail.com wrote:
> On Thursday, April 29, 2021 at 12:20:07 PM UTC+2, Vincent Marciante wrote: 
> > 
> > (My specific need is in trying to keep down code duplication in a few different implementations 
> > of a generic package: separate body parts/files for each different implementation appear in different 
> > subdirectories and the build system picks the correct ones depending on the variant being built.
> So what you want is a separate package/procedure/function: 
> 
> generic 
> package Generic_Foo is 
> procedure Bar; 
> end Generic_Foo; 
> 
> -- 
> 
> package body Generic_Foo is 
> Name : String := "generic Foo"; 
> 
> package Baz is 
> procedure Qux; 
> end Baz; 
> 
> package body Baz is separate; -magic! 
> 
> procedure Bar is 
> begin 
> Baz.Qux; 
> end Bar; 
> end Generic_Foo; 
> 
> -- 
> 
> with Ada.Text_IO; 
> separate(Generic_Foo) 
> package body Baz is 
> procedure Qux is 
> begin 
> Ada.Text_IO.Put_Line("Separate body of " & Name); 
> end Qux; 
> end Baz; 
> 
> 
> (Sorry in advance for google messing up indentation/formatting)

That is pretty much what I have to do except that in my situation 
your procedure Bar would also be separate - and that makes the big
difference: If private non-generic units were allowed (and visible 
only from the body of the parent generic) then the spec of your Baz 
package would not have to be declared in the body of Generic_Foo;
it would be with'd only by the body of Bar (and any other separate 
that require it - without any additional declaration order requirements 
in the body of Generic_Foo. 

The situation would be worse if procedure Quz needed to have a 
parameter whose type was not from a package that was already visible 
to Genereic_Foo, forcing that package to be with'd in the body of 
Generic_Foo. _And_ if the required package would then cause a chain 
of dependencies to occur that are not even satisfiable in the variant 
environments that do not really require it then that package wouold 
also have to be dummied with null or exception-propagating subprograms.

All of that could be avoided in a simple way if use of a private child 
unit as I have describe was made legal.

^ permalink raw reply	[relevance 0%]

* Re: [Ada95] Private non-generic children of generics not allowed
  @ 2021-04-29 11:02  1%     ` Egil H H
  2021-04-29 17:17  0%       ` Vincent Marciante
  0 siblings, 1 reply; 200+ results
From: Egil H H @ 2021-04-29 11:02 UTC (permalink / raw)


On Thursday, April 29, 2021 at 12:20:07 PM UTC+2, Vincent Marciante wrote:
> 
> (My specific need is in trying to keep down code duplication in a few different implementations 
> of a generic package: separate body parts/files for each different implementation appear in different 
> subdirectories and the build system picks the correct ones depending on the variant being built. 

So what you want is a separate package/procedure/function:

generic 
package Generic_Foo is
   procedure Bar;
end Generic_Foo;

--

package body Generic_Foo is
   Name : String := "generic Foo";

   package Baz is
      procedure Qux;
   end Baz;
   
   package body Baz is separate;  -magic!

   procedure Bar is
   begin
      Baz.Qux;
   end Bar;
end Generic_Foo;

--

with Ada.Text_IO;
separate(Generic_Foo)
package body Baz is
   procedure Qux is
   begin
      Ada.Text_IO.Put_Line("Separate body of " & Name);
   end Qux; 
end Baz;


(Sorry in advance for google messing up indentation/formatting)


^ permalink raw reply	[relevance 1%]

* Re: Constraint error overflow
  @ 2021-04-27 16:31  1%     ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2021-04-27 16:31 UTC (permalink / raw)


Richard Iswara <haujekchifan@gmail.com> writes:

> So the compiler is restricted to 32 bit integer value. I had hoped for
> 64 bit to get 18 digits.

GNAT comes with Long_Integer (64 bits).

Or yu could go with the Ada202x Big_Integers package
(http://www.ada-auth.org/standards/2xrm/html/RM-A-5-6.html),

pragma Ada_2020;

with Ada.Text_IO;
with Ada.Numerics.Big_Numbers.Big_Integers;

procedure Iswara is

   use Ada.Numerics.Big_Numbers.Big_Integers;

   Sum : Big_Natural := 0;
   Mul : Big_Natural := 1;

begin
   Ada.Text_IO.Put ( "Sum of the first 100 integers is :" );
   Ada.Text_IO.New_Line;
   Summing:
   for I in 1 .. 100 loop
      Sum := Sum + To_Big_Integer (I);
   end loop Summing;
   Ada.Text_IO.Put ( Sum'Image );
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put ( "Multiple of the first 100 integers is :" );
   Ada.Text_IO.New_Line;
   Multiplying:
   for J in 1 .. 100 loop
      Mul := Mul * To_Big_Integer (J);
   end loop Multiplying;
   Ada.Text_IO.Put ( Mul'Image );
   Ada.Text_IO.New_Line;
end Iswara;

which compiles fine with GNAT CE 2020 & FSF GCC 11.0.1; result

$ ./iswara 
Sum of the first 100 integers is :
 5050
Multiple of the first 100 integers is :
 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

^ permalink raw reply	[relevance 1%]

* Constraint error overflow
@ 2021-04-27 14:04  1% Richard Iswara
    0 siblings, 1 reply; 200+ results
From: Richard Iswara @ 2021-04-27 14:04 UTC (permalink / raw)


Ada beginner here. I was trying to multiply the first 100 integer and GNAT throw me a constraint error, overflow. I check the error was on integer 13. So what did I do wrong here?
Gnat CE 2020, Windows 10 Pro 64bit.
Here is the relevant program:

with Ada.Text_IO;
with Ada.Integer_Text_IO;

procedure Simple is
   sum : Natural := 0;
   mul : Natural := 1;

begin
   Ada.Text_IO.Put ( "Sum of first 100 integer is :" );
   Summing:
   for I in 1 .. 100 loop
      sum := sum + I;
   end loop Summing;
   Ada.Integer_Text_IO.Put ( sum );
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put ( "Multiple of the first 100 integer is :" );
   Ada.Text_IO.New_Line;
   Multiplying:
   for J in 1 .. 100 loop
      Ada.Integer_Text_IO.Put (J);
      Ada.Text_IO.New_Line;
      mul := mul * J;
   end loop Multiplying;
   Ada.Integer_Text_IO.Put ( mul );
   Ada.Text_IO.New_Line;
end Simple;


^ permalink raw reply	[relevance 1%]

* Re: array from static predicate on enumerated type
  @ 2021-03-16 14:25  1%               ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-03-16 14:25 UTC (permalink / raw)


On 2021-03-16 14:27, Shark8 wrote:
> On Monday, March 15, 2021 at 2:25:11 PM UTC-6, Dmitry A. Kazakov wrote:
>> On 2021-03-15 18:48, Shark8 wrote:
>>
>>> So, in Ada, there's no good choice for how to actually DO an array with gaps in the index:
>> That applies to all containers. The problem is mapping the key to a
>> dense position when the key is not dense or might be unordered.
>>
>> There is no gaps in positions.
>>> But Array *isn't* a map, though often it is substituted as one.
>> Of course it is, per definition of mapping. f : key -> element.
> 
> I think you misunderstand, I said it has further constraints.
> That definition of map doesn't care how the order of 'key' is, Ada's array does.

No, that is apples and oranges. You compare unconstrained map with 
constrained array. The OP wanted to constrain LETTER to CURVED_LETTER 
with the corresponding effect on the container.

You cannot do that with either arrays or a predefined vector container. 
Ada does not have mechanism to do that on the level of a type.

You can do that on the level individual values. That is a dynamic 
constraint, e.g. checking the key or index before using it.

> That definition doesn't care if 'Key' is a discriminated-type, or constrained, or limited, Ada's array flat-out doesn't work without its 'key' (Index) being discrete, I don't know about limited as I haven't tried it.

Try this:

with Ada.Text_IO; use Ada.Text_IO;

procedure Test is
    type CURVED is ('B', 'C', 'D', 'G', 'J');
    A : array (CURVED) of Integer;
begin
    Put_Line (Integer'Image (A'Length));
end Test;

It will print:

  5

Again, the problem is not arrays. The problem is lack of 
substitutability of things built upon constrained keys of a map.

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

^ permalink raw reply	[relevance 1%]

* Re: Ada and "early return" - opinion/practice question
  @ 2021-03-15 18:12  1% ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2021-03-15 18:12 UTC (permalink / raw)


On Monday, March 15, 2021 at 10:46:39 AM UTC-6, wrote:
> I hope this isn't a FAQ (it's hard to find relevant articles) but can someone guide me on the 'normal' treatment in Ada style of what appears to be referred to (by C/C++ programmers) as early-return. 

Exceptions, typically.
Sometimes a return itself, typically in a procedure though.

> For example, you have a C++ function (pseudo code sort of thing): 
> 
> <sometype> fn(<some parameters>) 
> { 
> if (<some undesirable condition 1>) 
> { 
> return <something bad happened 1>; 
> } 
> 
> if (<some undesirable condition 2>) 
> { 
> return <something bad 2>; 
> } 
> 
> if (<some undesirable condition 3>) 
> { 
> return <something bad 3>; 
> } 
> 
> // Only get here if everything's good... 
> <do some real stuff> 
> return <something good>; 
> } 

This is the style for a system that I'm looking at currently, it's interfacing for DLL calls related to some special hardware. My initial method is going to write a thin binding, then "thicken" it up with subtypes and procedures/functions tailored to the system so something like:

Subtype DLL_Return is Interfaces.Unsigned_8; -- Or whatever

Type Temp_Subtype is (A_OK, Out_Of_Range )
  with Size => DLL_Return'Size;

For Temp_Subtype use
( A_OK                => 14,
  Out_Of_Range => 72
);

Function Check_Temp return Temp_Subtype is
  Return_Value : Constant DLL_Return := Do_Temperture_Check;
  Result : Temp_Subtype renames Convert( Return_Value ); -- Convert is instantiation of unchecked_conversion.
Begin
  if DEBUGGING then
    Ada.Text_IO.Put_Line( "Called Check_Temp, got: " & DLL_Return'Image(Return_Value) );
  end if;
  Return Result;
End;

Heck, since the translations are so regular I could probably use Generics to handle leveraging things, meaning the most work would be getting the actual type/values defined.

> I've probably mentioned this before, but it's a long time since I used Ada in anger and I don't remember seeing stuff like that when I did use Ada a lot; does anyone write stuff like that in Ada? 
> 
> When I first learnt to program properly it was using Pascal with, as I remember it, only one return from a function being allowed,
Your memory is correct... for Pascal.
Ada has always allowed multiple return statements in a subprogram, with a "return" in a procedure acting as a "jump to the end, do clean-up".

> so over the years I've mostly looked at positive conditions and indented stuff, pulling the stuff in the middle out into its own procedure or function where appropriate, but you see so many people defending this style in C/C++ that I wonder whether it really is defensible? 

No, it's not defensible... at least IMO.

^ permalink raw reply	[relevance 1%]

* algorithm, two implementations that act the same, same type etc
@ 2021-02-14 19:35  1% Mehdi Saada
  0 siblings, 0 replies; 200+ results
From: Mehdi Saada @ 2021-02-14 19:35 UTC (permalink / raw)


Hi,
I have an issue with an algorithm - self-imposed "homework" I guess, the first one is mine, the wrong, the second is the "right" one, that works.
I can't figure out why they would logically be any different.
basically instead of using a stack on access values, I stack the values themselves. the rest is the same.
except this function ALL the rest of the project is the same. they are in related package so from the first I call the second to ensure the result is right, and it shows its not.

could someone throw an eye and tell if it seems identical or that something gross escaped my sight ?


45+78*56-(5-(8+5)-7);
gives (really) :  4428 and mine gives  4413

11-0/5+88/5;
it should be: 28 and mine gives 11

my function:
   function  Calcul ( V : in T_Vect_Token) return Integer is
      package ppile is new P_Pile_4(T_Elem   => Integer,
                                    Max_Pile => 80);
      use ppile;
      Pile_operandes : ppile.T_Pile(40);
      op1_calcul, op2_calcul: Integer;
   begin
      for I in V'Range loop
         if V(I).all'Tag = T_Token_Operande'Tag then
            ppile.Empiler(Pile_operandes,T_Token_Operande(v(I).all).Get_Elem);
         elsif V(I).all'Tag = T_Token_Operateur'Tag then
            Depiler(Pile_operandes,op2_calcul);
            Depiler(Pile_operandes,op1_calcul);
            case T_Token_Operateur(v(I).all).L_Operateur is
               when '*' => Empiler(Pile_operandes,op1_calcul * op2_calcul);
               when '-' => Empiler(Pile_operandes,op1_calcul - op2_calcul);
               when '+' => Empiler(Pile_operandes,op1_calcul + op2_calcul);
               when '/' => Empiler(Pile_operandes,op1_calcul / op2_calcul);
            end case;
         else raise P_Expression.Exc_Erreur;
         end if;
      end loop;
      Depiler(Une_Pile => Pile_operandes,
              Elem     => op2_calcul);
      if ppile.Pile_Vide(Pile_operandes) then Put_Line("BIEN !"); end if;
      Put_Line("vrai calcul : " & P_Expression.Calcul(V)'Image);
      Put_Line("faux calcul: "); return op1_calcul;
   exception
      when E: others => Put_Line(Exception_Information(E)); return 0;
   end Calcul;


the good function:
   function  Calcul ( V : in T_Vect_Token) return Integer is
      Pile   : P_Pile_Token.T_Pile(80); 
      Res    : Integer;
      Token1,
      Token2    : T_Ptr_Token ;
      Ptr_Token : T_Ptr_Token ;
   begin
      for I in V'range loop
         Ptr_Token := V(I);
         if Ptr_Token.all'Tag = T_Token_Operande'Tag
            then
            Empiler(Pile,Ptr_Token);
         elsif
            Ptr_Token.all'Tag = T_Token_Operateur'Tag
            then
            Depiler(Pile,Token2);
            Depiler(Pile,Token1);
            case Get_Elem(T_Token_Operateur(Ptr_Token.all)) is
               when'+' => Res := Get_Elem (T_Token_Operande(Token1.all)) +
                  Get_Elem (T_Token_Operande(Token2.all));
               when'-' => Res := Get_Elem (T_Token_Operande(Token1.all))-
                  Get_Elem (T_Token_Operande(Token2.all));
               when'*' => Res := Get_Elem (T_Token_Operande(Token1.all)) *
                  Get_Elem (T_Token_Operande(Token2.all));
               when'/' => Res := Get_Elem (T_Token_Operande(Token1.all)) /
                  Get_Elem (T_Token_Operande(Token2.all));
            end case;
            Empiler(Pile,Set_Ptr(Res));
         else
            Ada.Text_Io.Put_Line("TOKEN intru ");
            raise Exc_Erreur;
         end if;
      end loop;
      Depiler(Pile,Ptr_Token);
      if Pile_Vide(Pile)
         then
         return Get_Elem(T_Token_Operande(Ptr_Token.all));
      else
         Ada.Text_Io.Put_Line("Pile non vide ");
         raise Exc_Erreur;
      end if;
   exception
      when others => Ada.Text_Io.Put_Line ("Erreur CALCUL");
         raise Exc_Erreur;
   end Calcul;

^ permalink raw reply	[relevance 1%]

* Re: "end of declaration"
  2021-02-10 18:39  1% "end of declaration" Mehdi Saada
  2021-02-10 19:21  0% ` Egil H H
@ 2021-02-10 20:59  0% ` Shark8
  1 sibling, 0 replies; 200+ results
From: Shark8 @ 2021-02-10 20:59 UTC (permalink / raw)


On Wednesday, February 10, 2021 at 11:40:00 AM UTC-7, 0012... wrote:
> can someone explain in simple terms what are the rules for types' "end of declaration" ? 
> 
> I define a type in the private part of the package, and in the body I clone it (type t_proba2 is new t_proba) to benefit from its predefined operations... since it's a fixed point type I need to, or bam ! recursion... also I want the accuracy etc to stay the same so I would do the same for floating point types too. 
> 
> type T_Proba is delta 0.00001 range 0.0 .. 1.0; 
> for T_Proba'Small use 0.00001; 
> 
> package body P_Proba2 is 
> type t_proba2 is new T_Proba; 
> -- type t_proba2 can't be use before the end of its declaration 
> package Point_Fixe_io is new Ada.Text_Io.Fixed_IO(T_Proba); 
> 
> so I rather defined a different type with the same specifications. ugly. 
> no nicer way to access predefined operations for these cases ?
Use more meaningful names if you can.
You had "Type K is new K", which is obvious nonsense.
Considering the context, I think something like
> type Probability is delta 0.00001 range 0.0 .. 1.0; 
> for Probability'Small use 0.00001;
and
> type Internal_Probability is new Probability;
would be much better readability-/maintainability-wise

^ permalink raw reply	[relevance 0%]

* Re: "end of declaration"
  2021-02-10 18:39  1% "end of declaration" Mehdi Saada
@ 2021-02-10 19:21  0% ` Egil H H
  2021-02-10 20:59  0% ` Shark8
  1 sibling, 0 replies; 200+ results
From: Egil H H @ 2021-02-10 19:21 UTC (permalink / raw)


On Wednesday, February 10, 2021 at 7:40:00 PM UTC+1, 0012...@gmail.com wrote:
> 
> I define a type in the private part of the package, and in the body I clone it (type t_proba2 is new t_proba) to benefit from its predefined operations... 
What? The predefined operations are already visible in the body.

> since it's a fixed point type I need to, or bam ! recursion...
huh? 

> package body P_Proba2 is 
> type t_proba2 is new T_Proba2; 
> -- type t_proba2 can't be use before the end of its declaration 
This is because of a typo... Try
    type t_proba2 is new T_Proba; 
instead. Except that you don't need this derived type, so just delete the line.

> package Point_Fixe_io is new Ada.Text_Io.Fixed_IO(T_Proba); 
...and here you're using the original type anyway, so...

> no nicer way to access predefined operations for these cases ?
Just call them, they are visible...

-- 
~egilhh

^ permalink raw reply	[relevance 0%]

* "end of declaration"
@ 2021-02-10 18:39  1% Mehdi Saada
  2021-02-10 19:21  0% ` Egil H H
  2021-02-10 20:59  0% ` Shark8
  0 siblings, 2 replies; 200+ results
From: Mehdi Saada @ 2021-02-10 18:39 UTC (permalink / raw)


can someone explain in simple terms what are the rules for types' "end of declaration" ?

I define a type in the private part of the package, and in the body I clone it (type t_proba2 is new t_proba) to benefit from its predefined operations... since it's a fixed point type I need to, or bam ! recursion... also I want the accuracy etc to stay the same so I would do the same for floating point types too.

   type T_Proba is delta 0.00001 range 0.0 .. 1.0;
   for T_Proba'Small use 0.00001;

package body P_Proba2 is
      type t_proba2 is new T_Proba2;
-- type t_proba2 can't be use before the end of its declaration
   package Point_Fixe_io is new Ada.Text_Io.Fixed_IO(T_Proba);

so I rather defined a different type with the same specifications. ugly.
no nicer way to access predefined operations for these cases ?

^ permalink raw reply	[relevance 1%]

* Pascal triangle algorithm ("homework"). iterative one. the direct one was simple.
@ 2021-01-30 14:40  1% Mehdi Saada
  0 siblings, 0 replies; 200+ results
From: Mehdi Saada @ 2021-01-30 14:40 UTC (permalink / raw)


Here's this, complete with put_line and comments...
Sorry for the length. I can't even follow anymore where's it going wrong and why. tried to. At least the "swap" routine does what it 's supposed to.
I hope you'll enlighten me.

with Ada.Text_IO;
use Ada.Text_IO;

procedure Pascal is
   type Tab_type is array(Natural range <>) of Natural;
   function Factorial (Number: Natural) return Positive is
      result: Positive := 1;
   begin
      for I in 1..Number loop
         result := Result * I;
      end loop;
      return result;
   end Factorial;
   function Give_Pascal_factoriel (N_rank: in Natural) return Tab_type is
      Result: Tab_type(0..N_rank);
   begin
      if N_rank+1 mod 2 = 0 then
         for I in 0..N_rank/2 loop
            Result(I) := Factorial(N_rank) / (Factorial(N_rank-I)*Factorial(I));
         end loop;
         Result(N_rank/2+1..N_rank) := Result(0..N_rank/2);
      else
         for I in 0..N_rank/2 loop
            Result(I) := Factorial(N_rank) / (Factorial(N_rank-I)*Factorial(I));
            Result(N_rank-I) := Result(I);
         end loop;
      end if;
      return Result;
   end Give_Pascal_factoriel;
   function Give_Pascal_iterative (N_rank: in Natural) return Tab_type is
      Temp1, Temp2: Tab_type(0..N_rank+2):= (1 => 1, others => 0);
      Index1, Index2: Natural;
      procedure Swap(Temp2, Temp1: in out Tab_type;Index2, Index1: in out Natural) is
         temp_vrai_index : Natural := index1;
         Temp_vrai: Tab_type := temp1;
      begin
         temp1(0..index2) := temp2(0..Index2);
         index1 := index2;
         temp2 := Temp_vrai;
         index2 := temp_vrai_index;
      end Swap;
   begin
      if N_rank = 0 then return Tab_type'(0=> 1);
      elsif N_rank = 1 then return (1,1);
      else
         temp1(0..2) := (0,1,1);
         index1 := 2;
         -- each instance of this loop creates a new line on array 2 from array1
         -- then arrays are swapped.
         for N in 1..N_rank loop
            -- each instance of the inner loop fill one slot of array2 up to N/2, and reciprocally on the other side of the array
            -- then in case the number of coefficients for the nth line is even
            -- the last one at place N/2+1 (considering the array starts at 0);

            for I in 1..N/2 loop
               Put_Line("I = " & I'Image);
               Put_Line("temp1(I) : " & temp1(I)'Image);
               Put_Line("temp1(I-1): " & temp1(I-1)'Image);
               temp2(I) := temp1(I-1) + temp1(I);
               Put_Line("temp2((I)'Image is now :" & temp2(I)'Image);
            end loop;
            Put_Line("temp2 :" );
            for A of temp2(1..N/2) loop
               Put_Line(A'Image);
            end loop;
            if N mod 2 = 0 then
               Put_Line("N = " & N'Image & " so number of coefficients is odd");
               temp2(N/2+1) := temp1(N/2) + temp1(N/2+1);
            end if;
            Index2 := index1 + 1;         
            Swap(Index2 => Index2, Index1 => Index1,
                 Temp2  => Temp2, Temp1  => Temp1);
          
            -- index1 and index2 serve only to swap the arrays,
            -- whose size is constant and put to the max they'll have to be.
         end loop;
      end if;
      return Temp2(1..N_rank+2);
   end Give_Pascal_iterative;
   tab_result : Tab_type(0..6);
begin
   tab_result := Give_Pascal_iterative(N_rank => 5);
   New_Line;
   
   Put_Line("attempt");
   for A  of tab_result loop
      Put_Line(A'Image);
   end loop;
end Pascal;

Listing: /bin/sh -c /home/mehdi/obj/pascal
temp2 :
I =  1
temp1(I) :  1
temp1(I-1):  0
temp2((I)'Image is now : 1
temp2 :
 1
N =  2 donc nombre de cefficients impairs
I =  1
temp1(I) :  1
temp1(I-1):  0
temp2((I)'Image is now : 1
temp2 :
 1
I =  1
temp1(I) :  1
temp1(I-1):  0
temp2((I)'Image is now : 1
I =  2
temp1(I) :  0
temp1(I-1):  1
temp2((I)'Image is now : 1
temp2 :
 1
 1
N =  4 donc nombre de cefficients impairs
I =  1
temp1(I) :  1
temp1(I-1):  0
temp2((I)'Image is now : 1
I =  2
temp1(I) :  1
temp1(I-1):  1
temp2((I)'Image is now : 2
temp2 :
 1
 2

essai
 1
 1
 0
 0
 0
 0
 0
[2021-01-30 14:34:20] process terminated successfully, elapsed time: 01.04s

^ permalink raw reply	[relevance 1%]

* Re: ... !! GPS
  2021-01-29 16:15  1% ... !! GPS Mehdi Saada
@ 2021-01-29 18:39  0% ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2021-01-29 18:39 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> I wish gps weird unintuitive behavior would not add a source of
> irritation to my already existing difficulties.
> This:
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Main is begin
>    Put_Line("essai factoriels: de 1 à 5");
> end Main;
>
> results in:
> /bin/sh -c /home/mehdi/obj/main
> [2021-01-29 17:08:00] process terminated successfully, elapsed time: 00.25s

Did you choose "run in an external terminal"? Try not checking that box

> project Default is
>     for Source_Dirs use ("src");
>     for Object_Dir use "obj";
>     for Main use ("main.adb");
> end Default;
>
> it always uses "src" which includes the files from other
> projects/exos. So they appear on the project... !

I suggest you use a different top level directory for each project:

~/project1/...
~/project2/...

Also, I find
   for Exec_Dir use ".";
helpful

> Is there a simple compiler which still corrects for semantics ?

DWIM considered dangerous! Wikipedia:

   "DWIM (do what I mean) computer systems attempt to anticipate what
   users intend to do, correcting trivial errors automatically rather
   than blindly executing users' explicit but potentially incorrect
   input."

^ permalink raw reply	[relevance 0%]

* ... !! GPS
@ 2021-01-29 16:15  1% Mehdi Saada
  2021-01-29 18:39  0% ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2021-01-29 16:15 UTC (permalink / raw)


I wish gps weird unintuitive behavior would not add a source of irritation to my already existing difficulties.
This:
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is begin
   Put_Line("essai factoriels: de 1 à 5");
end Main;

results in:
/bin/sh -c /home/mehdi/obj/main
[2021-01-29 17:08:00] process terminated successfully, elapsed time: 00.25s

What the Ѐßß is that ? it ran on other exercises, then would not, so with a minimal program... it fails too.

project Default is
    for Source_Dirs use ("src");
    for Object_Dir use "obj";
    for Main use ("main.adb");
end Default;

it always uses "src" which includes the files from other projects/exos. So they appear on the project... !

Thanks for putting up with this...
Is there a simple compiler which still corrects for semantics ?

^ permalink raw reply	[relevance 1%]

* "begginner", sorting algorithm.
@ 2021-01-29 14:57  1% Mehdi Saada
  0 siblings, 0 replies; 200+ results
From: Mehdi Saada @ 2021-01-29 14:57 UTC (permalink / raw)


 I'm starting again after years and very different studies.
This is a sorting algorithm for already ordered arrays, but with (many) duplicated elements. Of course it doesn't work instantly...
Please be sweet and help me figure out what goes wrong.

Principle :
IndiceA_1 and IndiceB_1 starts at 1.
For each array there is a loop between IndiceA_1+1 and the last array superior limit index, which stops when IndiceX2 is chosen as the last index for which Tx(IndiceX1) = Tx(IndiceX2). The loop is exited when the equality holds no more, and we get to the loop for the other array.
I want to obtain IndiceA_1, IndiceA_2, IndiceB_1, IndiceB_2 so that depending on order both data array slices, slices on data arrays are added to the result array with 
if TA(IndiceA_1) <= TB(IndiceB_1)
then
TC(IndiceC..IndiceC+IndiceA_2+IndiceB_2-IndiceA_1-IndiceA_2 + 1) := TA(IndiceA_1..IndiceA_2) & TA(IndiceB_1..IndiceB_2)
else
TC(IndiceC..IndiceC+IndiceA_2+IndiceB_2-IndiceA_1-IndiceA_2 + 2) := TA(IndiceB_1..IndiceB_2) & TA(IndiceA_1..IndiceA_2);
end if;

The indices are adjusted accordingly with :
IndiceC := IndiceC + IndiceA_2 + IndiceB_2 - IndiceA_1 - IndiceA_2 + 2;
IndiceB_1 := IndiceB_2 + 1;
IndiceA_1 := IndiceA_2 + 1;

And the main loop starts again.
The end is a finish… the programs doesn’t go there yet.

Here's it all.

with Ada.Text_IO; use Ada.text_io;
procedure Main is
   type Tableau is array(Positive range <>) of Integer;
   procedure Tri_Tableaux_ordonnés (TA, TB: in Tableau; TC: out Tableau) is
      IndiceA_1, IndiceA_2 : Positive range Ta'Range := TA'First;
      IndiceB_1, IndiceB_2 : Positive range Tb'Range := TB'First;
      IndiceC: Positive range 1..TC'Last+1 := TC'First;
      Fini_A, Fini_B: Boolean;
   begin
      loop
         for Asub in IndiceA_1+1..TA'Last loop
            if TA(Asub) /= TA(IndiceA_1) then
               IndiceA_2 := (if Asub = TA'Last - 1 then TA'Last else Asub-1);
               exit;
            end if;
            Put_Line("IndiceA_1 : " & IndiceA_1'Image);
            Put_Line("IndiceA_2 : " & IndiceA_2'Image);
         end loop;
         for Bsub in IndiceB_1+1..TB'Last-1 loop
            if TB(Bsub) /= TB(IndiceB_1) then
               IndiceB_2 := (if Bsub = TB'Last - 1 then TB'Last else Bsub-1);
               exit;
            end if;
            Put_Line("IndiceB_1 : " & IndiceB_1'Image);
            Put_Line("IndiceB_2 : " & IndiceB_2'Image);
         end loop;
         if TA(IndiceA_1) <= TB(IndiceB_1) then
            TC(IndiceC..IndiceC+IndiceA_2+IndiceB_2-IndiceA_1-IndiceA_2 + 2)
              := TA(IndiceA_1..IndiceA_2) & TA(IndiceB_1..IndiceB_2);
         else
            TC(IndiceC..IndiceC+IndiceA_2+IndiceB_2-IndiceA_1-IndiceA_2 + 2)
              := TA(IndiceB_1..IndiceB_2) & TA(IndiceA_1..IndiceA_2);
         end if;

         if IndiceA_2 = TA'Last then Fini_A := True;
         elsif IndiceB_2 = TB'Last then Fini_B := True;
         end if;
         IndiceA_1 := IndiceA_2 + 1;
         IndiceB_1 := IndiceB_2 + 1;
         IndiceC := IndiceC+IndiceA_2+IndiceB_2-IndiceA_1-IndiceA_2 + 3;
         exit when Fini_A or Fini_B;
      end loop;
      if not Fini_A and Fini_B then
         if Fini_B then
            TC(IndiceC..Tc'Last) := TA(IndiceA_1..TA'Last);
         elsif Fini_A then
            TC(IndiceC..Tc'Last) := TB(IndiceB_1..TB'Last);
         end if;
      end if;
    pragma Assert(IndiceC > TC'Last);
   end Tri_Tableaux_ordonnés;
   A: Tableau := (1, 3, 9, 11);
   B: Tableau := (5, 55, 99);
   C: Tableau(1..A'Length+B'Length);
begin
   Tri_Tableaux_ordonnés(TA => A, 
                          TB => B,
                          TC => C);
   for element of C loop
      Put_Line(element'Image);
   end loop;
end Main;

^ permalink raw reply	[relevance 1%]

* Problem with unbounded string input
@ 2021-01-27 19:59  1% Brian McGuinness
  0 siblings, 0 replies; 200+ results
From: Brian McGuinness @ 2021-01-27 19:59 UTC (permalink / raw)


I was having trouble reading unbounded strings, so I wrote a short test program and had the same problem.

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

procedure scan2 is
  use Ada.Strings.Unbounded;
  line : Ada.Strings.Unbounded.Unbounded_String;
begin
  loop
    Ada.Text_IO.Put ("-> ");
    line := Ada.Text_IO.Unbounded_IO.Get_Line;
    exit when line = "quit";
    Ada.Text_IO.Unbounded_IO.Put_Line ("""" & line & """");
  end loop;
end scan2;

When I compile this with gnatmake 8.3.0 under Linux Mint Debian edition 4 and run it, every so often when I type a line and hit Enter there is no response until I hit Enter again, and then everything typed before the first Enter is ignored.  The rest of the time the lines I type are read and returned correctly.  I am really puzzled by this.  Is this a bug in the Ada library or am I doing something wrong?

--- Brian McGuinness

^ permalink raw reply	[relevance 1%]

* Re: Lower bounds of Strings
  @ 2021-01-15 19:36  1%         ` Egil H H
  0 siblings, 0 replies; 200+ results
From: Egil H H @ 2021-01-15 19:36 UTC (permalink / raw)


On Friday, January 15, 2021 at 6:35:54 PM UTC+1, Stephen Davies wrote:
> On Friday, 15 January 2021 at 11:41:24 UTC, J-P. Rosen wrote: 
> > function Slide (S : String) return String is 
> > (S(S'First) & S (S'First+1 .. S'Last));
> To me, this is a fundamental enough operation that, in the absence of 
> being able to specify a subtype where it happens automatically, it at 
> least deserves to be an attribute. But then again, I also think that 
> the attribute Trim_Image should be added, and I know you disagree 
> with me on that too :-)

Not entirely automatically, but you can do something like this:

...

   procedure Foo(Item :in out String) is
      subtype Mono_String is String (1..Item'Length);
   
      procedure Inner_Foo(Item : in out Mono_String) is
      begin
         Ada.Text_IO.Put_Line(Positive'Image(Item'First) & Positive'Image(Item'Last));
         Item(1) := 'C';
      end Inner_Foo;

   begin
      Inner_Foo(Item);
   end Foo;

 ...

   Foobar : String := "Foobar";
begin
   Foo(Foobar(4..5));
   Ada.Text_IO.Put_Line(Foobar);
...

^ permalink raw reply	[relevance 1%]

* Re: Lower bounds of Strings
  @ 2021-01-15 11:41  1%     ` J-P. Rosen
    0 siblings, 1 reply; 200+ results
From: J-P. Rosen @ 2021-01-15 11:41 UTC (permalink / raw)


Le 15/01/2021 à 11:24, Stephen Davies a écrit :
> I'd say my favourite solution proposed so far is the following,
> which surely can't be that hard to implement:
> Some_String'Slide(Some_Range)
Well, it's not that difficult to write a "slide" function, here it is as 
an expression function (with test program):

with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Slide is
    function Slide (S : String) return String is
           (S(S'First) & S (S'First+1 .. S'Last));

    S1 : String (3 .. 5);
    S2 : String := Slide (S1);
begin
    Put ("S1"); Put (S1'First'Image); Put (S1'Last'Image); New_Line;
    Put ("S2"); Put (S2'First'Image); Put (S2'Last'Image); New_Line;
end Test_Slide ;


-- 
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	[relevance 1%]

* Re: From_string(Arg : String) return Big_Integer
  2021-01-09 22:13  0%     ` DrPi
@ 2021-01-10  9:46  0%       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-01-10  9:46 UTC (permalink / raw)


On 2021-01-09 23:13, DrPi wrote:
> Le 09/01/2021 à 21:11, soren rundgren a écrit :
>> lördag 9 januari 2021 kl. 18:00:36 UTC+1 skrev AdaMagica:
>>> Since Ada 202X is not yet released, this package is not yet fully 
>>> implemented. (I had a conversation with AdaCore about a similar case 
>>> a year ago.)
>>
>> I managed to make a very basic solution by creating my own:
>>
>>     function My_From_String(S : String) return Big_Integer is
>>        sum : Big_Integer := 0;
>>        Len : constant Integer := S'Length;
>>        i : Integer := 1;
>>     begin
>>        -- Ada.Text_IO.Put_Line("My_From_String.S = " & S);
>>        while i <= Len loop
>>           case S(i) is -- i = Len : Len - Len = 0,
>>                        -- i = 1 : Len - 1
>>              when '1' => sum := sum + 1*10**(Len - i);
>>              when '2' => sum := sum + 2*10**(Len - i);
>>              when '3' => sum := sum + 3*10**(Len - i);
>>              when '4' => sum := sum + 4*10**(Len - i);
>>              when '5' => sum := sum + 5*10**(Len - i);
>>              when '6' => sum := sum + 6*10**(Len - i);
>>              when '7' => sum := sum + 7*10**(Len - i);
>>              when '8' => sum := sum + 8*10**(Len - i);
>>              when '9' => sum := sum + 9*10**(Len - i);
>>              when others => null;
>>           end case;
>>           i := i + 1;
>>        end loop;
>>        return sum;
>>     end My_From_String;
>>
> A much simpler function for Integer :
> 
>     function Int_From_String (Str : String) return Integer is
>        Num : Integer := 0;
>     begin
>        for C of Str loop

for C in Str'Range loop

>           Num := (Num * 10) + Integer'Value((1 => C));

    Num := Num * 10 + Character'Pos (C) - Character'Pos'('0');

> Notes :
> - I don't have a 202x compiler, so I can't check if it works with big ints.
> - It does not manage the sign (like the function you designed).

- It does not handle overflow;
- It does not handle missing numbers in the input;
- It does not handle malformed input;
- It does not handle bases other than 10;
- It does not handle blank characters at the ends.

Functions mimicking S'Value (X) cover only half of cases. For the other 
half you need to get the number from a part of the string, so you have 
to recognize the end of the number and return the index or position 
where it ends or another token begins.

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

^ permalink raw reply	[relevance 0%]

* Re: From_string(Arg : String) return Big_Integer
  2021-01-09 20:11  1%   ` soren rundgren
@ 2021-01-09 22:13  0%     ` DrPi
  2021-01-10  9:46  0%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: DrPi @ 2021-01-09 22:13 UTC (permalink / raw)


Le 09/01/2021 à 21:11, soren rundgren a écrit :
> lördag 9 januari 2021 kl. 18:00:36 UTC+1 skrev AdaMagica:
>> Since Ada 202X is not yet released, this package is not yet fully implemented. (I had a conversation with AdaCore about a similar case a year ago.)
> 
> I managed to make a very basic solution by creating my own:
> 
>     function My_From_String(S : String) return Big_Integer is
>        sum : Big_Integer := 0;
>        Len : constant Integer := S'Length;
>        i : Integer := 1;
>     begin
>        -- Ada.Text_IO.Put_Line("My_From_String.S = " & S);
>        while i <= Len loop
>           case S(i) is -- i = Len : Len - Len = 0,
>                        -- i = 1 : Len - 1
>              when '1' => sum := sum + 1*10**(Len - i);
>              when '2' => sum := sum + 2*10**(Len - i);
>              when '3' => sum := sum + 3*10**(Len - i);
>              when '4' => sum := sum + 4*10**(Len - i);
>              when '5' => sum := sum + 5*10**(Len - i);
>              when '6' => sum := sum + 6*10**(Len - i);
>              when '7' => sum := sum + 7*10**(Len - i);
>              when '8' => sum := sum + 8*10**(Len - i);
>              when '9' => sum := sum + 9*10**(Len - i);
>              when others => null;
>           end case;
>           i := i + 1;
>        end loop;
>        return sum;
>     end My_From_String;
> 
A much simpler function for Integer :

    function Int_From_String (Str : String) return Integer is
       Num : Integer := 0;
    begin
       for C of Str loop
          Num := (Num * 10) + Integer'Value((1 => C));
       end loop;

       return Num;
    end Int_From_String;

Notes :
- I don't have a 202x compiler, so I can't check if it works with big ints.
- It does not manage the sign (like the function you designed).

^ permalink raw reply	[relevance 0%]

* Re: From_string(Arg : String) return Big_Integer
    2021-01-09 20:09  1%   ` soren rundgren
@ 2021-01-09 20:11  1%   ` soren rundgren
  2021-01-09 22:13  0%     ` DrPi
  1 sibling, 1 reply; 200+ results
From: soren rundgren @ 2021-01-09 20:11 UTC (permalink / raw)


lördag 9 januari 2021 kl. 18:00:36 UTC+1 skrev AdaMagica:
> Since Ada 202X is not yet released, this package is not yet fully implemented. (I had a conversation with AdaCore about a similar case a year ago.)

I managed to make a very basic solution by creating my own:

   function My_From_String(S : String) return Big_Integer is
      sum : Big_Integer := 0;
      Len : constant Integer := S'Length;
      i : Integer := 1;
   begin
      -- Ada.Text_IO.Put_Line("My_From_String.S = " & S);
      while i <= Len loop
         case S(i) is -- i = Len : Len - Len = 0,
                      -- i = 1 : Len - 1
            when '1' => sum := sum + 1*10**(Len - i);
            when '2' => sum := sum + 2*10**(Len - i);
            when '3' => sum := sum + 3*10**(Len - i);
            when '4' => sum := sum + 4*10**(Len - i);
            when '5' => sum := sum + 5*10**(Len - i);
            when '6' => sum := sum + 6*10**(Len - i);
            when '7' => sum := sum + 7*10**(Len - i);
            when '8' => sum := sum + 8*10**(Len - i);
            when '9' => sum := sum + 9*10**(Len - i);
            when others => null;
         end case;
         i := i + 1;
      end loop;
      return sum;
   end My_From_String;

^ permalink raw reply	[relevance 1%]

* Re: From_string(Arg : String) return Big_Integer
  @ 2021-01-09 20:09  1%   ` soren rundgren
  2021-01-09 20:11  1%   ` soren rundgren
  1 sibling, 0 replies; 200+ results
From: soren rundgren @ 2021-01-09 20:09 UTC (permalink / raw)


lördag 9 januari 2021 kl. 18:00:36 UTC+1 skrev AdaMagica:
> Since Ada 202X is not yet released, this package is not yet fully implemented. (I had a conversation with AdaCore about a similar case a year ago.)

I managed to make a very baic solution by creating my own:

   function My_From_String(S : String) return Big_Integer is
      sum : Big_Integer := 0;
      Len : constant Integer := S'Length;
      i : Integer := 1;
   begin
      -- Ada.Text_IO.Put_Line("My_From_String.S = " & S);
      while i <= Len loop
         case S(i) is -- i = Len : Len - Len = 0,
                      -- i = 1 : Len - 1
            when '1' => sum := sum + 1*10**(Len - i);
            when '2' => sum := sum + 2*10**(Len - i);
            when '3' => sum := sum + 3*10**(Len - i);
            when '4' => sum := sum + 4*10**(Len - i);
            when '5' => sum := sum + 5*10**(Len - i);
            when '6' => sum := sum + 6*10**(Len - i);
            when '7' => sum := sum + 7*10**(Len - i);
            when '8' => sum := sum + 8*10**(Len - i);
            when '9' => sum := sum + 9*10**(Len - i);
            when others => null;
         end case;
         i := i + 1;
      end loop;
      return sum;
   end My_From_String;

^ permalink raw reply	[relevance 1%]

* Re: Lower bounds of Strings
  2021-01-05 12:32  1%   ` Jeffrey R. Carter
@ 2021-01-05 13:40  1%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-01-05 13:40 UTC (permalink / raw)


On 2021-01-05 13:32, Jeffrey R. Carter wrote:
> On 1/5/21 12:57 PM, Dmitry A. Kazakov wrote:
>>
>> This is a constraint, a meaningless and dangerous one:
>>
>>     procedure Foo (X : Mono_String);
>>     S : String := "abcdefgh";
>> begin
>>     Foo (S (2..S'Last)); -- Boom! Constraint_Error
> 
> Surely the slice would slide, as it does in
> 
> with Ada.Text_IO;
> 
> procedure Slider is
>     subtype S7 is String (1 .. 7);
> 
>     procedure Foo (X : in S7);
> 
>     procedure Foo (X : in S7) is
>        -- Empty
>     begin -- Foo
>        Ada.Text_IO.Put (Item => X (7) );
>        Ada.Text_IO.New_Line;
>     end Foo;
> 
>     S : constant String := "abcdefgh";
> begin -- Slider
>     Foo (X => S (2 .. 8) );
> end Slider;
> 
> ~/Code$ gnatmake -gnatan -gnato2 -O2 -fstack-check slider.adb
> x86_64-linux-gnu-gcc-9 -c -gnatan -gnato2 -O2 -fstack-check slider.adb
> x86_64-linux-gnu-gnatbind-9 -x slider.ali
> x86_64-linux-gnu-gnatlink-9 slider.ali -O2 -fstack-check
> ~/Code$ ./slider
> h

Yes, but here S7 is definite, it is a quite different case. Sliding 
indefinite subtypes without copies, with access types allowed?

And even with definite subtypes it is broken:

    with Ada.Text_IO;  use Ada.Text_IO;

    procedure Main is
       subtype S7 is String (1..7);
       S : constant String := "abcdefgh";
       V : S7 renames S (2..8);
    begin
       Put_Line ("Is it broken? " & Boolean'Image (S (7) = V (7)));
    end Main;

This will print: Is it broken? TRUE

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

^ permalink raw reply	[relevance 1%]

* Re: Lower bounds of Strings
  @ 2021-01-05 12:32  1%   ` Jeffrey R. Carter
  2021-01-05 13:40  1%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2021-01-05 12:32 UTC (permalink / raw)


On 1/5/21 12:57 PM, Dmitry A. Kazakov wrote:
> 
> This is a constraint, a meaningless and dangerous one:
> 
>     procedure Foo (X : Mono_String);
>     S : String := "abcdefgh";
> begin
>     Foo (S (2..S'Last)); -- Boom! Constraint_Error

Surely the slice would slide, as it does in

with Ada.Text_IO;

procedure Slider is
    subtype S7 is String (1 .. 7);

    procedure Foo (X : in S7);

    procedure Foo (X : in S7) is
       -- Empty
    begin -- Foo
       Ada.Text_IO.Put (Item => X (7) );
       Ada.Text_IO.New_Line;
    end Foo;

    S : constant String := "abcdefgh";
begin -- Slider
    Foo (X => S (2 .. 8) );
end Slider;

~/Code$ gnatmake -gnatan -gnato2 -O2 -fstack-check slider.adb
x86_64-linux-gnu-gcc-9 -c -gnatan -gnato2 -O2 -fstack-check slider.adb
x86_64-linux-gnu-gnatbind-9 -x slider.ali
x86_64-linux-gnu-gnatlink-9 slider.ali -O2 -fstack-check
~/Code$ ./slider
h

-- 
Jeff Carter
"I'm a vicious jungle beast!"
Play It Again, Sam
131

^ permalink raw reply	[relevance 1%]

* Re: renames usage
  2020-12-31 12:10  1% ` John Perry
@ 2020-12-31 13:31  0%   ` DrPi
  0 siblings, 0 replies; 200+ results
From: DrPi @ 2020-12-31 13:31 UTC (permalink / raw)


Le 31/12/2020 à 13:10, John Perry a écrit :
> No. Assignment copies the object, and changes to the copy don't affect the original, while renaming obtains a reference to the object. This program will illustrate it:
> 
> with Ada.Text_IO; use Ada.Text_IO;
> 
> procedure Test_Renames is
> 
>     S: String := "hello world";
>     T: String := S;
>     U: String renames S;
> 
> begin
> 
>     Put_Line(S);
> 
>     T(T'First) := 'y';
>     Put_Line(S); -- still "hello world"
> 
>     U(U'First) := 'y';
>     Put_Line(S); -- "yello world"
> 
> end Test_Renames;
> 

Understood. Thanks.

^ permalink raw reply	[relevance 0%]

* Re: renames usage
  @ 2020-12-31 12:10  1% ` John Perry
  2020-12-31 13:31  0%   ` DrPi
  0 siblings, 1 reply; 200+ results
From: John Perry @ 2020-12-31 12:10 UTC (permalink / raw)


No. Assignment copies the object, and changes to the copy don't affect the original, while renaming obtains a reference to the object. This program will illustrate it:

with Ada.Text_IO; use Ada.Text_IO;

procedure Test_Renames is

   S: String := "hello world";
   T: String := S;
   U: String renames S;

begin

   Put_Line(S);

   T(T'First) := 'y';
   Put_Line(S); -- still "hello world"

   U(U'First) := 'y';
   Put_Line(S); -- "yello world"

end Test_Renames;

^ permalink raw reply	[relevance 1%]

* Re: Advent of Code Day 3
  @ 2020-12-03 14:37  1% ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2020-12-03 14:37 UTC (permalink / raw)


On 12/3/20 2:00 PM, Stephen Leake wrote:
> easy puzzle; the only mildly difficult part was getting the wrap right;
> I made my own string type to allow starting at index 0. I made the map
> indices match Emacs line, column display for easier debugging.

I just used

    if Pos > Line'Last then
       Pos := Pos - Line'last;
    end if;

and the default 1-based indices for Strings returned by the Ada.Text_IO.Get_Line 
function worked fine.

The fun bit was how big the answer to the 2nd part was.

-- 
Jeff Carter
"I'll get broads up here like you wouldn't believe.
Swingers. Freaks. Nymphomaniacs. Dental hygienists."
Play It Again, Sam
125

^ permalink raw reply	[relevance 1%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-30 20:21  2% Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
                   ` (2 preceding siblings ...)
  2020-09-04 10:14  1% ` liyan white
@ 2020-09-24  4:10  1% ` nimaopatel121
  3 siblings, 0 replies; 200+ results
From: nimaopatel121 @ 2020-09-24  4:10 UTC (permalink / raw)


On Friday, 31 July 2020 01:51:10 UTC+5:30, Blady  wrote:
> Hello,
> 
> Given a legacy code calling many Put_Line from Ada.Text_IO which works 
> nice in a Terminal, I want to add a mode which sends these outputs to 
> another process without changing the legacy code too much.
> And I want to keep the Terminal mode.
> 
> Is there a way to create a File_Type object (from Ada.Text_IO) which 
> would have user defined Get and Put subprograms instead of the 
> predefined ones of the file system?
> 
> Thus in my case, I will create a custom File_Type object My_Output with 
> the user define Put which will send the lines to the other process and 
> then I will call "Set_Output (My_Ouput);" before the legacy code.
> 
> Thanks Pascal.

^ permalink raw reply	[relevance 1%]

* Re: Visibility issue
  @ 2020-09-16 10:23  1%           ` Daniel
  0 siblings, 0 replies; 200+ results
From: Daniel @ 2020-09-16 10:23 UTC (permalink / raw)


El miércoles, 16 de septiembre de 2020 a las 9:14:23 UTC+2, Dmitry A. Kazakov escribió:

> That is OK, but the hidden part needs to be constructed in some way. Your 
> requirements are silent about how. There exist only two possibilities, 
> it is either generated internally or else provided by the client 
> externally in some form, e.g. as parameters for the constructing function.
The Requirements are not constraining how to construct the API handle in both sides (Client, API and Internal). Im lucky with that. :)
Let's try to set and construct all hidden part details from Internal side, not from user side. I will add Just a public Registering type because it will be a limited pool of callbacks and users needs to Identify them.

What needs to know the user?
  -the implementation of the callback procedure it self
  -A number that identify this procedure (they are constrained to lets say just 12 procedures)

What needs to know and access the Internal package side?
   - A hidden part of Handle_type with dirty details about buffer pointers that needs to be set before triggering the procedure.
  - The callback procedure from a pool implemented in the same Internal package hierarchy that previously set the user.

Let me expose a simplification using the 3 parts: Client, API, Implementing.

-- USER SIDE: ---
procedure mycallback6 (S: in out Handle) is
begin
---call to public Handle functions
   ada.text_io.Put_Line(S.public_for_users);
end mycallback6;

procedure Initialize is
MyUserCallbackRegister : Register_type := (mycallback'Access , 6);
begin
null;
end Initialize;

-- API SIDE: ---------
package API.Callbacks
--Manage the callback:
type Handle is tagged private
type pointer_to_Procedure is access procedure (Self : API.CAllbacks.Handle );
function public_for_users(S: in out Handle) return string;
--Manage registering the callback
type Register_type is private;
function Register_Callback ( cp: CallbackProcedure , ID: Natural ) return Register_type ;
private
type Handle is tagged record
Usefull_for_Implementing_side : Pointer_To_buffer_type;
Register : Register_type; 
end record;
end package API.Callbacks;
type Register_type is Natural;

with Internal.Pool;
package body API.Callbacks is
function Register_Callback ( cp: CallbackProcedure , ID: Natural ) return Register_type  is
begin
   Internal.CallbacksPool.Set( cp, ID);
  return Register_type'(ID);
end Register_Callback;

----- IMPLEMENTING SIDE: --------
with API.Callbacks;
with Buffer_Stuff;
package body Internal.CallbacksPool is

task body InteranalCaller6 is
MyInternalHandle : API.Handle;
callbackprocedure: API.CallbackProcedure := Get_from_pool_of_callbacks (6);
begin
-- I need to set here the private part of MyInternalHandle defined in API.Handle before triggering and I Can't. :(
-- If I want to set this private part with a function, the only way is to make it public and accessible for users too.
 MyInternalHandle := ????
--Later I trigger:
 callbackprocedure (MyInternalHandle);
end InteranalCaller6 ;

end Internal.CallbacksPool;
-----------------------------------

So, here comes my options:
-- Set MyInternalHandle with a public function visible to users in API and tryng to explain them with education that they can't use it.
-- Implement the Internal details in API package hierarchy extending API.Handle
-- Saying to who give me this requirements I can't do it using Ada (and probably any other language)
-- Some other magic idea to implement this totally different :)

^ permalink raw reply	[relevance 1%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-30 20:21  2% Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
  2020-07-30 21:51  1% ` J-P. Rosen
  2020-07-31 18:19  1% ` Shark8
@ 2020-09-04 10:14  1% ` liyan white
  2020-09-24  4:10  1% ` nimaopatel121
  3 siblings, 0 replies; 200+ results
From: liyan white @ 2020-09-04 10:14 UTC (permalink / raw)


On Friday, July 31, 2020 at 1:51:10 AM UTC+5:30, Blady wrote:
> Hello,
> 
> Given a legacy code calling many Put_Line from Ada.Text_IO which works 
> nice in a Terminal, I want to add a mode which sends these outputs to 
> another process without changing the legacy code too much.
> And I want to keep the Terminal mode.
> 
> Is there a way to create a File_Type object (from Ada.Text_IO) which 
> would have user defined Get and Put subprograms instead of the 
> predefined ones of the file system?
> 
> Thus in my case, I will create a custom File_Type object My_Output with 
> the user define Put which will send the lines to the other process and 
> then I will call "Set_Output (My_Ouput);" before the legacy code.
> 
> Thanks Pascal.

^ permalink raw reply	[relevance 1%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-08-01  7:46  1%   ` Blady
@ 2020-08-01 17:23  2%     ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2020-08-01 17:23 UTC (permalink / raw)


On Saturday, August 1, 2020 at 1:46:24 AM UTC-6, Blady wrote:
> Le 31/07/2020 à 20:19, Shark8 a écrit :
> > On Thursday, July 30, 2020 at 2:21:10 PM UTC-6, Blady wrote:
> >> Hello,
> >>
> >> Given a legacy code calling many Put_Line from Ada.Text_IO which works
> >> nice in a Terminal, I want to add a mode which sends these outputs to
> >> another process without changing the legacy code too much.
> >> And I want to keep the Terminal mode.
> >>
> >> Is there a way to create a File_Type object (from Ada.Text_IO) which
> >> would have user defined Get and Put subprograms instead of the
> >> predefined ones of the file system?
> > 
> > Kind of; I have a generic interface-package that I use for dealing with text-io and its permutations.
> > 
> > I just published it on github: https://github.com/OneWingedShark/EVIL/tree/master/src
> > It's part of what's intended to be a verified, general purpose library -- though I'm still teaching myself SPARK -- and so I've only published the file-interfacing utility portion.
> 
> Have you an example of how to use it?

with
--Ada.Wide_Wide_Text_IO.Text_Streams;
Ada.Text_IO.Text_Streams;

use
--Ada.Wide_Wide_Text_IO;
Ada.Text_IO;

Package Example is
   -- Bring in the Text-stream namespace.
   Use Ada.Text_IO.Text_Streams;
   
   -- Instantiate EVIL.Util.Files.
   Package Uniform_IO is New EVIL.Util.Files
      (
        Character	=> Character,
        String		=> String,
	File_Type	=> Ada.Text_IO.File_Type,
	File_Mode	=> Ada.Text_IO.File_Mode,
	Stream_Access	=> Ada.Text_IO.Text_Streams.Stream_Access
      );
  File : Uniform_IO.File:= Uniform_IO.Create( "Test.tmp", Ada.Text_IO.Out_File );
Begin

   Declare
      Test_String : Constant String := "-TESTING!!-";
   Begin
      String'Write( Test_File.Stream, Test_String );
   End;

End Example;

I don't have it implemented yet, but I plan on doing a "stream splitter" so you could say, use one stream to write to both the file and Standard_IO.

> >> Thus in my case, I will create a custom File_Type object My_Output with
> >> the user define Put which will send the lines to the other process and
> >> then I will call "Set_Output (My_Ouput);" before the legacy code.
> > 
> > It might be a better idea to have them as TASKs and in a single program, selecting and/or creating/executing the proper task ass needed. (If you have access to the legacy-program sources, you could wrap them or their interfaces in the TASK.)
> 
> Yes, I'll try in that way.

It'll probably save you some headache; I've found tasks really good at timed/cyclic events.

^ permalink raw reply	[relevance 2%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-08-01  7:42  1%       ` Blady
@ 2020-08-01 13:45  2%         ` J-P. Rosen
  0 siblings, 0 replies; 200+ results
From: J-P. Rosen @ 2020-08-01 13:45 UTC (permalink / raw)


Le 01/08/2020 à 09:42, Blady a écrit :
> There is always use clause for Text_IO in the code, the point is to
> catch those Put_Line calls with no file parameter.
That's exactly where Adasubst comes handy:
Just use a dictionary with:
   ada.text_io.put_line{standard.string} => My_TIO.Put_Line


-- 
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	[relevance 2%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-31 18:19  1% ` Shark8
@ 2020-08-01  7:46  1%   ` Blady
  2020-08-01 17:23  2%     ` Shark8
  0 siblings, 1 reply; 200+ results
From: Blady @ 2020-08-01  7:46 UTC (permalink / raw)


Le 31/07/2020 à 20:19, Shark8 a écrit :
> On Thursday, July 30, 2020 at 2:21:10 PM UTC-6, Blady wrote:
>> Hello,
>>
>> Given a legacy code calling many Put_Line from Ada.Text_IO which works
>> nice in a Terminal, I want to add a mode which sends these outputs to
>> another process without changing the legacy code too much.
>> And I want to keep the Terminal mode.
>>
>> Is there a way to create a File_Type object (from Ada.Text_IO) which
>> would have user defined Get and Put subprograms instead of the
>> predefined ones of the file system?
> 
> Kind of; I have a generic interface-package that I use for dealing with text-io and its permutations.
> 
> I just published it on github: https://github.com/OneWingedShark/EVIL/tree/master/src
> It's part of what's intended to be a verified, general purpose library -- though I'm still teaching myself SPARK -- and so I've only published the file-interfacing utility portion.

Have you an example of how to use it?

>> Thus in my case, I will create a custom File_Type object My_Output with
>> the user define Put which will send the lines to the other process and
>> then I will call "Set_Output (My_Ouput);" before the legacy code.
> 
> It might be a better idea to have them as TASKs and in a single program, selecting and/or creating/executing the proper task ass needed. (If you have access to the legacy-program sources, you could wrap them or their interfaces in the TASK.)

Yes, I'll try in that way.

^ permalink raw reply	[relevance 1%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-08-01  5:35  1%     ` J-P. Rosen
@ 2020-08-01  7:42  1%       ` Blady
  2020-08-01 13:45  2%         ` J-P. Rosen
  0 siblings, 1 reply; 200+ results
From: Blady @ 2020-08-01  7:42 UTC (permalink / raw)


Le 01/08/2020 à 07:35, J-P. Rosen a écrit :
> Le 31/07/2020 à 19:06, Blady a écrit :
>> The simplest solution (I found) is to add a virtual dummy Text_IO
>> package (name My_TIO) with Put_Line defined inside processing the values
>> and sending the lines to the other process if needed.
> Looks reasonable
> 
>> And I replaced everywhere with "Ada.Text_IO;" by "with My_TIO;".
>> But Text_IO is also used for file management inside the legacy code
>> which made me going to wrap all the Text_IO stuff :-(
> Did you think that you can simply use "renames" to reexport the
> operations of Text_IO from My_TIO ?

Yes I'll try in that way.

> You could also leave Text_IO and My_TIO. Use Adasubst to automatically
> change all the special operations from Text_IO to My_TIO.
> https://www.adalog.fr/en/components.html#adasubst

There is always use clause for Text_IO in the code, the point is to 
catch those Put_Line calls with no file parameter.

^ permalink raw reply	[relevance 1%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-31 17:06  2%   ` Blady
@ 2020-08-01  5:35  1%     ` J-P. Rosen
  2020-08-01  7:42  1%       ` Blady
  0 siblings, 1 reply; 200+ results
From: J-P. Rosen @ 2020-08-01  5:35 UTC (permalink / raw)


Le 31/07/2020 à 19:06, Blady a écrit :
> The simplest solution (I found) is to add a virtual dummy Text_IO
> package (name My_TIO) with Put_Line defined inside processing the values
> and sending the lines to the other process if needed.
Looks reasonable

> And I replaced everywhere with "Ada.Text_IO;" by "with My_TIO;".
> But Text_IO is also used for file management inside the legacy code
> which made me going to wrap all the Text_IO stuff :-(
Did you think that you can simply use "renames" to reexport the
operations of Text_IO from My_TIO ?

You could also leave Text_IO and My_TIO. Use Adasubst to automatically
change all the special operations from Text_IO to My_TIO.
https://www.adalog.fr/en/components.html#adasubst

-- 
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	[relevance 1%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-30 20:21  2% Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
  2020-07-30 21:51  1% ` J-P. Rosen
@ 2020-07-31 18:19  1% ` Shark8
  2020-08-01  7:46  1%   ` Blady
  2020-09-04 10:14  1% ` liyan white
  2020-09-24  4:10  1% ` nimaopatel121
  3 siblings, 1 reply; 200+ results
From: Shark8 @ 2020-07-31 18:19 UTC (permalink / raw)


On Thursday, July 30, 2020 at 2:21:10 PM UTC-6, Blady wrote:
> Hello,
> 
> Given a legacy code calling many Put_Line from Ada.Text_IO which works 
> nice in a Terminal, I want to add a mode which sends these outputs to 
> another process without changing the legacy code too much.
> And I want to keep the Terminal mode.
> 
> Is there a way to create a File_Type object (from Ada.Text_IO) which 
> would have user defined Get and Put subprograms instead of the 
> predefined ones of the file system?

Kind of; I have a generic interface-package that I use for dealing with text-io and its permutations.

I just published it on github: https://github.com/OneWingedShark/EVIL/tree/master/src
It's part of what's intended to be a verified, general purpose library -- though I'm still teaching myself SPARK -- and so I've only published the file-interfacing utility portion.

> 
> Thus in my case, I will create a custom File_Type object My_Output with 
> the user define Put which will send the lines to the other process and 
> then I will call "Set_Output (My_Ouput);" before the legacy code.

It might be a better idea to have them as TASKs and in a single program, selecting and/or creating/executing the proper task ass needed. (If you have access to the legacy-program sources, you could wrap them or their interfaces in the TASK.)

^ permalink raw reply	[relevance 1%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-30 21:51  1% ` J-P. Rosen
@ 2020-07-31 17:06  2%   ` Blady
  2020-08-01  5:35  1%     ` J-P. Rosen
  0 siblings, 1 reply; 200+ results
From: Blady @ 2020-07-31 17:06 UTC (permalink / raw)


Le 30/07/2020 à 23:51, J-P. Rosen a écrit :
> Le 30/07/2020 à 22:21, Blady a écrit :
> 
>> Given a legacy code calling many Put_Line from Ada.Text_IO which works
>> nice in a Terminal, I want to add a mode which sends these outputs to
>> another process without changing the legacy code too much.
>> And I want to keep the Terminal mode.
>>
>> Is there a way to create a File_Type object (from Ada.Text_IO) which
>> would have user defined Get and Put subprograms instead of the
>> predefined ones of the file system?
>>
>> Thus in my case, I will create a custom File_Type object My_Output with
>> the user define Put which will send the lines to the other process and
>> then I will call "Set_Output (My_Ouput);" before the legacy code.
>>
> Why don't you simply pipe the first process to the second one?

Yes, it was an option.
But I have to catch the outputs during some specific execution phases 
and on some particular output values.
Both processes should then have an extra synchronization path which is 
too far for the considered changes.

The simplest solution (I found) is to add a virtual dummy Text_IO 
package (name My_TIO) with Put_Line defined inside processing the values 
and sending the lines to the other process if needed.
And I replaced everywhere with "Ada.Text_IO;" by "with My_TIO;".
But Text_IO is also used for file management inside the legacy code 
which made me going to wrap all the Text_IO stuff :-(

Then I went to think of the possibility of user defined Put and Get 
subprograms for a Text_IO File_Type object.
However, I even don't know if it is feasible on an Unix-Like OS but I 
would be pleased to having this possibility in an Ada way.

Pascal.


^ permalink raw reply	[relevance 2%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  2020-07-30 20:21  2% Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
@ 2020-07-30 21:51  1% ` J-P. Rosen
  2020-07-31 17:06  2%   ` Blady
  2020-07-31 18:19  1% ` Shark8
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 200+ results
From: J-P. Rosen @ 2020-07-30 21:51 UTC (permalink / raw)


Le 30/07/2020 à 22:21, Blady a écrit :

> Given a legacy code calling many Put_Line from Ada.Text_IO which works
> nice in a Terminal, I want to add a mode which sends these outputs to
> another process without changing the legacy code too much.
> And I want to keep the Terminal mode.
> 
> Is there a way to create a File_Type object (from Ada.Text_IO) which
> would have user defined Get and Put subprograms instead of the
> predefined ones of the file system?
> 
> Thus in my case, I will create a custom File_Type object My_Output with
> the user define Put which will send the lines to the other process and
> then I will call "Set_Output (My_Ouput);" before the legacy code.
> 
Why don't you simply pipe the first process to the second one?


-- 
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	[relevance 1%]

* Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
@ 2020-07-30 20:21  2% Blady
  2020-07-30 21:51  1% ` J-P. Rosen
                   ` (3 more replies)
  0 siblings, 4 replies; 200+ results
From: Blady @ 2020-07-30 20:21 UTC (permalink / raw)


Hello,

Given a legacy code calling many Put_Line from Ada.Text_IO which works 
nice in a Terminal, I want to add a mode which sends these outputs to 
another process without changing the legacy code too much.
And I want to keep the Terminal mode.

Is there a way to create a File_Type object (from Ada.Text_IO) which 
would have user defined Get and Put subprograms instead of the 
predefined ones of the file system?

Thus in my case, I will create a custom File_Type object My_Output with 
the user define Put which will send the lines to the other process and 
then I will call "Set_Output (My_Ouput);" before the legacy code.

Thanks Pascal.

^ permalink raw reply	[relevance 2%]

* Re: Fixed vs float and precision and conversions
  2020-07-08 16:16  1%     ` Shark8
@ 2020-07-08 18:08  0%       ` Björn Lundin
  0 siblings, 0 replies; 200+ results
From: Björn Lundin @ 2020-07-08 18:08 UTC (permalink / raw)


Den 2020-07-08 kl. 18:16, skrev Shark8:
> On Wednesday, July 8, 2020 at 2:15:43 AM UTC-6, björn lundin wrote:
>> Den 2020-07-07 kl. 23:58, skrev Shark8:
>>> On Tuesday, July 7, 2020 at 3:10:22 PM UTC-6, björn lundin wrote:
>>>>


> Ok, so one thing to keep in mind here is that type-wise you're dealing not with two types, but *three* -- the type on the other side, the values in the Global_Odds_Table; the IEEE754 transport, via JSON serialization and deserialization; and the type on your side, Fixed_Type.

hmm no. valuies in global_odds_table are fixed_type
   Global_Odds_Table : array(Tics_Type'Range) of Fixed_Type := (

The type on the other side arrive in JSON as float. In deserialisation I 
convert to Fixed_Type.
I don't quite follow you


> 
> So then, the correct way to set up your end of things is to have a Fixed_Type which only has the values of Global_Odds_Table for your general-purpose/internal-usage, and have a conversion function for handling the IEEE754; here you are:
> 
>      Lowest_Odds  : Constant := 1.01;
>      Highest_Odds : Constant := 1_000.00;
>      type Odds_Base is delta 0.001 digits 18 range Lowest_Odds..Highest_Odds;
>      Subtype Odds is Odds_Base -- range Lowest_Odds..Hihgest_Odds
>        with Predicate_Failure => raise Constraint_Error with
>          Odds_Base'Image(Odds) & " is not a valid value.",
>        Static_Predicate => Odds in
>          --    Global_Odds_Table
>            1.01 |   1.02 |   1.03 |   1.04 |   1.05 |
>            2.00 |   2.02 |   2.04 |   2.06 |   2.08 |   2.10 |
>            3.00 |   3.05 |   3.10 |   3.15 |   3.20 |   3.25 |
>            4.00 |   4.10 |   4.20 |   4.30 |   4.40 |   4.50 |
>            5.00 |   5.10 |   5.20 |   5.30 |   5.40 |   5.50 |
>           10.00 |  10.50 |  11.00 |  11.50 |  12.00 |  12.50 |
>           20.00 |  21.00 |  22.00 |  23.00 |  24.00 |  25.00 |
>           50.00 |  55.00 |  60.00 |  65.00 |  70.00 |  75.00 |
>          100.00 | 110.00 | 120.00 | 130.00 | 140.00 | 150.00 |
>          960.00 | 970.00 | 980.00 | 990.00 |1000.00 ;
>      
>      Function Convert( Input : Interfaces.IEEE_Float_32 ) return Odds is
>          use Interfaces;
>      Begin
>          Ada.Text_IO.Put_Line( "Input:" & Input'Image );
>          Ada.Text_IO.Put_Line( "OB:" & Odds_Base'Round(Input)'Image );
>          Return Odds'Round( Input );
>      Exception
>          When Constraint_Error =>
>              -- Handle out-of-range errors.
>              if Input < Lowest_Odds then
>                  return Lowest_Odds;
>              elsif Input > Highest_Odds then
>                  return Highest_Odds;
>              else
>                  declare
>                      --    Global_Odds_Table
>                      Table : Constant Array (Positive range <>) of IEEE_Float_32 :=
>                        ( 1.01,   1.02,   1.03,   1.04,   1.05,
>                          2.00,   2.02,   2.04,   2.06,   2.08,   2.10,
>                          3.00,   3.05,   3.10,   3.15,   3.20,   3.25,
>                          4.00,   4.10,   4.20,   4.30,   4.40,   4.50,
>                          5.00,   5.10,   5.20,   5.30,   5.40,   5.50,
>                          10.00,  10.50,  11.00,  11.50,  12.00,  12.50,
>                          20.00,  21.00,  22.00,  23.00,  24.00,  25.00,
>                          50.00,  55.00,  60.00,  65.00,  70.00,  75.00,
>                          100.00, 110.00, 120.00, 130.00, 140.00, 150.00,
>                          960.00, 970.00, 980.00, 990.00,1000.00 );
>                      Closest_Index : Positive      := 1;
>                      Closest_Value : IEEE_Float_32 := IEEE_Float_32'Last;
>                  begin
>                      For X in Table'Range loop
>                          if abs (Input - Table(X)) < Closest_Value then
>                              Closest_Value:= abs (Input - Table(X));
>                              Closest_Index:= X;
>                          end if;
>                      end loop;
>                      
>                      Return  Odds'Round( Table(Closest_Index) );
>                  end;
>              end if;
>      End Convert;
> 
> The bad thing here is that you have to repeat Global_Odds_Table, though this isn't so bad as the second is fully contained within the exception-handler; further, searching the table is done only when 'Round cannot be used directly. Also, this version does catch out of bounds errors and coerce them to the nearest bound. -- You might want to write a one-off program to generate the Predicate-form and array-value form of Global_Odds_Table, since there's 350 values.
> 

hmm, nice. I'll implement this if not the thing I implemented and 
deployed *10* minutes ago works.

it is based on the fact that I have a float-to-fixed_type converted 
price in a fixed_type variable.

It -as it turns out  - can be

* too low for a specific value (as 5.099 vs 5.10)
* correct
* too high for a specific value

So I call below function with the converted value,
and then I look up returned index in the table/array
It also only goes to fix things only if incorrect/illegal value

   ---------

   function Get_Tic_Index(Price : Fixed_Type) return Tics_Type is
   begin
      --optimistic approch - we have the coorect conversion
     for I in Global_Odds_Table'Range loop
       if Global_Odds_Table(I) = Price then
         return I;
       end if;
     end loop;

     -- ok - did not find any -> bad float then

     -- it has to be a valid value within min an max
     declare
       P   : Fixed_Type;
       D   : Fixed_Type := 0.001 ;
       Min : Fixed_Type;
       Max : Fixed_Type;
     begin

       -- Find Index in odds table which is just below given odds
       for I in Global_Odds_Table'Range loop
         if Global_Odds_Table(I) < Price then
           Min := Global_Odds_Table(I);
         else
           exit; -- must have found it
         end if;
       end loop;

       -- Find Index in odds table which is just above given odds
       for I in Global_Odds_Table'Range loop
         if Global_Odds_Table(I) > Price then
           Max := Global_Odds_Table(I);
           exit;
         end if;
       end loop;

       -- now step carefully util we get a hit or we have to give up

       Log("Get_Tic_Index", "try fixing bad float price " &  Price'Img);
       P := Min + D;
       loop
         for I in Global_Odds_Table'Range loop
           if Global_Odds_Table(I) = P then
             Log("Get_Tic_Index", "fixed bad float - min/max " & 
Min'Img & " / " & Max'Img);
             return I;
           end if;
         end loop;
         exit when P > Max; --give up, and propagate exception
         Log("Get_Tic_Index", "fixing bad float p/min/max " &  P'Img & 
Min'Img & " / " & Max'Img);
         P := P + D;
       end loop;
       Log("Get_Tic_Index", "did not fix bad float min/max " &  Min'Img 
& " / " & Max'Img);
     end;

     raise Bad_Odds with Price'Img;
   end Get_Tic_Index;

   ---------


Thanks for the time and effort


-- 
Björn

^ permalink raw reply	[relevance 0%]

* Re: Fixed vs float and precision and conversions
  @ 2020-07-08 16:16  1%     ` Shark8
  2020-07-08 18:08  0%       ` Björn Lundin
  0 siblings, 1 reply; 200+ results
From: Shark8 @ 2020-07-08 16:16 UTC (permalink / raw)


On Wednesday, July 8, 2020 at 2:15:43 AM UTC-6, björn lundin wrote:
> Den 2020-07-07 kl. 23:58, skrev Shark8:
> > On Tuesday, July 7, 2020 at 3:10:22 PM UTC-6, björn lundin wrote:
> >>
> >> I have a fixed type
> >>     type Fixed_Type is delta 0.001 digits 18;
> >>
> >> but JSON does not support that. So I get floats instead.
> > This is a limitation of JSON, IIUC: all numeric are IEE754 floats -- see: https://www.json.org/json-en.html
> 
> Yes.
> 
> > 
> > If you have access to both sides of the serialization, you could define an intermediate serialization say a string of "Fixed_Type#value#" where 'value' is the string-representation you need. -- You can extract the value by indexing on the '#' characters, extracting the portion in between, and feeding that via Fixed_Type'Value( EXTRACTED_SUBSTRING ), and produce it via "Fixed_Type#" & Fixed_Type'Image( fp_value ) & '#'.
> 
> Interesting - but for another project.
> Here, I do not own the other side.
> 
> Perhaps I should have stated that the other side is Betfair, and in this 
> case I get odds of horse races via their API.
> The only valid odds are in a fixed set of numbers like
> 
> they have small increments in the beginning, which increase as the odds 
> go up
> like this partial array shows where
>    type Tics_Type is new integer range 1 .. 350;
> 
> Global_Odds_Table : array(Tics_Type'Range) of Fixed_Type := (
> 1.01,   1.02,   1.03,   1.04,   1.05,
> ...
> 2.00,   2.02,   2.04,   2.06,   2.08,   2.10,
> ...
> 3.00,   3.05,   3.10,   3.15,   3.20,   3.25,
> ...
> 4.00,   4.10,   4.20,   4.30,   4.40,   4.50,
> ...
> 5.00,   5.10,   5.20,   5.30,   5.40,   5.50,
> ...
> 10.00,  10.50,  11.00,  11.50,  12.00,  12.50,
> ...
> 20.00,  21.00,  22.00,  23.00,  24.00,  25.00,
> ...
> 50.00,  55.00,  60.00,  65.00,  70.00,  75.00,
> ...
> 100.00, 110.00, 120.00, 130.00, 140.00, 150.00,
> ...
> 960.00, 970.00, 980.00, 990.00,1000.00);
> 
> 
> so I get 5.1 from the JSON, which is occasionaly converted to 5.099, 
> which I have trouble to find in the array above.
> I am now thinking of traversing it and make an absolute diff like 
> abs(myval - arrayval) and pick the one with smallest diff.
> 
> But my idea of using fixed was to escape the rounding errors.
> But hmm, here it is about feeding data _into_ the system, and here I'll 
> get the error, while the rest will work nice.
> 
> Hmm, I need to do some testing
> 
> Thanks for the reply
> 
> 
> -- 
> Björn

Ok, so one thing to keep in mind here is that type-wise you're dealing not with two types, but *three* -- the type on the other side, the values in the Global_Odds_Table; the IEEE754 transport, via JSON serialization and deserialization; and the type on your side, Fixed_Type.

So then, the correct way to set up your end of things is to have a Fixed_Type which only has the values of Global_Odds_Table for your general-purpose/internal-usage, and have a conversion function for handling the IEEE754; here you are:

    Lowest_Odds  : Constant := 1.01;
    Highest_Odds : Constant := 1_000.00;
    type Odds_Base is delta 0.001 digits 18 range Lowest_Odds..Highest_Odds;
    Subtype Odds is Odds_Base -- range Lowest_Odds..Hihgest_Odds
      with Predicate_Failure => raise Constraint_Error with
        Odds_Base'Image(Odds) & " is not a valid value.",
      Static_Predicate => Odds in
        --    Global_Odds_Table
          1.01 |   1.02 |   1.03 |   1.04 |   1.05 |
          2.00 |   2.02 |   2.04 |   2.06 |   2.08 |   2.10 |
          3.00 |   3.05 |   3.10 |   3.15 |   3.20 |   3.25 |
          4.00 |   4.10 |   4.20 |   4.30 |   4.40 |   4.50 |
          5.00 |   5.10 |   5.20 |   5.30 |   5.40 |   5.50 |
         10.00 |  10.50 |  11.00 |  11.50 |  12.00 |  12.50 |
         20.00 |  21.00 |  22.00 |  23.00 |  24.00 |  25.00 |
         50.00 |  55.00 |  60.00 |  65.00 |  70.00 |  75.00 |
        100.00 | 110.00 | 120.00 | 130.00 | 140.00 | 150.00 |
        960.00 | 970.00 | 980.00 | 990.00 |1000.00 ;
    
    Function Convert( Input : Interfaces.IEEE_Float_32 ) return Odds is
        use Interfaces;
    Begin
        Ada.Text_IO.Put_Line( "Input:" & Input'Image );
        Ada.Text_IO.Put_Line( "OB:" & Odds_Base'Round(Input)'Image );
        Return Odds'Round( Input );
    Exception
        When Constraint_Error =>
            -- Handle out-of-range errors.
            if Input < Lowest_Odds then
                return Lowest_Odds;
            elsif Input > Highest_Odds then
                return Highest_Odds;
            else
                declare
                    --    Global_Odds_Table
                    Table : Constant Array (Positive range <>) of IEEE_Float_32 :=
                      ( 1.01,   1.02,   1.03,   1.04,   1.05,
                        2.00,   2.02,   2.04,   2.06,   2.08,   2.10,
                        3.00,   3.05,   3.10,   3.15,   3.20,   3.25,
                        4.00,   4.10,   4.20,   4.30,   4.40,   4.50,
                        5.00,   5.10,   5.20,   5.30,   5.40,   5.50,
                        10.00,  10.50,  11.00,  11.50,  12.00,  12.50,
                        20.00,  21.00,  22.00,  23.00,  24.00,  25.00,
                        50.00,  55.00,  60.00,  65.00,  70.00,  75.00,
                        100.00, 110.00, 120.00, 130.00, 140.00, 150.00,
                        960.00, 970.00, 980.00, 990.00,1000.00 );
                    Closest_Index : Positive      := 1;
                    Closest_Value : IEEE_Float_32 := IEEE_Float_32'Last;
                begin
                    For X in Table'Range loop
                        if abs (Input - Table(X)) < Closest_Value then
                            Closest_Value:= abs (Input - Table(X));
                            Closest_Index:= X;
                        end if;
                    end loop;
                    
                    Return  Odds'Round( Table(Closest_Index) );
                end;
            end if;
    End Convert;

The bad thing here is that you have to repeat Global_Odds_Table, though this isn't so bad as the second is fully contained within the exception-handler; further, searching the table is done only when 'Round cannot be used directly. Also, this version does catch out of bounds errors and coerce them to the nearest bound. -- You might want to write a one-off program to generate the Predicate-form and array-value form of Global_Odds_Table, since there's 350 values.

^ permalink raw reply	[relevance 1%]

* Re: How to terminate all running tasks?
  2020-06-10 13:49  0% ` Jeffrey R. Carter
@ 2020-06-10 14:45  0%   ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2020-06-10 14:45 UTC (permalink / raw)


On 6/10/20 3:49 PM, Jeffrey R. Carter wrote:
> On 6/10/20 1:14 PM, Gilbert Gosseyn wrote:
>> package packp6 is
>>    procedure tp6pm(N : Long_Integer);
>> end packp6;
>>
>> with Ada.Text_IO; use Ada.Text_IO;
>> package body packp6 is
>>    procedure tp6pm(N : Long_Integer) is
>>       package LIO is new Integer_IO(Long_Integer);
> 
>          Solution_Found : Boolean := False;
>          pragma Atomic (Solution_Found);
>>
>>       task p6p;
>>
>>       task body p6p is
>>          pp,i : Long_Integer := 0;
>>       begin
>>          loop
>                exit when Solution_Found;
> 
>>             i := i+1;
>>             pp := 6*i+1;
>>             if N mod pp = 0 then
>>                new_line;put("pp= ");LIO.put(pp);
>                   Solution_Found := True;
>>             end if;
>>          end loop;
>>       end p6p;

Sorry, of course the variables previously in P6m have to be declared here:

          pm,i : Long_Integer := 0;

>>    begin
>>       loop
>             exit when Solution_Found;
> 
>>          i := i+1;
>>          pm := 6*i-1;
>>          if N mod pm = 0 then
>>             new_line;put("pm= ");LIO.put(pm);
>                Solution_Found := True;
>>          end if;
>>        end loop;
>>    end tp6pm;
>> end packp6;

-- 
Jeff Carter
"Unix and C are the ultimate computer viruses."
Richard Gabriel
99

^ permalink raw reply	[relevance 0%]

* Re: How to terminate all running tasks?
  2020-06-10 11:14  1% How to terminate all running tasks? Gilbert Gosseyn
  2020-06-10 12:12  0% ` Niklas Holsti
@ 2020-06-10 13:49  0% ` Jeffrey R. Carter
  2020-06-10 14:45  0%   ` Jeffrey R. Carter
  1 sibling, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2020-06-10 13:49 UTC (permalink / raw)


On 6/10/20 1:14 PM, Gilbert Gosseyn wrote:
> package packp6 is
>    procedure tp6pm(N : Long_Integer);
> end packp6;
> 
> with Ada.Text_IO; use Ada.Text_IO;
> package body packp6 is
>    procedure tp6pm(N : Long_Integer) is
>       package LIO is new Integer_IO(Long_Integer);

         Solution_Found : Boolean := False;
         pragma Atomic (Solution_Found);
> 
>       task p6p;
> 
>       task body p6p is
>          pp,i : Long_Integer := 0;
>       begin
>          loop
               exit when Solution_Found;

>             i := i+1;
>             pp := 6*i+1;
>             if N mod pp = 0 then
>                new_line;put("pp= ");LIO.put(pp);
                  Solution_Found := True;
>             end if;
>          end loop;
>       end p6p;
>    begin
>       loop
            exit when Solution_Found;

>          i := i+1;
>          pm := 6*i-1;
>          if N mod pm = 0 then
>             new_line;put("pm= ");LIO.put(pm);
               Solution_Found := True;
>          end if;
>        end loop;
>    end tp6pm;
> end packp6;

-- 
Jeff Carter
"Unix and C are the ultimate computer viruses."
Richard Gabriel
99

^ permalink raw reply	[relevance 0%]

* Re: How to terminate all running tasks?
  2020-06-10 11:14  1% How to terminate all running tasks? Gilbert Gosseyn
@ 2020-06-10 12:12  0% ` Niklas Holsti
  2020-06-10 13:49  0% ` Jeffrey R. Carter
  1 sibling, 0 replies; 200+ results
From: Niklas Holsti @ 2020-06-10 12:12 UTC (permalink / raw)


On 2020-06-10 14:14, Gilbert Gosseyn wrote:
> Hi,

It would be easier to understand your post if you started with the 
explanation and question, rather than throwing a bunch of uncommented 
code at the reader.

> -- package spezification
> package packp6 is
>     procedure tp6pm(N : Long_Integer);
> end packp6;
> 
> -- package body
> with Ada.Text_IO; use Ada.Text_IO;
> with Ada.Task_Identification;
> package body packp6 is
>     procedure tp6pm(N : Long_Integer) is
>        use Ada.Task_Identification;
>        package LIO is new Integer_IO(Long_Integer);
>        solution_found : exception;
> 
>        task p6p;
>        task p6m;
> 
>        task body p6p is
>           pp,i : Long_Integer := 0;
>        begin
>           loop
>              i := i+1;
>              pp := 6*i+1;
>              if N mod pp = 0 then
>                 new_line;put("pp= ");LIO.put(pp);
>                 raise solution_found;
>              end if;
>           end loop;


This is the last point at which you can handle the "raise" above. If 
there is no handler here, WITHIN task p6p, the exception will try to 
propagate out of the task, which will terminate the task and STOP the 
propagation of the exception.

>        end p6p;
> 
>        task body p6m is
>           pm,i : Long_Integer := 0;
>        begin
>           loop
>              i := i+1;
>              pm := 6*i-1;
>              if N mod pm = 0 then
>                 new_line;put("pm= ");LIO.put(pm);
>                 raise solution_found;
>              end if;
>           end loop;


Same comment as above.

>        end p6m;
>     begin
>        null;
>     exception
>        when solution_found =>


This handler is never entered, because the "null" statement above does 
not raise solution_found.

>           Abort_Task(p6p'Identity);
>           Abort_Task(p6m'Identity);
>     end tp6pm;
> end packp6;


    [snip]

> When in a task the exception solution_found is raised, then I want
> all running tasks to be terminated immediately.

It is not possible to use an exception, raised in a task, to signal 
something outside the task in that way.

> Apparently this does not happen. How to improve?


You must use some other way to inform the main subprogram that a 
solution has been found. There are may ways, but for example you can use 
an synchronization object as follows:

    with Ada.Synchronous_Task_Control;
    ...
    solution_found : Ada.Synchronous_Task_Control.Suspension_Object;
    ...
    task body p6p
       ...
       Ada.Synchronous_Task_Control.Set_True (solution_found);
       -- Instead of the "raise".
    ...
    same for task p6m

and in the main subprogram, instead of the null statement and the 
exception handler:

    Ada.Synchronous_Task_Control.Suspend_Until_True (solution_found);
    abort p6p;
    abort p6m;

-- 
Niklas Holsti

niklas holsti tidorum fi
       .      @       .

^ permalink raw reply	[relevance 0%]

* How to terminate all running tasks?
@ 2020-06-10 11:14  1% Gilbert Gosseyn
  2020-06-10 12:12  0% ` Niklas Holsti
  2020-06-10 13:49  0% ` Jeffrey R. Carter
  0 siblings, 2 replies; 200+ results
From: Gilbert Gosseyn @ 2020-06-10 11:14 UTC (permalink / raw)


Hi,
-- package spezification
package packp6 is
   procedure tp6pm(N : Long_Integer);
end packp6;

-- package body
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Task_Identification;
package body packp6 is
   procedure tp6pm(N : Long_Integer) is
      use Ada.Task_Identification;
      package LIO is new Integer_IO(Long_Integer);
      solution_found : exception;

      task p6p;
      task p6m;

      task body p6p is
         pp,i : Long_Integer := 0;
      begin
         loop
            i := i+1;
            pp := 6*i+1;
            if N mod pp = 0 then
               new_line;put("pp= ");LIO.put(pp);
               raise solution_found;
            end if;
         end loop;
      end p6p;

      task body p6m is
         pm,i : Long_Integer := 0;
      begin
         loop
            i := i+1;
            pm := 6*i-1;
            if N mod pm = 0 then
               new_line;put("pm= ");LIO.put(pm);
               raise solution_found;
            end if;
         end loop;
      end p6m;
   begin
      null;
   exception
      when solution_found =>
         Abort_Task(p6p'Identity);
         Abort_Task(p6m'Identity);    
   end tp6pm;
end packp6;

-- test
with packp6; use packp6;
procedure P6_Test is
NN : Long_Integer := 11111111111111111;
begin
   tp6pm(NN);
end P6_Test;

-- test result:

pm=         2071723
pp=     5363222357


When in a task the exception solution_found is raised, then I want all running tasks to be terminated immediately. Apparently this does not happen. How to improve?

^ permalink raw reply	[relevance 1%]

* Re: GNAT vs Matlab - operation on   multidimensional complex matrices
  2020-03-23 23:16  1% GNAT vs Matlab - operation on multidimensional complex matrices darek
@ 2020-06-08 17:42  1% ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2020-06-08 17:42 UTC (permalink / raw)


Cleaning out my computer, I found this working-file; it might be of interesti to you -- it shows "going all-in" with Generics:
--------------------------------------------------------------
With
Ada.Real_Time,
Ada.Containers.Indefinite_Holders,
Ada.Numerics.Long_Complex_Types,
Ada.Exceptions,
Ada.Text_IO.Complex_IO;

Procedure Demo is
    package TIO renames Ada.Text_IO;
    package CTIO is new TIO.Complex_IO(Ada.Numerics.Long_Complex_Types);

    subtype mReal   is Long_Float;
    subtype Complex is Ada.Numerics.Long_Complex_Types.Complex;


    NumIteration : constant  := 1_000;
    NumChannels  : constant  := 64;
    NumRanges    : constant  := 400;
    NumAngles    : constant  := 30;


    Type Channel is range 1..NumChannels;
    Type Angle   is range 1..NumAngles;
    Type Range_T is range 1..NumRanges;

    type tCubeReal    is array (Channel, Angle, Range_T) of mReal;
    type tCubeComplex is array (Channel, Angle, Range_T) of Complex;

    Generic
        Type T is private;
        Type IndexA is (<>);
        Type IndexB is (<>);
        Type IndexC is (<>);
        Type Cubic is Array(IndexA, IndexB, indexC) of T;
        Zero : in T;
        with Function "+"(Left, Right: T) return T is <>;
    Function Summation( Input : Cubic ) return T
      with Inline;

    Function Summation( Input : Cubic ) return T is
    Begin
        Return Result : T := Zero do
            For A in IndexA loop
                For B in IndexB loop
                    For C in IndexC loop
                        Result:= Result + Input(A, B, C);
                    End loop;
                End loop;
            End loop;
        End return;
    End Summation;

    Generic
        Type Element is private;
        Type Cubic is array (Channel, Angle, Range_T) of Element;
        Zero : In Element;
        with Function "+"(Left, Right: Element) return Element is <>;
    Procedure Timing_Harness(Mtx : in Cubic;  S: out Element; Iterations : in Positive:= 1);

    Procedure Timing_Harness(Mtx : in Cubic;  S: out Element; Iterations : in Positive:= 1) is
        Function Sum is new Summation(Element, Channel, Angle, Range_T, Cubic, Zero);
        Use Ada.Real_Time;
        Start : Time renames Clock;
    Begin
        For Count in 1..Iterations Loop
            S := Sum( Mtx );
        End loop;


        METRICS:
        Declare
            Execution_Time  : Constant Time_Span:= Clock - Start;
            Execution_Image : Constant String:= Duration'Image(To_Duration(Execution_Time));
            T : Constant mReal := mReal(To_Duration(Execution_Time))/mReal(NumIteration);
        Begin
            TIO.New_Line;
            TIO.Put_Line("Computation time:" & Execution_Image );
            TIO.Put_Line("Computation time per iteration:" & mReal'Image(T));
        End METRICS;
    End Timing_Harness;


    Function Image( Input : mReal   )  return string renames mReal'Image;
    Function Image( Input : Complex )  return string is
        ('(' & mReal'Image(Input.Re) & ", " & mReal'Image(Input.Im) & ')');
    
    Generic
        Type T is private;
        Type IndexA is (<>);
        Type IndexB is (<>);
        Type IndexC is (<>);
        Type Cubic is Array(IndexA, IndexB, indexC) of T;
        Default : in T;
    Package Test_Data is
        Type Access_Cubic is not null access all Cubic;

        Access_Data : Constant Access_Cubic := new Cubic'(others => (others => (others => Default)));
        Data        : Cubic renames Access_Data.all;
    End Test_Data;

    Generic
        Type Element    is private;
        Type Cube_Array is array (Channel, Angle, Range_T) of Element;
        Default,
        Zero      : in Element;
        Test_Name : in String;
        with Function "+"(Left, Right: Element) return Element is <>;
        with Function Image( Input : Element )  return string  is <>;
    Procedure TEST;


    Procedure TEST is

        Package Test_Set is new Test_Data(
           T       => Element,
           IndexA  => Channel,
           IndexB  => Angle,
           IndexC  => Range_T,
           Cubic   => Cube_Array,
           Default => Default
          );
        
        procedure SpeedSum is new Timing_Harness(
           Element => Element,
           Cubic   => Cube_Array,
           Zero    => Zero,
           "+"     => TEST."+"
          );
        
        Cube   : Cube_Array renames Test_Set.Data;
        Result : Element;
    Begin
        TIO.Put_Line(Test_Name & " cube");
        TIO.Put_Line(Test_Name & " type size is:" & Integer'Image(Element'Size));

        SpeedSum(
           Mtx          => Cube,
           S            => Result,
           Iterations   => NumIteration
          );

        TIO.Put_Line("Sum is:" & Image(Result));
    End TEST;

Begin
    REAL_CUBE_TEST:
    Declare
        Procedure Do_Test is new Test(
           Element    => mReal,
           Cube_Array => tCubeReal,
           Default    => 1.0,
           Zero       => 0.0,
           Test_Name  => "Real"
          );
    Begin
        Do_Test;
    End REAL_CUBE_TEST;

    TIO.Put_Line( (1..20 => '-') ); -- Separator.

    COMPLEX_CUBE_TEST:
    Declare
        Procedure Do_Test is new Test(
           "+"        => Ada.Numerics.Long_Complex_Types."+",
           Element    => Complex,
           Cube_Array => tCubeComplex,
           Default    => (Re => 1.0, Im => 1.0),
           Zero       => (Re => 0.0, Im => 0.0),
           Test_Name  => "Complex"
          );
    Begin
        Do_Test;
    End COMPLEX_CUBE_TEST;



    TIO.Put_Line( (1..20 => '-') ); -- Separator.


    Ada.Text_IO.Put_Line( "Done." );
End Demo;

^ permalink raw reply	[relevance 1%]

* Re: CONSTRAINT ERROR: erroneous memory access
  2020-06-06 23:40  1% CONSTRAINT ERROR: erroneous memory access jcupak
@ 2020-06-07 15:53  0% ` Anh Vo
  0 siblings, 0 replies; 200+ results
From: Anh Vo @ 2020-06-07 15:53 UTC (permalink / raw)


On Saturday, June 6, 2020 at 4:40:04 PM UTC-7, jcu...@gmail.com wrote:
> It has been a few years since I have written Ada; I used and taught Ada 95 back when I was working for a defense contractor. But, now that I'm retired, I wanted to get up to speed with Ada 2012, so I decided to implement a main program to see how the Shortest_Paths generic package works (taken from A.18.31, pages 574-576). But, when I read in the data and call the Shortest_Path function, it returns with CONSTRAINT ERROR: erroneous memory access. I've tried multiple times, but can't seem to figure out what I'm doing (or NOT doing) wrong. 
> 
> Here's the main program:
> 
> with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
> with Ada.Float_Text_IO;   use Ada.Float_Text_IO;
> with Ada.Text_IO;         use Ada.Text_IO;
> with Shortest_Paths;
> with Ada.Command_Line;    use Ada.Command_Line;
> with DirectedEdge;        use DirectedEdge;
> with Ada.Containers;      use Ada.Containers;
> with Ada.Exceptions;
> 
> procedure Main_Test is
> 
>    Input_File : Ada.Text_IO.File_Type;
> 
>    Vertices   : Integer; -- Number of nodes
>    Edges      : Integer; -- Number of paths
> 
>    Tail       : Integer; -- Node From
>    Head       : Integer; -- Node To
>    Weight     : Float;   -- Path Weight/Distance/Cost
> 
>    -- Instantiate Shortest Paths package with 0..Integer'Last subtype
>    package SP is new Shortest_Paths(Node => Natural);
>    
>    -- Use Edge'Read to read the Edge components into Item
>    
>    -- Display directed edge components
>    procedure Display(Edge : in SP.Edge) is
>    begin
>       Put(Edge.From, Width=>1); Put("->");
>       Put(Edge.To,   Width=>1); Put(" ");
>       Put(Float(Edge.Length), Fore => 0, Aft => 2, Exp => 0); Put(" ");
>    end Display;
> 
>    -- Display directed edge components at cursor
>    -- Replace List'Write with Display
>    procedure Display(Cursor: in SP.Adjacency_Lists.Cursor)
>    is
>       Edge : SP.Edge := SP.Adjacency_Lists.Element(Cursor);
>    begin
>       Display(Edge); -- Let other procedure do all the work
>    end Display;
> 
> begin
> 
> -- Open input file using arg 1
>    Open (File => Input_File,
>          Mode => In_File,
>          Name => Argument(1)); -- ../tinyEWD.txt
> 
>    Set_Input(Input_File);        -- Redirect input
>    New_Line;
>    Put("Processing '"); Put(Argument(1)); Put_Line("'");
> 
>    -- Read number of nodes (vertices)
>    Get(Vertices); New_Line;
>    Put("Vertices: ");Put(Vertices, width=>2);New_Line;
> 
>    -- Read number of paths (edges)
>    Get(Edges);
>    Put("Edges:    ");Put(Edges, Width=>2);New_Line(2);
> 
>    declare
>    
>       -- Constrain Vertex to zero-based subrange
>       subtype Vertex is Natural range 0..Vertices-1;
>       
>       -- Adj is DLL of Adjacency Lists for each Vertex
>       Adj    : array (Vertex) of SP.Adjacency_Lists.List;
>       
>       -- Edge is a record of Tail, Head, and Weight components
>       Edge   : SP.Edge;
>    
>    begin
>    
>       Put_Line("Creating Adjacency Lists"); New_Line;
>    
>       -- For each node, create empty list of adjacent nodes
>       Create_Empty_Adjacency_Lists: for Node in Vertex loop
>       
>          -- Initialize each adjacency list to empty
>          Adj(Node) := SP.Adjacency_Lists.Empty_List;
>       
>       end loop Create_Empty_Adjacency_Lists;
>    
>       -- Display and append new edge to adjacency list for node
>       -- Constrain Edge index to natural subrange
>       Append_New_Edge: for E in 0..Edges-1 loop
>       
>          Put("Edge:     ");Put(E, Width=>2);Put(" ");
>       
>          -- Get edge components from data file
>          Get(Tail);   -- Tail
>          Get(Head);   -- Head
>          Get(Weight); -- Distance/Weight
>       
>          -- Set edge components
>          Edge.From   := Tail;
>          Edge.To     := Head;
>          Edge.Length := SP.Distance(Weight);
>       
>          -- Display Edge
>          Display(Edge);
>          Put(" Appended to edge ");Put(Tail,1);
>          New_Line;
>       
>          -- Append new edge to From adjacency list
>          -- Indicating path to another node
>          Adj(Edge.From).Append(Edge);
>       
>       end loop Append_New_Edge;
>       New_Line;
>    
>       Close(Input_File);
>       Set_Input(Standard_Input); -- Reset input source
>    
>       Put_Line("Node Adjacency Lists");
>    
>       -- Display contents of each adjacency list
>       Display_Adjacency_Lists: for Node in Vertex loop
>       
>          Put("Adj[");Put(Node, Width=>1);Put("] ");
>       
>          declare
>             Edges  : Ada.Containers.Count_Type;
>          begin
>          
>             -- How many edges are in this node?
>             Edges := SP.Adjacency_Lists.Length(Adj(Node));
>             Put(Integer(Edges), Width => 1);
>             if (Edges > 1) then
>                Put(" Edges: ");
>             else
>                Put(" Edge:  ");
>             end if;
>          
>             -- Iterate over all nodes in this adjacency list
>             -- and Display each edge for each node
>             SP.Adjacency_Lists.Iterate(Adj(Node), Process => Display'Access);
>          
>          end;
>          New_Line;
>       
>       end loop Display_Adjacency_Lists;
>       New_Line;
>    
>       -- Create Edge-Weighted Graph of Node and Adjacency List
>       declare
>          EWG    : SP.Graphs.Vector; -- Edge Weighted Graphs
>          Path   : SP.Paths.List;    -- Shortest Path
>       begin
>       
>          Put_Line("Creating Edge-Weighted Graphs.");
>          EWG := SP.Graphs.Empty_Vector;
>          Put_Line("EWG Empty_Vector created.");
>          
>          Put("Initializing Shortest Path to empty list...");
>          Path := SP.Paths.Empty_List;
>          Put_Line("done.");
>          
>          for Vertex in 0..Vertices-1 loop
>             Put("Vertex: ");Put(Vertex, Width => 1);
>             EWG.Append(Adj(Vertex));
>             Put_Line(" appended to EWG.");
>          end loop;
>          New_Line;
>          
>          Put("EWG.Length = "); Put(Integer(EWG.Length), Width => 1);New_Line;
>       
>          Put_Line("Finding shortest path from node 0 to node 6");
>          declare
>             use Ada.Exceptions;
>          begin
>             -- Compute Shortest Path
>             Path := SP.Shortest_Path
>                (EWG, Source => 0, Target => 6);
>             exception
>                when Error: others =>
>                   New_Line;
>                   Put_Line(Exception_Name(Error));
>                   Put_Line(Exception_Message(Error));
>                   New_Line;
>                   Return;
>          end;
>       
>          Put("The Shortest Path from Node 0 to Node 6 ");
>          Put("contains "); Put(Integer(Path.Length)); Put(" entries.");
>          -- Display path
>       end;
>    
>    
>    end;
> 
> end Main_Test;
> 
> And here's the test data (taken from Algorithms, by Sedwick):
> 
> 8
> 15
> 4 5 0.35
> 5 4 0.35
> 4 7 0.37
> 5 7 0.28
> 7 5 0.28
> 5 1 0.32
> 0 4 0.38
> 0 2 0.26
> 7 3 0.39
> 1 3 0.29
> 2 7 0.34
> 6 2 0.40
> 3 6 0.52
> 6 0 0.58
> 6 4 0.93

It is hard to comment without Ada units Shortest_Path and DirectedEdge posted. In other word, your code does not compile.

Anh Vo 

^ permalink raw reply	[relevance 0%]

* CONSTRAINT ERROR: erroneous memory access
@ 2020-06-06 23:40  1% jcupak
  2020-06-07 15:53  0% ` Anh Vo
  0 siblings, 1 reply; 200+ results
From: jcupak @ 2020-06-06 23:40 UTC (permalink / raw)


It has been a few years since I have written Ada; I used and taught Ada 95 back when I was working for a defense contractor. But, now that I'm retired, I wanted to get up to speed with Ada 2012, so I decided to implement a main program to see how the Shortest_Paths generic package works (taken from A.18.31, pages 574-576). But, when I read in the data and call the Shortest_Path function, it returns with CONSTRAINT ERROR: erroneous memory access. I've tried multiple times, but can't seem to figure out what I'm doing (or NOT doing) wrong. 

Here's the main program:

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO;   use Ada.Float_Text_IO;
with Ada.Text_IO;         use Ada.Text_IO;
with Shortest_Paths;
with Ada.Command_Line;    use Ada.Command_Line;
with DirectedEdge;        use DirectedEdge;
with Ada.Containers;      use Ada.Containers;
with Ada.Exceptions;

procedure Main_Test is

   Input_File : Ada.Text_IO.File_Type;

   Vertices   : Integer; -- Number of nodes
   Edges      : Integer; -- Number of paths

   Tail       : Integer; -- Node From
   Head       : Integer; -- Node To
   Weight     : Float;   -- Path Weight/Distance/Cost

   -- Instantiate Shortest Paths package with 0..Integer'Last subtype
   package SP is new Shortest_Paths(Node => Natural);
   
   -- Use Edge'Read to read the Edge components into Item
   
   -- Display directed edge components
   procedure Display(Edge : in SP.Edge) is
   begin
      Put(Edge.From, Width=>1); Put("->");
      Put(Edge.To,   Width=>1); Put(" ");
      Put(Float(Edge.Length), Fore => 0, Aft => 2, Exp => 0); Put(" ");
   end Display;

   -- Display directed edge components at cursor
   -- Replace List'Write with Display
   procedure Display(Cursor: in SP.Adjacency_Lists.Cursor)
   is
      Edge : SP.Edge := SP.Adjacency_Lists.Element(Cursor);
   begin
      Display(Edge); -- Let other procedure do all the work
   end Display;

begin

-- Open input file using arg 1
   Open (File => Input_File,
         Mode => In_File,
         Name => Argument(1)); -- ../tinyEWD.txt

   Set_Input(Input_File);        -- Redirect input
   New_Line;
   Put("Processing '"); Put(Argument(1)); Put_Line("'");

   -- Read number of nodes (vertices)
   Get(Vertices); New_Line;
   Put("Vertices: ");Put(Vertices, width=>2);New_Line;

   -- Read number of paths (edges)
   Get(Edges);
   Put("Edges:    ");Put(Edges, Width=>2);New_Line(2);

   declare
   
      -- Constrain Vertex to zero-based subrange
      subtype Vertex is Natural range 0..Vertices-1;
      
      -- Adj is DLL of Adjacency Lists for each Vertex
      Adj    : array (Vertex) of SP.Adjacency_Lists.List;
      
      -- Edge is a record of Tail, Head, and Weight components
      Edge   : SP.Edge;
   
   begin
   
      Put_Line("Creating Adjacency Lists"); New_Line;
   
      -- For each node, create empty list of adjacent nodes
      Create_Empty_Adjacency_Lists: for Node in Vertex loop
      
         -- Initialize each adjacency list to empty
         Adj(Node) := SP.Adjacency_Lists.Empty_List;
      
      end loop Create_Empty_Adjacency_Lists;
   
      -- Display and append new edge to adjacency list for node
      -- Constrain Edge index to natural subrange
      Append_New_Edge: for E in 0..Edges-1 loop
      
         Put("Edge:     ");Put(E, Width=>2);Put(" ");
      
         -- Get edge components from data file
         Get(Tail);   -- Tail
         Get(Head);   -- Head
         Get(Weight); -- Distance/Weight
      
         -- Set edge components
         Edge.From   := Tail;
         Edge.To     := Head;
         Edge.Length := SP.Distance(Weight);
      
         -- Display Edge
         Display(Edge);
         Put(" Appended to edge ");Put(Tail,1);
         New_Line;
      
         -- Append new edge to From adjacency list
         -- Indicating path to another node
         Adj(Edge.From).Append(Edge);
      
      end loop Append_New_Edge;
      New_Line;
   
      Close(Input_File);
      Set_Input(Standard_Input); -- Reset input source
   
      Put_Line("Node Adjacency Lists");
   
      -- Display contents of each adjacency list
      Display_Adjacency_Lists: for Node in Vertex loop
      
         Put("Adj[");Put(Node, Width=>1);Put("] ");
      
         declare
            Edges  : Ada.Containers.Count_Type;
         begin
         
            -- How many edges are in this node?
            Edges := SP.Adjacency_Lists.Length(Adj(Node));
            Put(Integer(Edges), Width => 1);
            if (Edges > 1) then
               Put(" Edges: ");
            else
               Put(" Edge:  ");
            end if;
         
            -- Iterate over all nodes in this adjacency list
            -- and Display each edge for each node
            SP.Adjacency_Lists.Iterate(Adj(Node), Process => Display'Access);
         
         end;
         New_Line;
      
      end loop Display_Adjacency_Lists;
      New_Line;
   
      -- Create Edge-Weighted Graph of Node and Adjacency List
      declare
         EWG    : SP.Graphs.Vector; -- Edge Weighted Graphs
         Path   : SP.Paths.List;    -- Shortest Path
      begin
      
         Put_Line("Creating Edge-Weighted Graphs.");
         EWG := SP.Graphs.Empty_Vector;
         Put_Line("EWG Empty_Vector created.");
         
         Put("Initializing Shortest Path to empty list...");
         Path := SP.Paths.Empty_List;
         Put_Line("done.");
         
         for Vertex in 0..Vertices-1 loop
            Put("Vertex: ");Put(Vertex, Width => 1);
            EWG.Append(Adj(Vertex));
            Put_Line(" appended to EWG.");
         end loop;
         New_Line;
         
         Put("EWG.Length = "); Put(Integer(EWG.Length), Width => 1);New_Line;
      
         Put_Line("Finding shortest path from node 0 to node 6");
         declare
            use Ada.Exceptions;
         begin
            -- Compute Shortest Path
            Path := SP.Shortest_Path
               (EWG, Source => 0, Target => 6);
            exception
               when Error: others =>
                  New_Line;
                  Put_Line(Exception_Name(Error));
                  Put_Line(Exception_Message(Error));
                  New_Line;
                  Return;
         end;
      
         Put("The Shortest Path from Node 0 to Node 6 ");
         Put("contains "); Put(Integer(Path.Length)); Put(" entries.");
         -- Display path
      end;
   
   
   end;

end Main_Test;

And here's the test data (taken from Algorithms, by Sedwick):

8
15
4 5 0.35
5 4 0.35
4 7 0.37
5 7 0.28
7 5 0.28
5 1 0.32
0 4 0.38
0 2 0.26
7 3 0.39
1 3 0.29
2 7 0.34
6 2 0.40
3 6 0.52
6 0 0.58
6 4 0.93

^ permalink raw reply	[relevance 1%]

* Re: Any good package for mathematical function in Ada?
  @ 2020-06-06 13:58  1%               ` AdaMagica
  0 siblings, 0 replies; 200+ results
From: AdaMagica @ 2020-06-06 13:58 UTC (permalink / raw)


Am Samstag, 6. Juni 2020 09:06:57 UTC+2 schrieb Dmitry A. Kazakov:
> No, it is the type system. Randy posted links to the drafts for 
> unbounded integer and real. Same story. They are not numbers. As a 
> consequence you have no conversions to/from legal numeric types, you 
> need to instantiate generics. They do not match formal numeric types in 
> generics. They have no attributes (some of which would have no sense 
> anyway).

GNAT CE 2020 has them (albeit not in the latest RM form). They behave much like numbers.

pragma Warnings (Off);
with Ada.Numerics.Big_Numbers.Big_Integers, Ada.Numerics.Big_Numbers.Big_Reals;
use  Ada.Numerics.Big_Numbers.Big_Integers, Ada.Numerics.Big_Numbers.Big_Reals;
pragma Warnings (On);

with Ada.Text_IO;
use  Ada.Text_IO;

procedure Main is

  I: Big_Integer := From_String ("   42   ");
  J: Big_Integer := 42;
  R: Big_Real := From_String("10.0")**100 - 1.0;
  S: Big_Real := 10.0**100 - 1/1;
  D: Big_Real := 1 / 3;

begin

  Put_Line (Boolean'(I=J)'Image);
  Put_Line (to_String (R));
  Put_Line (Boolean'Image(R=S));
  Put_Line (to_String (Numerator (S)) & to_String (Denominator (S)));
  Put_Line (to_String (D, Aft => 110));
  Put_Line (to_String (Numerator (D)) & to_String (Denominator (D)));

end Main;

^ permalink raw reply	[relevance 1%]

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-02  9:46  1% GNAT CE 2020 : error when using anon access to subprogram inside protected !? Jérôme Haguet
@ 2020-06-02 12:04  0% ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2020-06-02 12:04 UTC (permalink / raw)


Jérôme Haguet <j.haguet@cadwin.com> writes:

> When I start testing existing code with GNAT CE 2020, I faced a
> compilation error when using anonymous access to subprogram inside
> protected body.

> pb20200602.adb:27:18: subprogram "Do_On_Item" has wrong convention
> pb20200602.adb:27:18: does not match access to subprogram declared at line 7
>
>
> package Pb20200602 is
>    protected Tokens is 
>       procedure Call_Walker;    
>    end;
> end;
>
> --  ---------------------------------------------------------------------
> with Ada.Text_Io;
> package body Pb20200602 is
>
>    protected body Tokens is
>
>       procedure Walker
>         (On_Item : not null access procedure (Name    : String);
>          Success : out Boolean
>         )
>       is
>       begin
>          On_Item.all ("John Doe");
>          On_Item.all ("Jane Doe");
>          Success := True;
>       end;
>
>       procedure Call_Walker
>       is
>          procedure Do_On_Item (Name      : String)
>          is
>          begin
>             null;
>          end;
>          Success : Boolean := False;
>       begin
>          Walker (Do_On_Item'Access,
>                  Success);
>          if Success then
>             Ada.Text_Io.Put_Line ("Success!");
>          end if;
>       end;
>
>    end;
>
> end;

I'm amazed that you can declare Walker inside the PO!

CE 2020 will compile this without complaint if you move Walker outside
the PO.

^ permalink raw reply	[relevance 0%]

* GNAT CE 2020 : error when using anon access to subprogram inside protected !?
@ 2020-06-02  9:46  1% Jérôme Haguet
  2020-06-02 12:04  0% ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Jérôme Haguet @ 2020-06-02  9:46 UTC (permalink / raw)


Hello 

When I start testing existing code with GNAT CE 2020, I faced a compilation error when using anonymous access to subprogram inside protected body.

Maybe somebody can provide an explanation ...

Hereafter you will find the compiler message and (simplified) code that illustrates my problem 


pb20200602.adb:27:18: subprogram "Do_On_Item" has wrong convention
pb20200602.adb:27:18: does not match access to subprogram declared at line 7


package Pb20200602 is
   protected Tokens is 
      procedure Call_Walker;    
   end;
end;

--  ---------------------------------------------------------------------
with Ada.Text_Io;
package body Pb20200602 is

   protected body Tokens is

      procedure Walker
        (On_Item : not null access procedure (Name    : String);
         Success : out Boolean
        )
      is
      begin
         On_Item.all ("John Doe");
         On_Item.all ("Jane Doe");
         Success := True;
      end;

      procedure Call_Walker
      is
         procedure Do_On_Item (Name      : String)
         is
         begin
            null;
         end;
         Success : Boolean := False;
      begin
         Walker (Do_On_Item'Access,
                 Success);
         if Success then
            Ada.Text_Io.Put_Line ("Success!");
         end if;
      end;

   end;

end;




^ permalink raw reply	[relevance 1%]

* Re: Any good package for mathematical function in Ada?
  @ 2020-06-01 10:19  1%     ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2020-06-01 10:19 UTC (permalink / raw)


On 01/06/2020 10:24, reinert wrote:

> Anybody having a simple (complete - runable) code example using GSL from Ada?

Assuming Windows.

Install MSYS2 if you did not already. [64-bit, GNAT GPL is not available 
for 32-bit anymore.]

Install GSL mingw-w64-x86_64-gsl under MSYS.

Now, assuming that MSYS2 is under C:\MSYS64\MinGW, here you go:

---gsl.gpr--------------
project GSL is
    for Main use ("test.adb");

    package Linker is
       for Default_Switches ("ada")
          use ("-L/c/msys64/mingw/lib", "-lgsl");
    end Linker;

end GSL;

---gsl.ads-------------
with Interfaces.C;  use Interfaces.C;

package GSL is
   function Bessel_J0 (X : double) return double;

private
    pragma Import (C, Bessel_J0, "gsl_sf_bessel_J0");
end GSL;

---test.adb------------>
with Ada.Text_IO;   use Ada.Text_IO;
with GSL;           use GSL;
with Interfaces.C;  use Interfaces.C;

procedure Test is
begin
    Put_Line ("J0(1)=" & double'Image (Bessel_J0 (1.0)));
end Test;
-----------------------

The test produces:

J0(1)= 7.65197686557967E-01

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

^ permalink raw reply	[relevance 1%]

* Re: Getting the 3 letter time zone abbreviation
  @ 2020-04-30 21:11  1%         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2020-04-30 21:11 UTC (permalink / raw)


On 2020-04-30 20:59, Bob Goddard wrote:
> On Wednesday, 29 April 2020 20:53:11 UTC+1, Dmitry A. Kazakov  wrote:
>> On 2020-04-29 21:20, Bob Goddard wrote:
>>
>>> Seems easier just to import strftime and call it requesting just "%Z". This is on Linux, but MS suggests it should also work on Windows.
>>
>> An interesting idea. Did you try it under Windows? (There is a
>> suspicious remark that it depends on the setlocale)
> 
> 'Fraid not, I'm a Linux user. I just noticed that Windows does have it.

OK, I tested it. As expected it does not work. For example this one:
---------------------------
with Ada.Command_Line;           use Ada.Command_Line;
with Interfaces.C;               use Interfaces.C;
with Ada.Exceptions;             use Ada.Exceptions;
with Ada.Text_IO;                use Ada.Text_IO;

with System;

procedure Strftime_Test is

    type tm is record
       tm_sec   : int;
       tm_min   : int;
       tm_hour  : int;
       tm_mday  : int;
       tm_mon   : int;
       tm_year  : int;
       tm_wday  : int;
       tm_yday  : int;
       tm_isdst : int;
    end record;
    pragma Convention (C, tm);
    type tm_Ptr is access all tm;
    pragma Convention (C, tm_Ptr);

    type time_t is new Interfaces.Unsigned_64;

    function localtime (timep : access time_t) return tm_Ptr;
    pragma Import (C, localtime);

    function time (destTime : System.Address := System.Null_Address)
       return time_t;
    pragma Import (C, time, "_time64");

    function strftime
             (  strDest : char_array;
                maxsize : size_t;
                format  : char_array;
                timeptr : access tm
             )  return size_t;
    pragma Import (C, strftime);

    Result    : size_t;
    Buffer    : char_array (1..200);
    Now       : aliased time_t := 0;
    Local_Ptr : tm_Ptr;
begin
    Now := time;
    Put_Line ("Time=" & time_t'Image (Now));
    Local_Ptr := localtime (Now'Access);
    if Local_Ptr /= null then
       declare
          Local : tm renames localtime (Now'Access).all;
       begin
          Put_Line
          (  int'Image (Local.tm_year)
          &  " -"
          &  int'Image (Local.tm_mon)
          &  " -"
          &  int'Image (Local.tm_mday)
          &  " "
          &  int'Image (Local.tm_hour)
          &  " :"
          &  int'Image (Local.tm_min)
          &  " :"
          &  int'Image (Local.tm_sec)
          );
          Result := strftime
                    (  Buffer,
                       Buffer'Length,
                       To_C ("%#Z"),
                       Local'Access
                    );
          Put_Line ("Result=" & To_Ada (Buffer (1..Result), False));
       end;
    end if;
    Set_Exit_Status (0);
exception
    when Error : Status_Error | Data_Error =>
       Put_Line (Exception_Message (Error));
       Set_Exit_Status (1);
    when Error : others =>
       Put_Line ("Fault: " & Exception_Information (Error));
       Set_Exit_Status (2);
end Strftime_Test;
----------------------------------

Gives the output on my Windows machine:

    Result=W. Europe Daylight Time

instead of

    CEST

Windows POSIX layer relies on Windows API. If the API does something 
wrong, so would whatever POSIX function.

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

^ permalink raw reply	[relevance 1%]

* Re: GNAT CE 2019 bug: Predicate check not performed
  2020-04-19 22:31  0% ` Anh Vo
@ 2020-04-19 22:32  0%   ` Anh Vo
  0 siblings, 0 replies; 200+ results
From: Anh Vo @ 2020-04-19 22:32 UTC (permalink / raw)


On Sunday, April 19, 2020 at 3:31:15 PM UTC-7, Anh Vo wrote:
> On Sunday, April 19, 2020 at 2:28:18 AM UTC-7, AdaMagica wrote:
> > The problem is with GNAT CE 2019.
> > GNAT CE 2018 was correct.
> > ------------------------------------------------
> > with Ada.Text_IO;
> > use  Ada.Text_IO;
> > with Ada.Assertions;
> > use  Ada.Assertions;
> > 
> > procedure Ass is
> > 
> >   pragma Assertion_Policy (Check);
> > 
> >   subtype String_5 is String with Dynamic_Predicate => String_5'First = 5;
> > 
> >   procedure P (X: String_5) is
> >   begin
> >     Put_Line ("P expects 5:" & X'First'Image);
> >   end P;
> > 
> >   procedure Q (X: String) is
> >   begin
> >     P (X);  -- Why no predicate check here?
> >   end Q;
> > 
> >   S: constant String := "Lady Ada";
> > 
> > begin
> > 
> >   begin
> >     Q (S);  -- prints 1, expected Assertion_Error
> >     Put_Line ("Problem Q: Assertion_Error not raised.");
> >   exception
> >     when Assertion_Error => Put_Line ("Q: Assertion_Error raised as expected.");
> >   end;
> > 
> >   begin
> >     P (S);  -- Assertion_Error raised here
> >     Put_Line ("Problem P: Assertion_Error not raised.");
> >   exception
> >     when Assertion_Error => Put_Line ("P: Assertion_Error raised as expected.");
> >   end;
> > 
> > end Ass;
> > ---------------------
> > Result GNAT CE 2018
> > C:\Users\Grein\Documents\Christoph\Ada\Spielplatz\ausprobieren.exe
> > Q: Assertion_Error raised as expected.
> > P: Assertion_Error raised as expected.
> > [2020-04-18 19:33:34] process terminated successfully, elapsed time: 07.47s
> > Result GNAT CE 2019
> > C:\Users\Grein\Documents\Christoph\Ada\Spielplatz\ausprobieren.exe
> > P expects 5: 1
> > Problem Q: Assertion_Error not raised.
> > P: Assertion_Error raised as expected.
> > [2020-04-18 19:58:20] process terminated successfully, elapsed time: 04.25s
> 
> It takes time to look thru the LRM to if this behavior is expected or not. However if String_5 is changed to type and lines 19 and 34 are adjusted for compilation, then it behaves as in GNAT CE 2018. By the way, GNAT Community 2019 on Windows 10 is for this check.

It takes time to look thru the LRM to see if...

^ permalink raw reply	[relevance 0%]

* Re: GNAT CE 2019 bug: Predicate check not performed
  2020-04-19  9:28  1% GNAT CE 2019 bug: Predicate check not performed AdaMagica
@ 2020-04-19 22:31  0% ` Anh Vo
  2020-04-19 22:32  0%   ` Anh Vo
  0 siblings, 1 reply; 200+ results
From: Anh Vo @ 2020-04-19 22:31 UTC (permalink / raw)


On Sunday, April 19, 2020 at 2:28:18 AM UTC-7, AdaMagica wrote:
> The problem is with GNAT CE 2019.
> GNAT CE 2018 was correct.
> ------------------------------------------------
> with Ada.Text_IO;
> use  Ada.Text_IO;
> with Ada.Assertions;
> use  Ada.Assertions;
> 
> procedure Ass is
> 
>   pragma Assertion_Policy (Check);
> 
>   subtype String_5 is String with Dynamic_Predicate => String_5'First = 5;
> 
>   procedure P (X: String_5) is
>   begin
>     Put_Line ("P expects 5:" & X'First'Image);
>   end P;
> 
>   procedure Q (X: String) is
>   begin
>     P (X);  -- Why no predicate check here?
>   end Q;
> 
>   S: constant String := "Lady Ada";
> 
> begin
> 
>   begin
>     Q (S);  -- prints 1, expected Assertion_Error
>     Put_Line ("Problem Q: Assertion_Error not raised.");
>   exception
>     when Assertion_Error => Put_Line ("Q: Assertion_Error raised as expected.");
>   end;
> 
>   begin
>     P (S);  -- Assertion_Error raised here
>     Put_Line ("Problem P: Assertion_Error not raised.");
>   exception
>     when Assertion_Error => Put_Line ("P: Assertion_Error raised as expected.");
>   end;
> 
> end Ass;
> ---------------------
> Result GNAT CE 2018
> C:\Users\Grein\Documents\Christoph\Ada\Spielplatz\ausprobieren.exe
> Q: Assertion_Error raised as expected.
> P: Assertion_Error raised as expected.
> [2020-04-18 19:33:34] process terminated successfully, elapsed time: 07.47s
> Result GNAT CE 2019
> C:\Users\Grein\Documents\Christoph\Ada\Spielplatz\ausprobieren.exe
> P expects 5: 1
> Problem Q: Assertion_Error not raised.
> P: Assertion_Error raised as expected.
> [2020-04-18 19:58:20] process terminated successfully, elapsed time: 04.25s

It takes time to look thru the LRM to if this behavior is expected or not. However if String_5 is changed to type and lines 19 and 34 are adjusted for compilation, then it behaves as in GNAT CE 2018. By the way, GNAT Community 2019 on Windows 10 is for this check.

^ permalink raw reply	[relevance 0%]

* GNAT CE 2019 bug: Predicate check not performed
@ 2020-04-19  9:28  1% AdaMagica
  2020-04-19 22:31  0% ` Anh Vo
  0 siblings, 1 reply; 200+ results
From: AdaMagica @ 2020-04-19  9:28 UTC (permalink / raw)


The problem is with GNAT CE 2019.
GNAT CE 2018 was correct.
------------------------------------------------
with Ada.Text_IO;
use  Ada.Text_IO;
with Ada.Assertions;
use  Ada.Assertions;

procedure Ass is

  pragma Assertion_Policy (Check);

  subtype String_5 is String with Dynamic_Predicate => String_5'First = 5;

  procedure P (X: String_5) is
  begin
    Put_Line ("P expects 5:" & X'First'Image);
  end P;

  procedure Q (X: String) is
  begin
    P (X);  -- Why no predicate check here?
  end Q;

  S: constant String := "Lady Ada";

begin

  begin
    Q (S);  -- prints 1, expected Assertion_Error
    Put_Line ("Problem Q: Assertion_Error not raised.");
  exception
    when Assertion_Error => Put_Line ("Q: Assertion_Error raised as expected.");
  end;

  begin
    P (S);  -- Assertion_Error raised here
    Put_Line ("Problem P: Assertion_Error not raised.");
  exception
    when Assertion_Error => Put_Line ("P: Assertion_Error raised as expected.");
  end;

end Ass;
---------------------
Result GNAT CE 2018
C:\Users\Grein\Documents\Christoph\Ada\Spielplatz\ausprobieren.exe
Q: Assertion_Error raised as expected.
P: Assertion_Error raised as expected.
[2020-04-18 19:33:34] process terminated successfully, elapsed time: 07.47s
Result GNAT CE 2019
C:\Users\Grein\Documents\Christoph\Ada\Spielplatz\ausprobieren.exe
P expects 5: 1
Problem Q: Assertion_Error not raised.
P: Assertion_Error raised as expected.
[2020-04-18 19:58:20] process terminated successfully, elapsed time: 04.25s

^ permalink raw reply	[relevance 1%]

* Re: Put the access value
  @ 2020-04-15  7:20  1%     ` briot.emmanuel
  0 siblings, 0 replies; 200+ results
From: briot.emmanuel @ 2020-04-15  7:20 UTC (permalink / raw)



The approach I tend to use is using `System.Address_Image`:


   El  : Buffer_Pointer := LastBuffer; 
   ...

   if El /= null then
      Ada.Text_IO.Put_Line (System.Address_Image (El.all'Address));
   end if;

or if this is for slightly longer term

   function Convert is new Ada.Unchecked_Conversion
     (Buffer_Pointer, System.Address);
   Ada.Text_IO.Put_Line (System.Address_Image (Convert (El));

This is really just for quick debugging, and the code is never (really, I swear) committed... Otherwise, I would go to the trouble of creating an `Image` function and use that

^ permalink raw reply	[relevance 1%]

* Re: Using Generic Pasckages
  @ 2020-04-09 20:45  1% ` Jere
  0 siblings, 0 replies; 200+ results
From: Jere @ 2020-04-09 20:45 UTC (permalink / raw)


On Thursday, April 9, 2020 at 4:40:11 AM UTC-4, ldries46 wrote:
> I have created some generic packages. tese are packages that only do the 
> same thing but with other types. Till now I did only need these packages 
> without interaction with between packages using the same type. I just 
> can declare them:
> Package AA is new BB(type); then calling them as
> A := AA.Get_Value;
> No other declaration seemed to be neccesary .
> 
> Now I have the following situation:
> Package AA is new BB(integer);
> Package CC is new BB(integer);
> and a case where I have several statements using Package AA in one 
> condition and CC the other case.
> I want  to do that by using:
> if D then EE := AA; else EE := CC; end if;
> But I cannot find in the documentation  how the declaration of EE should 
> be made.
> 
> Of course there is the possibility to create the same progrram without 
> using EE but that is far less readable and thus creating more possible 
> errors.
> 
> If I have to do this without the generic packages I already have the 
> program alse will be less readable.

You've already had suggestions for polymorphism or using if/else 
scaffolding.  For run time decisions like this, if both packages
are using the same types, I would recommend polymorphism.  However
if you prefer to stick with generics, you make the scaffolding a bit
less painful by using another generic.  Assuming your generic BB has
a specification like this:

    generic
        type Some_Type is private;
    package BB is
        procedure Set_Value(V : Some_Type);
        function Get_Value return Some_Type;
    end BB;

You can abstract out all your logic using it with another generic
similar to:

    generic
        with package EE is new BB(Some_Type => Integer);
    procedure Do_Stuff;
    
    procedure Do_Stuff is
    
        V : Integer := 23;
    
    begin
        Put_Line(Integer'Image(EE.Get_Value));
        EE.Set_Value(V);
        Put_Line(Integer'Image(EE.Get_Value));
        
        -- All your other BB logic you want to do

    end Do_Stuff;

then you pair it with the if/else or case structure 
and locally declared blocks:

    Put_Line("Hello, world!");
    AA.Set_Value(10);
    CC.Set_Value(20);
  
    if D then 
        declare
            procedure P is new Do_Stuff(AA);
        begin
            P;
        end;
    else
        declare
            procedure P is new Do_Stuff(CC);
        begin
            P;
        end;
    end if;

It still has some scaffolding, but it is more 
readable then tons of if/else blocks scattered
throughout the code.  If your packages don't 
have to rely on Integer, you can change the 
specification to:

    generic
        with package EE is new BB(<>);
    procedure Do_Stuff;

But if your logic actually does rely on knowing
it is an integer type, you will get compiler errors.

Full compilable example below:

with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
    
    generic
        type Some_Type is private;
    package BB is
        procedure Set_Value(V : Some_Type);
        function Get_Value return Some_Type;
    end BB;
    
    package body BB is
        Value : Some_Type;
        
        procedure Set_Value(V : Some_Type) is
        begin
            Value := V;
        end Set_Value;
        
        function Get_Value return Some_Type is (Value);
    end BB;
    
    package AA is new BB(Integer);
    package CC is new BB(Integer);
    
    generic
        with package EE is new BB(<>);
    procedure Do_Stuff_1;
    
    procedure Do_Stuff_1 is
    
        V : EE.Some_Type := EE.Get_Value;
    
    begin
        EE.Set_Value(V);
    end Do_Stuff_1;
    
    generic
        with package EE is new BB(Some_Type => Integer);
    procedure Do_Stuff_2;
    
    procedure Do_Stuff_2 is
    
        V : Integer := 23;
    
    begin
        Put_Line(Integer'Image(EE.Get_Value));
        EE.Set_Value(V);
        Put_Line(Integer'Image(EE.Get_Value));
    end Do_Stuff_2;
    
    D : Boolean := True;

begin
    Put_Line("Hello, world!");
    AA.Set_Value(10);
    CC.Set_Value(20);
  
    if D then 
        declare
            procedure P is new Do_Stuff_2(AA);
        begin
            P;
        end;
    else
        declare
            procedure P is new Do_Stuff_2(CC);
        begin
            P;
        end;
    end if;
  
end Hello;

^ permalink raw reply	[relevance 1%]

* Re: Simple parse from https website
  2020-04-02 17:16  1%     ` Dmitry A. Kazakov
@ 2020-04-02 18:27  0%       ` Rego, P.
  0 siblings, 0 replies; 200+ results
From: Rego, P. @ 2020-04-02 18:27 UTC (permalink / raw)


> No, that site looks OK. I modified my OpenSSL HTTP client. I just added 
> JSON parser and procedure Dump to print the JSON object:
> 
> ----------------------------- test_https_openssl_json_client.adb -----
> with Ada.Exceptions;               use Ada.Exceptions;
> with Ada.Text_IO;                  use Ada.Text_IO;
> with Ada.Streams;                  use Ada.Streams;
> --with GNAT.Exception_Traces;      use GNAT.Exception_Traces;
> with GNAT.Sockets.Server.Handles;  use GNAT.Sockets.Server.Handles;
> with GNAT.Sockets.Server.OpenSSL;  use GNAT.Sockets.Server.OpenSSL;
> with OpenSSL;                      use OpenSSL;
> with Parsers.JSON;                 use Parsers.JSON;
> with Parsers.JSON.String_Source;   use Parsers.JSON.String_Source;
> with Strings_Edit.Integers;        use Strings_Edit.Integers;
> with Strings_Edit.Quoted;          use Strings_Edit.Quoted;
> with Strings_Edit.Streams;         use Strings_Edit.Streams;
> with Strings_Edit.Long_Floats;     use Strings_Edit.Long_Floats;
> with Test_HTTP_Servers.OpenSSL;    use Test_HTTP_Servers.OpenSSL;
> 
> with GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;
> with GNAT.Sockets.Server.Pooled;
> with Parsers.String_Source;
> with Stack_Storage;
> 
> procedure Test_HTTPS_OpenSSL_JSON_Client is
>     use GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;
> 
>     Address : constant String := "poloniex.com";
>     Path    : constant String := "public?command=returnTicker";
>     Port    : constant := 443;
> 
>     procedure Dump (Prefix : String; Value : JSON_Value) is
>     begin
>        case Value.JSON_Type is
>           when JSON_Boolean =>
>              Put_Line (Prefix & Boolean'Image (Value.Condition));
>           when JSON_Null =>
>              Put_Line (Prefix & "null");
>           when JSON_Number =>
>              Put_Line (Prefix & Image (Value.Value));
>           when JSON_String =>
>              Put_Line (Prefix & Quote (Value.Text.all));
>           when JSON_Array =>
>              Put_Line (Prefix & "(");
>              for Index in Value.Sequence'Range loop
>                 Dump (Prefix & "   ", Value.Sequence (Index));
>              end loop;
>              Put_Line (Prefix & ")");
>           when JSON_Object =>
>              Put_Line (Prefix & "{");
>              for Index in Value.Map'Range loop
>                 Put_Line (Prefix & "   " & Value.Map (Index).Name.all & 
> "=");
>                 Dump (Prefix & "      ", Value.Map (Index).Value);
>              end loop;
>              Put_Line (Prefix & "}");
>        end case;
>     end Dump;
> begin
>     declare
>        Factory : aliased HTTPS_OpenSSL_Factory
>                          (  Request_Length  => 200,
>                             Input_Size      => 40,
>                             Output_Size     => 1024,
>                             Decoded_Size    => 40,
>                             Max_Connections => 100
>                          );
>     begin
>        Set_Default_Verify_Paths (Factory, Client_Context);
>        declare
>           Message   : aliased String_Stream (1024 * 100);
>           Server    : aliased GNAT.Sockets.Server.
>                               Connections_Server (Factory'Access, 0);
>           Reference : GNAT.Sockets.Server.Handles.Handle;
>        begin
>           Put_Line ("HTTP client started");
>           Set
>           (  Reference,
>              new HTTP_Session_Signaled
>                  (  Server'Unchecked_Access,
>                     200,
>                     512,
>                     1024
>           )      );
>           declare
>              Client : HTTP_Session_Signaled renames
>                       HTTP_Session_Signaled (Ptr (Reference).all);
>           begin
>              Connect (Client, Address, Port);
>              Get
>              (  Client,
>                 "https://" & Address & "/" & Path,
>                 Message'Unchecked_Access
>              );
>              Wait (Client, False);
>              Put_Line
>              (  Image (Get_Response_Code (Client))
>              &  " "
>              &  Get_Response_Reason (Client)
>              &  " Message >>>>>>>>>>>>>>>>>>>>"
>              );
>              declare
>                 Content : aliased String := Get (Message);
>                 Source  : aliased Parsers.String_Source.
>                                   Source (Content'Access);
>                 Arena   : aliased Stack_Storage.Pool (1024, 10);
>                 Data    : constant JSON_Value :=
>                                    Parse (Source'Access, Arena'Access);
>              begin
>                 Dump ("", Data);
>              end;
>              Put_Line ("<<<<<<<<<<<<<<<<<<<< Message");
>           end;
>           Put_Line ("HTTP client stopping");
>        end;
>     end;
> exception
>     when Error : others =>
>        Put_Line ("Error: " & Exception_Information (Error));
> end Test_HTTPS_OpenSSL_JSON_Client;
> ----------------------------- test_https_openssl_json_client.adb -----
> 
> It connects fine and spills lots of garbage like:
> 
>    ...
>     USDT_SNX=
>        {
>           id=
>              290.9999999999999
>           last=
>              "0.00000000"
>           lowestAsk=
>              "0.00000000"
>           highestBid=
>              "0.00000000"
>           percentChange=
>              "0.00000000"
>           baseVolume=
>              "0.00000000"
>           quoteVolume=
>              "0.00000000"
>           isFrozen=
>              "0"
>           high24hr=
>              "0.00000000"
>           low24hr=
>              "0.00000000"
>        }
>     TRX_SNX=
>        {
>           id=
>              292.0000000000000
>           last=
>              "0.00000000"
>           lowestAsk=
>              "0.00000000"
>           highestBid=
>              "0.00000000"
>           percentChange=
>              "0.00000000"
>      ...
> 
> and so on. Funny enough, they put numbers as strings, so it seems.
> 
> It is not very efficient as written. You see, the code it accumulates 
> all response in a string stream buffer. Then takes a string from that. 
> Then it parses the obtained string into a JSON object. So it is two 
> copies too many. One could parse the response on the fly without 
> accumulating it whole in the memory. But it would mean more efforts.

Omg... (almost) Perfect(!lol)...just discovered that GNAT.Sockets has a signature change, some subpackages are no more exposed (like GNAT.SOCKETS.Server). I am using GNAT Community 2019.

Builder results
        17:6 file "g-scstma.ads" not found
        6:6 file "g-socser.ads" not found
        7:6 file "g-socser.ads" not found
        18:6 file "g-socser.ads" not found
        8:6 file "openssl.ads" not found
        9:6 file "parsers.ads" not found
        10:6 file "parsers.ads" not found
        19:6 file "parsers.ads" not found
        20:6 file "stack_storage.ads" not found
        11:6 file "strings_edit.ads" not found
        12:6 file "strings_edit.ads" not found
        13:6 file "strings_edit.ads" not found
        14:6 file "strings_edit.ads" not found
        15:6 file "test_http_servers.ads" not found


^ permalink raw reply	[relevance 0%]

* Re: Simple parse from https website
  @ 2020-04-02 17:16  1%     ` Dmitry A. Kazakov
  2020-04-02 18:27  0%       ` Rego, P.
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2020-04-02 17:16 UTC (permalink / raw)


On 2020-04-02 16:48, Rego, P. wrote:

> Ops...not, just testing more simpler cases. I am trying to get the data from
> https://poloniex.com/public?command=returnTicker
> 
> Just tried with google to check if it's problem from polo ticker. But the exception was the same.

No, that site looks OK. I modified my OpenSSL HTTP client. I just added 
JSON parser and procedure Dump to print the JSON object:

----------------------------- test_https_openssl_json_client.adb -----
with Ada.Exceptions;               use Ada.Exceptions;
with Ada.Text_IO;                  use Ada.Text_IO;
with Ada.Streams;                  use Ada.Streams;
--with GNAT.Exception_Traces;      use GNAT.Exception_Traces;
with GNAT.Sockets.Server.Handles;  use GNAT.Sockets.Server.Handles;
with GNAT.Sockets.Server.OpenSSL;  use GNAT.Sockets.Server.OpenSSL;
with OpenSSL;                      use OpenSSL;
with Parsers.JSON;                 use Parsers.JSON;
with Parsers.JSON.String_Source;   use Parsers.JSON.String_Source;
with Strings_Edit.Integers;        use Strings_Edit.Integers;
with Strings_Edit.Quoted;          use Strings_Edit.Quoted;
with Strings_Edit.Streams;         use Strings_Edit.Streams;
with Strings_Edit.Long_Floats;     use Strings_Edit.Long_Floats;
with Test_HTTP_Servers.OpenSSL;    use Test_HTTP_Servers.OpenSSL;

with GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;
with GNAT.Sockets.Server.Pooled;
with Parsers.String_Source;
with Stack_Storage;

procedure Test_HTTPS_OpenSSL_JSON_Client is
    use GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;

    Address : constant String := "poloniex.com";
    Path    : constant String := "public?command=returnTicker";
    Port    : constant := 443;

    procedure Dump (Prefix : String; Value : JSON_Value) is
    begin
       case Value.JSON_Type is
          when JSON_Boolean =>
             Put_Line (Prefix & Boolean'Image (Value.Condition));
          when JSON_Null =>
             Put_Line (Prefix & "null");
          when JSON_Number =>
             Put_Line (Prefix & Image (Value.Value));
          when JSON_String =>
             Put_Line (Prefix & Quote (Value.Text.all));
          when JSON_Array =>
             Put_Line (Prefix & "(");
             for Index in Value.Sequence'Range loop
                Dump (Prefix & "   ", Value.Sequence (Index));
             end loop;
             Put_Line (Prefix & ")");
          when JSON_Object =>
             Put_Line (Prefix & "{");
             for Index in Value.Map'Range loop
                Put_Line (Prefix & "   " & Value.Map (Index).Name.all & 
"=");
                Dump (Prefix & "      ", Value.Map (Index).Value);
             end loop;
             Put_Line (Prefix & "}");
       end case;
    end Dump;
begin
    declare
       Factory : aliased HTTPS_OpenSSL_Factory
                         (  Request_Length  => 200,
                            Input_Size      => 40,
                            Output_Size     => 1024,
                            Decoded_Size    => 40,
                            Max_Connections => 100
                         );
    begin
       Set_Default_Verify_Paths (Factory, Client_Context);
       declare
          Message   : aliased String_Stream (1024 * 100);
          Server    : aliased GNAT.Sockets.Server.
                              Connections_Server (Factory'Access, 0);
          Reference : GNAT.Sockets.Server.Handles.Handle;
       begin
          Put_Line ("HTTP client started");
          Set
          (  Reference,
             new HTTP_Session_Signaled
                 (  Server'Unchecked_Access,
                    200,
                    512,
                    1024
          )      );
          declare
             Client : HTTP_Session_Signaled renames
                      HTTP_Session_Signaled (Ptr (Reference).all);
          begin
             Connect (Client, Address, Port);
             Get
             (  Client,
                "https://" & Address & "/" & Path,
                Message'Unchecked_Access
             );
             Wait (Client, False);
             Put_Line
             (  Image (Get_Response_Code (Client))
             &  " "
             &  Get_Response_Reason (Client)
             &  " Message >>>>>>>>>>>>>>>>>>>>"
             );
             declare
                Content : aliased String := Get (Message);
                Source  : aliased Parsers.String_Source.
                                  Source (Content'Access);
                Arena   : aliased Stack_Storage.Pool (1024, 10);
                Data    : constant JSON_Value :=
                                   Parse (Source'Access, Arena'Access);
             begin
                Dump ("", Data);
             end;
             Put_Line ("<<<<<<<<<<<<<<<<<<<< Message");
          end;
          Put_Line ("HTTP client stopping");
       end;
    end;
exception
    when Error : others =>
       Put_Line ("Error: " & Exception_Information (Error));
end Test_HTTPS_OpenSSL_JSON_Client;
----------------------------- test_https_openssl_json_client.adb -----

It connects fine and spills lots of garbage like:

   ...
    USDT_SNX=
       {
          id=
             290.9999999999999
          last=
             "0.00000000"
          lowestAsk=
             "0.00000000"
          highestBid=
             "0.00000000"
          percentChange=
             "0.00000000"
          baseVolume=
             "0.00000000"
          quoteVolume=
             "0.00000000"
          isFrozen=
             "0"
          high24hr=
             "0.00000000"
          low24hr=
             "0.00000000"
       }
    TRX_SNX=
       {
          id=
             292.0000000000000
          last=
             "0.00000000"
          lowestAsk=
             "0.00000000"
          highestBid=
             "0.00000000"
          percentChange=
             "0.00000000"
     ...

and so on. Funny enough, they put numbers as strings, so it seems.

It is not very efficient as written. You see, the code it accumulates 
all response in a string stream buffer. Then takes a string from that. 
Then it parses the obtained string into a JSON object. So it is two 
copies too many. One could parse the response on the fly without 
accumulating it whole in the memory. But it would mean more efforts.

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

^ permalink raw reply	[relevance 1%]

* Re: Simple parse from https website
  2020-04-02 13:58  1% Simple parse from https website Rego, P.
@ 2020-04-02 14:42  0% ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2020-04-02 14:42 UTC (permalink / raw)


On 2020-04-02 15:58, Rego, P. wrote:

> I am trying to make a simple parser for an https website push, so trying to follow from the example from http://rosettacode.org/wiki/HTTP#Ada, just changing the address from a website.
> 
> So I  tried
> 
>      with Ada.Text_IO; use Ada.Text_IO;
>      
>      with AWS.Client;
>      with AWS.Response;
>      
>      procedure Main_Other is
>      begin
>         Put_Line (AWS.Response.Message_Body
>                   (AWS.Client.Get
>                      (URL => "https://google.com")));
>      end Main_Other;
> 
> But I got an exception
> raised PROGRAM_ERROR : aws-client.adb:398 finalize/adjust raised exception
> [2020-04-02 10:41:20] process exited with status 1, elapsed time: 00.80s
> 
> So, any thoughts on how to fix that?

This is certainly an induced error. You get some exception which 
propagates on and upon finalization of an AWS object (AWS Client?) 
causes another exception inside its Finalize. I suggest you to report it 
to AdaCore, as this is surely a bug.

As for the original error, like another poster guessed, you seem try to 
establish an insecure connection (HTTP) to a secure server (HTTPS), get 
bounced and then, see above.

You need to configure OpenSSL or GNUTLS for you AWS client before 
connecting. I cannot help with details because I don't use AWS. There 
should be some samples of secure HTTP connection using an AWS client.

> I'd like to parse the current status of some tables in a website, similar of making something like that in Python
> 
>      import pandas as pd
>      def retrieve_json(json_url):
>          return pd.read_json(json_url)

Hmm, google.com content does not look like JSON, far from. Though they 
may have REST API in JSON format, is that you are trying to do?

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

^ permalink raw reply	[relevance 0%]

* Simple parse from https website
@ 2020-04-02 13:58  1% Rego, P.
  2020-04-02 14:42  0% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Rego, P. @ 2020-04-02 13:58 UTC (permalink / raw)


Hi folks, how are you? I hope everyone is safe and healthy.

I am trying to make a simple parser for an https website push, so trying to follow from the example from http://rosettacode.org/wiki/HTTP#Ada, just changing the address from a website.

So I  tried 

    with Ada.Text_IO; use Ada.Text_IO;
    
    with AWS.Client;
    with AWS.Response;
    
    procedure Main_Other is
    begin
       Put_Line (AWS.Response.Message_Body
                 (AWS.Client.Get
                    (URL => "https://google.com")));
    end Main_Other;

But I got an exception
raised PROGRAM_ERROR : aws-client.adb:398 finalize/adjust raised exception
[2020-04-02 10:41:20] process exited with status 1, elapsed time: 00.80s

So, any thoughts on how to fix that? 

I'd like to parse the current status of some tables in a website, similar of making something like that in Python

    import pandas as pd
    def retrieve_json(json_url):
        return pd.read_json(json_url)


Thanks
Pablo.

^ permalink raw reply	[relevance 1%]

* Re: How do I resolve SPARK warning "procedure [...] has no effect for output procedure
  2020-03-26 13:13  1%         ` Egil H H
@ 2020-03-27  0:05  0%           ` digitig
  0 siblings, 0 replies; 200+ results
From: digitig @ 2020-03-27  0:05 UTC (permalink / raw)


On Thursday, March 26, 2020 at 1:13:10 PM UTC, Egil H H wrote:
> On Thursday, March 26, 2020 at 12:56:04 PM UTC+1, digitig wrote:
> > 
> > I've found out how in older versions of SPARK I could annotate the procedure to say that it modified global outputs, but that depended on SPARK_Io, and the documentation on that says it has been replaced and I can't find either it or its replacement - the current SPARK documentation doesn't seem to mention either.
> 
> In recent versions of GNAT, Ada.Text_IO includes SPARK aspects, like Global, so I guess that's the replacement for SPARK_IO you're looking for.

As simple as that! The thing I was looking for I had all along! Thanks, that's what I needed.

^ permalink raw reply	[relevance 0%]

* Re: How do I resolve SPARK warning "procedure [...] has no effect for output procedure
  @ 2020-03-26 13:13  1%         ` Egil H H
  2020-03-27  0:05  0%           ` digitig
  0 siblings, 1 reply; 200+ results
From: Egil H H @ 2020-03-26 13:13 UTC (permalink / raw)


On Thursday, March 26, 2020 at 12:56:04 PM UTC+1, digitig wrote:
> 
> I've found out how in older versions of SPARK I could annotate the procedure to say that it modified global outputs, but that depended on SPARK_Io, and the documentation on that says it has been replaced and I can't find either it or its replacement - the current SPARK documentation doesn't seem to mention either.

In recent versions of GNAT, Ada.Text_IO includes SPARK aspects, like Global, so I guess that's the replacement for SPARK_IO you're looking for.

^ permalink raw reply	[relevance 1%]

* Re: How do I resolve SPARK warning "procedure [...] has no effect for output procedure
  @ 2020-03-26  0:45  1%   ` digitig
    0 siblings, 1 reply; 200+ results
From: digitig @ 2020-03-26  0:45 UTC (permalink / raw)


On Wednesday, March 25, 2020 at 11:38:06 PM UTC, Anh Vo wrote:
> Would you mind to post the source code and the warning message. So, every one is at the page.

Ok, here's a simplified thing that gives the same issue:

Suppose I've got a naive error logging procedure (to isolate the use of Standard_Error, which Spark doesn't like and I don't know how to get at the underlying file in Ada yet):

with Ada.Text_IO; use Ada.Text_IO;
package body Logging is
   procedure Log_Error(Message: String) with SPARK_Mode => Off is
   begin
      Put_Line(Standard_Error, Message);
   end Log_Error;
end Logging;

As you can see, SPARK is turned off for that.  Then I have (simplified) :

with Logging;                use Logging;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
package body Utils is
   procedure Error_Header is
   begin
      Log_Error
        ("This is the standard header I want for the Standard_Error output" &
         LF);
   end Error_Header;
end Utils;

When I run SPARK examiner (from within GPS) I Get the warning I'd like to clear:

warning: subprogram "Error_Header" has no effect.


^ permalink raw reply	[relevance 1%]

* GNAT vs Matlab - operation on   multidimensional complex matrices
@ 2020-03-23 23:16  1% darek
  2020-06-08 17:42  1% ` Shark8
  0 siblings, 1 reply; 200+ results
From: darek @ 2020-03-23 23:16 UTC (permalink / raw)


Hi Everyone, 
 I am working on radar signal processing algorithms that use multidimensional complex arrays. 

To my surprise, the performance of some Matlab functions is much better than compiled Ada code. 

Let's start with a simple problem of computing sum of all elements in a 3D real and complex array. 

The Ada code is as follows:

with Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Unchecked_Deallocation;

with Ada.Numerics.Long_Complex_Types;  use Ada.Numerics.Long_Complex_Types;

with Ada.Text_IO.Complex_IO;

procedure TestSpeed is
   

   
   package TIO renames Ada.Text_IO;
   
   package CTIO is new Ada.Text_IO.Complex_IO(Ada.Numerics.Long_Complex_Types);
   
   subtype mReal is Long_Float;
   
   
   NumIteration : constant := 1_000;
   NumChannels  : constant  := 64;
   NumRanges    : constant  := 400; 
   NumAngles    : constant  := 30;
   
   type tCubeReal is array (1..NumChannels, 1..NumAngles, 1..NumRanges) of mReal;
   type tCubeRealAcc is access all tCubeReal;
   --for tCubeReal'Alignment use 8;
   
   type tCubeComplex is array (1..NumChannels, 1..NumAngles, 1..NumRanges) of Complex;
   type tCubeComplexAcc is access all tCubeComplex;
   --for tCubeComplex'Alignment use 16;
   
   RealCubeAcc : tCubeRealAcc;
   SReal       : mReal;
   
   ComplexCubeAcc : tCubeComplexAcc;
   SComplex    : Complex;

   
   procedure Free is new Ada.Unchecked_Deallocation(tCubeReal, tCubeRealAcc);
   procedure Free is new Ada.Unchecked_Deallocation(tCubeComplex, tCubeComplexAcc);
   
   --| -------------------------------------------------------------------------
   procedure SpeedSumRealCube (NumIteration : Integer; Mtx : in  tCubeReal;  S: out mReal) is
      
      Ts   : Time;
      TEx  : Time_Span; 
      t    : mReal;
   begin
      Ts := Clock;
      S := 0.0;
      for k in 1..NumIteration loop
         for m  in Mtx'Range(1) loop
            for n in   Mtx'Range(2) loop
               for p in   Mtx'Range(3) loop
                  S := S + Mtx(m, n, p);
               end loop;
            end loop;
         end loop;      
      end loop;

      TEx :=  Clock - Ts;
      TIO.New_Line;
      TIO.Put_Line("Computation time:" & Duration'Image(To_Duration(TEx)));
      t := mReal(To_Duration(TEx))/mReal(NumIteration);
      TIO.Put_Line("Computation time per iteration:" & t'Image);
   end SpeedSumRealCube;
   
   --| -------------------------------------------------------------------------
   
   procedure SpeedSumComplexCube (NumIteration : Integer; Mtx : in  tCubeComplex;  S:  out Complex) is
      
      Ts   : Time;
      TEx  : Time_Span; 
      t    : mReal;
   begin
      Ts := Clock;     
      S := 0.0  + i* 0.0; 
      for k in 1..NumIteration loop
         for m  in Mtx'Range(1) loop
            for n in    Mtx'Range(2) loop
               for p in   Mtx'Range(3) loop
                  S := S + Mtx(m, n, p);
               end loop;
            end loop;
         end loop;      
      end loop;
      TEx :=  Clock - Ts;
      TIO.New_Line;
      TIO.Put_Line("Computation time:" & Duration'Image(To_Duration(TEx)));
      t := mReal(To_Duration(TEx))/mReal(NumIteration);
      TIO.Put_Line("Computation time per iteration:" & t'Image);
   end SpeedSumComplexCube;
   
   --| -------------------------------------------------------------------------
   
begin
   TIO.Put_Line("Real cube");
   TIO.Put_Line("Real type size is:" & Integer(mReal'Size)'Image);
   RealCubeAcc := new tCubeReal;
   RealCubeAcc.all := (others =>(others =>( others => 1.0)));
   SpeedSumRealCube(NumIteration => NumIteration,
                    Mtx           => RealCubeAcc.all,
                    S            => SReal);
   
   TIO.Put_Line("Sum is:" & SReal'Image);
   
   TIO.Put_Line("Complex cube");
   TIO.Put_Line("Complex type size is:" & Integer(Complex'Size)'Image);
   ComplexCubeAcc := new tCubeComplex;
   ComplexCubeAcc.all := (others =>(others =>( others => 1.0 + i * 1.0)));
   SpeedSumComplexCube(NumIteration => NumIteration,
                       Mtx          => ComplexCubeAcc.all,
                       S            => SComplex);
   
   TIO.Put("Sum is:"); CTIO.Put(SComplex);
   Free(ComplexCubeAcc);
   Free(RealCubeAcc);   
end TestSpeed;

1. Compiled with:  gcc version 9.2.0 (tdm64-1) ( and gnat community edition 2019), with the -O2 optimisation level. 
2. CPU: AMD64 Family 23 Model 24 Stepping 1  CPU0      2300           AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx
3. Win10 64bit 


The results of the program execution:

Computation time: 0.616710300
Computation time per iteration: 6.16710300000000E-04
Sum is: 7.68000000000000E+08
Complex cube
Complex type size is: 128

Computation time: 3.707091000
Computation time per iteration: 3.70709100000000E-03
Sum is:( 7.68000000000000E+08, 7.68000000000000E+08)


The executable produced by the gcc provide with the gnat community edition gave very similar results.

More interesting part - the Matlab code.

Matlab version : Matlab 2019b, 64bit

function [] = TestSpeed 

NumIterations = 1000;
NumChannels = 64;  
NumRanges  = 400; 
NumAngles = 30;

%--| real matrix 

ReMtx = ones(NumChannels, NumAngles, NumRanges);

tic
SReal =  ComputeSum(NumIterations, ReMtx);
TExR = toc;%cputime-ts;
fprintf('TExe:%f, sum real=%f\n', TExR, SReal);
%--| complex matrix
CplxMtx = complex(ReMtx, ReMtx);
%ts = cputime;
tic
SCplx = ComputeSum(NumIterations, CplxMtx);
TExC = toc; %cputime - ts;
fprintf('TExe:%f, sum complex= <%f,%f> \n', TExC, real(SCplx), imag(SCplx));
fprintf('Complex operations are %f times slower\n', TExC/TExR);
end % function


function [S] = ComputeSum(NumIterations, Mtx)
 S = 0;
 for i = 1:NumIterations   
    S = S + sum(sum(sum(Mtx)));  
 end % for  
end % function 

The results of the program execution:

TExe:0.260718, sum real=768000000.000000
TExe:0.789778, sum complex= <768000000.000000,768000000.000000> 
Complex operations are 3.029242 times slower


What is wrong with my code ? Is it the Ada compiler doing bad job here?
 
If you look at Matlab code, on average the computation that use complex  addition are ~3 times slower than for the real numbers.

In the case of Ada code, the complex operations are ~ 6 times slower that for the real numbers. 

Did I miss something somewhere ? Any ideas how I can improve the performance of the Ada program (different array layout, magic pragmas, or magic compiler switches) ?

It seems that Matlab is performing really well here ...

Any suggestions are  very welcome.

Regards,
  Darek  







^ permalink raw reply	[relevance 1%]

* Re: Ada.Calendar.Formatting.Image (or Time_Of) changing the time
  @ 2020-03-03 14:53  1% ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2020-03-03 14:53 UTC (permalink / raw)


Marius Amado-Alves <amado.alves@gmail.com> writes:

> Feeding Ada.Calendar.Formatting.Image with an Ada.Calendar.Time_Of the
> year, month, day, seconds on the left, we get the image on the
> right. Some images, marked *, are 1 hour behind.
>
> 2015 1 21 32040 ( 8:54 AM) => 2015-01-21 08:54:00
> 2015 1 21 39240 (10:54 AM) => 2015-01-21 10:54:00
> 2015 7 21 32040 ( 8:54 AM) => 2015-07-21 07:54:00 *
> 2015 7 21 39240 (10:54 AM) => 2015-07-21 09:54:00 *
>
> The different input is the month, January versus July, so it looks
> like a daylight savings thing. Is this expected behaviour? Thanks.
>
> [Compiler = GNAT Community 2018 (20180523-73)]

There was a conversation on Ada-Comment in June last year, in which it
turned out that compiler implementers may have have been misinterpreting
the ARM. It was quite confusing.

Part of the problem is that Ada.Calendar.Clock, implemented over the OS
facilities, may or may not be in local time; and how does it treat times
which are not in the 'now' time zone?

I wrote this:

   with Ada.Calendar.Formatting;
   with Ada.Calendar.Time_Zones;
   with Ada.Text_IO;
   procedure Marius is
      use type Ada.Calendar.Time;
      Earlier : constant Ada.Calendar.Time
        := Ada.Calendar.Time_Of (2015, 1, 21, 32040.0);
      Later : constant Ada.Calendar.Time
        := Ada.Calendar.Time_Of (2015, 7, 21, 32040.0);
      Offset_Earlier : constant Ada.Calendar.Time_Zones.Time_Offset
        := Ada.Calendar.Time_Zones.UTC_Time_Offset (Earlier);
      Offset_Later : constant Ada.Calendar.Time_Zones.Time_Offset
        := Ada.Calendar.Time_Zones.UTC_Time_Offset (Later);
   begin
      Ada.Text_Io.Put_Line ("Earlier");
      Ada.Text_IO.Put_Line
        ("UTC_Time_Offset: " & Offset_Earlier'Image);
      Ada.Text_IO.Put_Line
        ("Time_Zone default: "
           & Ada.Calendar.Formatting.Image (Earlier));
      Ada.Text_IO.Put_Line
        ("Time_Zone  offset: "
           & Ada.Calendar.Formatting.Image (Earlier, Time_Zone => Offset_Earlier));
      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put_Line ("Later");
      Ada.Text_IO.Put_Line
        ("UTC_Time_Offset: " & Offset_Later'Image);
      Ada.Text_IO.Put_Line
        ("Time_Zone default: "
           & Ada.Calendar.Formatting.Image (Later));
      Ada.Text_IO.Put_Line
        ("Time_Zone  offset: "
           & Ada.Calendar.Formatting.Image (Later, Time_Zone => Offset_Later));
   end Marius;

and it appears that with GNAT (current free
versions), macOS Mojave, time zone London, Time_Of does something
mysterious;it seems that Time_Of looks at the time you specify (08:54)
and thinks to itself, "but the date part shows that's in DST, so the
local clock now (in GMT) would be reading 07:54"

   $ ./marius 
   Earlier
   UTC_Time_Offset:  0
   Time_Zone default: 2015-01-21 08:54:00
   Time_Zone  offset: 2015-01-21 08:54:00

   Later
   UTC_Time_Offset:  60
   Time_Zone default: 2015-07-21 07:54:00
   Time_Zone  offset: 2015-07-21 08:54:00

Just for fun, trying a different time zone (this may well NOT be the
same as actually being in that time zone :)

   $ TZ=EST ./marius 
   Earlier
   UTC_Time_Offset: -300
   Time_Zone default: 2015-01-21 13:54:00
   Time_Zone  offset: 2015-01-21 08:54:00

   Later
   UTC_Time_Offset: -300
   Time_Zone default: 2015-07-21 13:54:00
   Time_Zone  offset: 2015-07-21 08:54:00

Same results on Debian (running in a VM on this Macbook).


^ permalink raw reply	[relevance 1%]

Results 1-200 of ~6000   | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-03-02 18:49     Ada.Calendar.Formatting.Image (or Time_Of) changing the time Marius Amado-Alves
2020-03-03 14:53  1% ` Simon Wright
2020-03-23 23:16  1% GNAT vs Matlab - operation on multidimensional complex matrices darek
2020-06-08 17:42  1% ` Shark8
2020-03-25 20:48     How do I resolve SPARK warning "procedure [...] has no effect for output procedure digitig
2020-03-25 23:38     ` Anh Vo
2020-03-26  0:45  1%   ` digitig
2020-03-26 10:02         ` Simon Wright
2020-03-26 11:56           ` digitig
2020-03-26 13:13  1%         ` Egil H H
2020-03-27  0:05  0%           ` digitig
2020-04-02 13:58  1% Simple parse from https website Rego, P.
2020-04-02 14:42  0% ` Dmitry A. Kazakov
2020-04-02 14:48       ` Rego, P.
2020-04-02 17:16  1%     ` Dmitry A. Kazakov
2020-04-02 18:27  0%       ` Rego, P.
2020-04-09  8:40     Using Generic Pasckages ldries46
2020-04-09 20:45  1% ` Jere
2020-04-14  7:15     Put the access value ldries46
2020-04-14 11:05     ` Jeffrey R. Carter
2020-04-14 12:09       ` ldries46
2020-04-15  7:20  1%     ` briot.emmanuel
2020-04-19  9:28  1% GNAT CE 2019 bug: Predicate check not performed AdaMagica
2020-04-19 22:31  0% ` Anh Vo
2020-04-19 22:32  0%   ` Anh Vo
2020-04-29  8:46     Getting the 3 letter time zone abbreviation Bob Goddard
2020-04-29  9:09     ` Dmitry A. Kazakov
2020-04-29 19:20       ` Bob Goddard
2020-04-29 19:53         ` Dmitry A. Kazakov
2020-04-30 18:59           ` Bob Goddard
2020-04-30 21:11  1%         ` Dmitry A. Kazakov
2020-05-31 10:46     Any good package for mathematical function in Ada? reinert
2020-05-31 23:25     ` Jerry
2020-06-01  8:24       ` reinert
2020-06-01 10:19  1%     ` Dmitry A. Kazakov
2020-06-01 10:48           ` Nasser M. Abbasi
2020-06-01 11:34             ` Dmitry A. Kazakov
2020-06-05 22:54               ` Paul Rubin
2020-06-06  7:06                 ` Dmitry A. Kazakov
2020-06-06 13:58  1%               ` AdaMagica
2020-06-02  9:46  1% GNAT CE 2020 : error when using anon access to subprogram inside protected !? Jérôme Haguet
2020-06-02 12:04  0% ` Simon Wright
2020-06-06 23:40  1% CONSTRAINT ERROR: erroneous memory access jcupak
2020-06-07 15:53  0% ` Anh Vo
2020-06-10 11:14  1% How to terminate all running tasks? Gilbert Gosseyn
2020-06-10 12:12  0% ` Niklas Holsti
2020-06-10 13:49  0% ` Jeffrey R. Carter
2020-06-10 14:45  0%   ` Jeffrey R. Carter
2020-07-07 21:10     Fixed vs float and precision and conversions Björn Lundin
2020-07-07 21:58     ` Shark8
2020-07-08  8:15       ` Björn Lundin
2020-07-08 16:16  1%     ` Shark8
2020-07-08 18:08  0%       ` Björn Lundin
2020-07-30 20:21  2% Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
2020-07-30 21:51  1% ` J-P. Rosen
2020-07-31 17:06  2%   ` Blady
2020-08-01  5:35  1%     ` J-P. Rosen
2020-08-01  7:42  1%       ` Blady
2020-08-01 13:45  2%         ` J-P. Rosen
2020-07-31 18:19  1% ` Shark8
2020-08-01  7:46  1%   ` Blady
2020-08-01 17:23  2%     ` Shark8
2020-09-04 10:14  1% ` liyan white
2020-09-24  4:10  1% ` nimaopatel121
2020-09-11 10:37     Visibility issue Daniel
2020-09-11 21:05     ` Dmitry A. Kazakov
2020-09-14 11:33       ` Daniel
2020-09-14 14:42         ` Dmitry A. Kazakov
2020-09-15 19:35           ` Daniel
2020-09-16  7:14             ` Dmitry A. Kazakov
2020-09-16 10:23  1%           ` Daniel
2020-12-03 13:00     Advent of Code Day 3 Stephen Leake
2020-12-03 14:37  1% ` Jeffrey R. Carter
2020-12-31 11:48     renames usage DrPi
2020-12-31 12:10  1% ` John Perry
2020-12-31 13:31  0%   ` DrPi
2021-01-05 11:04     Lower bounds of Strings Stephen Davies
2021-01-05 11:57     ` Dmitry A. Kazakov
2021-01-05 12:32  1%   ` Jeffrey R. Carter
2021-01-05 13:40  1%     ` Dmitry A. Kazakov
2021-01-14 11:38     ` AdaMagica
2021-01-15 10:24       ` Stephen Davies
2021-01-15 11:41  1%     ` J-P. Rosen
2021-01-15 17:35           ` Stephen Davies
2021-01-15 19:36  1%         ` Egil H H
2021-01-09 15:16     From_string(Arg : String) return Big_Integer soren rundgren
2021-01-09 17:00     ` AdaMagica
2021-01-09 20:09  1%   ` soren rundgren
2021-01-09 20:11  1%   ` soren rundgren
2021-01-09 22:13  0%     ` DrPi
2021-01-10  9:46  0%       ` Dmitry A. Kazakov
2021-01-27 19:59  1% Problem with unbounded string input Brian McGuinness
2021-01-29 14:57  1% "begginner", sorting algorithm Mehdi Saada
2021-01-29 16:15  1% ... !! GPS Mehdi Saada
2021-01-29 18:39  0% ` Simon Wright
2021-01-30 14:40  1% Pascal triangle algorithm ("homework"). iterative one. the direct one was simple Mehdi Saada
2021-02-10 18:39  1% "end of declaration" Mehdi Saada
2021-02-10 19:21  0% ` Egil H H
2021-02-10 20:59  0% ` Shark8
2021-02-14 19:35  1% algorithm, two implementations that act the same, same type etc Mehdi Saada
2021-03-12 20:49     array from static predicate on enumerated type Matt Borchers
2021-03-12 22:41     ` Dmitry A. Kazakov
2021-03-13  2:06       ` Matt Borchers
2021-03-13  8:04         ` Dmitry A. Kazakov
2021-03-15 14:11           ` Matt Borchers
2021-03-15 17:48             ` Shark8
2021-03-15 20:25               ` Dmitry A. Kazakov
2021-03-16 13:27                 ` Shark8
2021-03-16 14:25  1%               ` Dmitry A. Kazakov
2021-03-15 16:46     Ada and "early return" - opinion/practice question John McCabe
2021-03-15 18:12  1% ` Shark8
2021-04-17 21:45     Unchecked_Deallocation with tagged types DrPi
2021-04-18  8:21     ` Dmitry A. Kazakov
2021-04-18  9:13       ` DrPi
2021-04-18 16:48         ` Jeffrey R. Carter
2021-04-20 15:57           ` Stephen Leake
2021-04-20 17:24             ` Jeffrey R. Carter
2021-04-20 17:34               ` Vincent Marciante
2021-04-20 20:56                 ` Jeffrey R. Carter
2021-04-21 10:21                   ` Vincent Marciante
2021-04-24  1:04                     ` Randy Brukardt
2022-04-12 23:25                       ` use clauses Thomas
2022-04-13  1:05                         ` Randy Brukardt
2022-04-19  3:53  1%                       ` Thomas
2022-04-19  5:59  1%                         ` Randy Brukardt
2021-04-17 22:03     Ada and Unicode DrPi
2021-04-19  8:29     ` Maxim Reznik
2021-04-19 11:15       ` Simon Wright
2022-04-03 19:20         ` Thomas
2022-04-04  6:10           ` Vadim Godunko
2023-03-30 23:35  1%         ` Thomas
2021-04-19  9:08     ` Stephen Leake
2021-04-19 11:56       ` Luke A. Guest
2021-04-19 12:52         ` Dmitry A. Kazakov
2021-04-19 13:00           ` Luke A. Guest
2021-04-19 13:24             ` J-P. Rosen
2022-04-03 18:04               ` Thomas
2022-04-06 18:57                 ` J-P. Rosen
2022-04-07  1:30  1%               ` Randy Brukardt
2021-04-20 19:06             ` Randy Brukardt
2022-04-03 18:37               ` Thomas
2022-04-04 23:52  1%             ` Randy Brukardt
2023-03-31  3:06  1%               ` Thomas
2023-04-01 10:18  0%                 ` Randy Brukardt
2021-04-26 15:43     [Ada95] Private non-generic children of generics not allowed Vincent Marciante
2021-04-29  8:57     ` AdaMagica
2021-04-29 10:20       ` Vincent Marciante
2021-04-29 11:02  1%     ` Egil H H
2021-04-29 17:17  0%       ` Vincent Marciante
2021-04-27 14:04  1% Constraint error overflow Richard Iswara
2021-04-27 15:00     ` Dmitry A. Kazakov
2021-04-27 15:32       ` Richard Iswara
2021-04-27 16:31  1%     ` Simon Wright
2021-05-17 18:44  1% Better way to fill Storage_IO? Michael Hardeman
2021-05-17 19:14  1% ` Simon Wright
2021-05-17 19:23  1%   ` Michael Hardeman
2021-05-18 20:39  0%     ` Simon Wright
2021-05-19  6:24  0%       ` Dmitry A. Kazakov
2021-06-10  2:17     Is it possible to redirect text output to a String or Unbounded_String? Jerry
2021-06-10  6:50  1% ` Simon Wright
2021-06-10  7:00  1% ` Dmitry A. Kazakov
2021-06-11 13:07  1%   ` Stephane Carrez
2021-06-10  8:31  1% ` ytomino
2021-06-10 21:12  1% ` Shark8
2021-06-12 12:51  1% non-preemptive tasking on GNAT 2020 Windows 10 multicore AMD Dan Winslow
2021-06-19 18:28     XMLAda & unicode symbols 196...@googlemail.com
2021-06-19 21:24  1% ` Simon Wright
2021-06-20 17:10  0%   ` 196...@googlemail.com
2021-06-21 15:26         ` Simon Wright
2021-06-21 18:33  1%       ` Emmanuel Briot
2021-06-21 20:06  0%         ` 196...@googlemail.com
2021-07-28  9:25     Building the 2021 source release of GnatStudio Rod Kay
2021-07-29  0:49     ` Randy Brukardt
2021-07-29  7:49       ` Luke A. Guest
2021-07-29  8:41         ` Dmitry A. Kazakov
2021-07-29 11:33           ` Stéphane Rivière
2021-07-29 11:58             ` Dmitry A. Kazakov
2021-07-30 11:29               ` Stéphane Rivière
2021-07-31 10:30  1%             ` Dmitry A. Kazakov
2021-07-31 11:58                   ` Stéphane Rivière
2021-07-31 12:29  1%                 ` Dmitry A. Kazakov
2021-08-26  5:36  1% Get_Line skip input Richard Iswara
2021-08-26  7:56  1% ` Niklas Holsti
2021-08-26  9:09  1% ` Jeffrey R. Carter
2021-08-27  2:55  0%   ` Richard Iswara
2021-09-02 10:25  1% Oddity with function returning image of fixed point type Jesper Quorning
2021-09-29  9:09     On absurdity of collections 7.6.1 (11.1/3) Dmitry A. Kazakov
2021-09-29 11:05     ` Simon Wright
2021-09-29 11:20       ` Dmitry A. Kazakov
2021-09-29 21:38  1%     ` Simon Wright
2021-09-30  8:07  0%       ` Dmitry A. Kazakov
2021-10-23  8:06  2% How to test if file = Ada.Text_IO.Standard_Input ? reinert
2021-10-23 10:22  2% ` Jeffrey R.Carter
2021-10-23 12:28  1%   ` reinert
2021-10-23 15:40  2%     ` Gautier write-only address
2021-10-24 20:51  1%   ` Keith Thompson
2021-11-12 14:32  1% Beginners question uq5huo...@gmail.com
2021-11-12 15:24  0% ` Niklas Holsti
2021-11-12 15:44  0%   ` uq5huo...@gmail.com
2021-11-15 21:27  1% Integer_IO or Modular_IO with different base as default Ken Roberts
2021-11-15 21:40  0% ` Simon Wright
2021-11-15 22:09       ` Ken Roberts
2021-11-15 23:10  1%     ` Jeffrey R.Carter
2021-11-19  0:06  1%       ` Ken Roberts
2021-11-15 22:13  1% ` Ben Bacarisse
2021-12-22  5:57  1% Ada.Numerics.Big_Numbers.Big_Integer has a limit of 300 digits? Michael Ferguson
2022-01-01 18:53     Accessing Addresses in a Passed String Pat Van Canada
2022-01-01 20:57  1% ` Niklas Holsti
2022-01-26 16:54  1% Generic formal ">" Simon Wright
2022-02-02 17:21  1% Plugin with controlled variable for initialization hreba
2022-02-02 18:05  0% ` Dmitry A. Kazakov
2022-03-08  7:45  1% Get_Immediate does not read CR in CRLF pairs Marius Amado-Alves
2022-03-08  7:46  0% ` Luke A. Guest
2022-03-08 12:08  0%   ` Marius Amado-Alves
2022-03-08 14:57  0%     ` Luke A. Guest
2022-03-08  8:03  0% ` Dmitry A. Kazakov
2022-03-08  9:06  1% ` Jeffrey R.Carter
2022-04-30  8:57  1% Question on in/out parameters reinert
2022-06-06 12:59     Extra information in the message string of exceptions Rod Kay
2022-06-06 13:40     ` Fabien Chouteau
2022-06-07 15:55       ` Fabien Chouteau
2022-06-08  7:31  1%     ` Jerry
2022-06-08  8:04  0%       ` Dmitry A. Kazakov
2022-06-09  2:39  0%         ` Jerry
2022-06-09 21:30     Using pointers with inline assembly in Ada NiGHTS
2022-06-11 12:28  1% ` Simon Wright
2022-06-11 12:32  0%   ` NiGHTS
2022-08-17 20:11  1% Adjust primitive not called on defaulted nonlimited controlled parameter, bug or feature ? David SAUVAGE
2022-08-17 22:49  0% ` Jere
2022-09-11  7:16  1% Is this an error in compiler? reinert
2022-09-11  7:19  1% Is this an error in compiler reinert
2022-09-11  7:21  1% Is this an error in compiler? reinert
2022-09-11  7:27  1% reinert
2022-09-12 22:43  1% Struggling to use fonts in SDLAda Troy Jacobs
2022-09-14 12:36     Non-standard functions in GNAT's Ada.Containers packages? G.B.
2022-09-14 16:04     ` Egil H H
2022-09-15  7:13       ` G.B.
2022-09-15 14:26         ` Marius Amado-Alves
2022-09-15 15:03           ` Niklas Holsti
2022-09-15 17:11             ` Marius Amado-Alves
2022-09-15 17:22               ` Dmitry A. Kazakov
2022-09-16 16:03                 ` Marius Amado-Alves
2022-09-16 16:30                   ` Marius Amado-Alves
2022-09-16 17:08  1%                 ` Jere
2022-09-16 11:33               ` Björn Lundin
2022-09-16 15:00                 ` Marius Amado-Alves
2022-09-16 15:42  1%               ` Egil H H
2022-09-16 15:47  1%           ` Jere
2022-09-26  6:20     A new universe of Ada Rick Duley
2022-09-26  6:45  1% ` Dmitry A. Kazakov
2022-09-26  7:00  0%   ` Rick Duley
2022-09-26  7:27       ` Simon Wright
2022-09-26  7:45         ` Dmitry A. Kazakov
2022-09-26  8:04           ` Rick Duley
2022-09-26  9:16  1%         ` Dmitry A. Kazakov
2022-09-26  6:54  1% Compiler error (2) ? reinert
2022-09-26  8:34  0% ` J-P. Rosen
2022-09-26  8:47  1%   ` reinert
2022-09-26  9:59  0%     ` reinert
2022-10-11  8:06     Bold text (in terminal) from Ada? reinert
2022-10-11  8:49  1% ` Niklas Holsti
2022-11-20 18:03  1% Variable value if exception is raised nytpu
     [not found]     <nnd$70b29fcd$4811e339@5bc1ef990a7003a8>
2023-01-10 18:12  1% ` Is this my failure or of the compiler's debugger Niklas Holsti
2023-01-10 22:17  0%   ` ldries46
2023-01-11  7:40  0%     ` ldries46
2023-01-11 13:43  1%     ` Niklas Holsti
2023-01-11 16:52  0%       ` ldries46
2023-01-11 10:14     Text_io package's Positive_Count type Mace Ayres
2023-01-11 13:52     ` Niklas Holsti
2023-01-11 21:04  1%   ` Mace Ayres
2023-01-11 21:42  0%     ` Niklas Holsti
2023-01-11 21:46  1%     ` Jeffrey R.Carter
2023-01-22 21:34     Real_Arrays on heap with overloaded operators and clean syntax Jim Paloander
2023-01-22 23:18     ` Rod Kay
2023-01-22 23:20       ` Jim Paloander
2023-01-22 23:34         ` Rod Kay
2023-01-22 23:53  1%       ` Joakim Strandberg
2023-02-07 20:29     Broadcast / iterate to all Connection objects via Simple Components? A.J.
2023-02-08  9:55     ` Jeffrey R.Carter
2023-02-13  7:28       ` Emmanuel Briot
2023-02-13  8:30         ` Dmitry A. Kazakov
2023-02-13  8:44           ` Emmanuel Briot
2023-02-13 10:55             ` Dmitry A. Kazakov
2023-02-13 11:07               ` Emmanuel Briot
2023-02-13 11:57                 ` Dmitry A. Kazakov
2023-02-13 13:22                   ` Niklas Holsti
2023-02-13 15:10                     ` Dmitry A. Kazakov
2023-02-13 16:26                       ` Niklas Holsti
2023-02-13 19:48                         ` Dmitry A. Kazakov
2023-02-15  9:54                           ` Niklas Holsti
2023-02-15 10:57  1%                         ` Dmitry A. Kazakov
2023-02-22 16:34  1% wait does not perform as expected Daniel Gaudry
2023-02-22 17:36  1% ` Niklas Holsti
2023-02-23 14:26       ` AdaMagica
2023-02-23 17:35         ` Niklas Holsti
2023-02-23 18:14           ` Dmitry A. Kazakov
2023-02-23 18:29             ` Niklas Holsti
2023-02-23 18:47  1%           ` Daniel Gaudry
2023-02-23 19:08  0%             ` Niklas Holsti
2023-02-23 19:31  0%             ` Niklas Holsti
2023-02-24 21:16  1% ` Jeffrey R.Carter
2023-02-28 21:10     Build order with gprbuild Gautier write-only address
2023-02-28 22:07     ` Dmitry A. Kazakov
2023-03-01 20:08  1%   ` Gautier write-only address
2023-03-30 21:49  1% ChatGPT Anatoly Chernyshev
2023-05-05  9:51  1% problemn with string'last Daniel Gaudry
2023-05-05 10:02  0% ` Dmitry A. Kazakov
2023-05-05 11:17  0% ` Jeffrey R.Carter
2023-06-08  3:55     does a safer language mean it is slower to run? Nasser M. Abbasi
2023-06-08  8:50  1% ` Jeffrey R.Carter
2023-07-27  5:26     When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced? Kenneth Wolcott
2023-07-27  8:53  1% ` Jeffrey R.Carter
2023-07-27 22:47  1%   ` Kenneth Wolcott
2023-07-28 18:21         ` Simon Wright
2023-07-29 11:07           ` AdaMagica
2023-07-29 23:49             ` Kenneth Wolcott
2023-07-29 23:53  1%           ` Kenneth Wolcott
2023-07-30  4:43  1%             ` Randy Brukardt
2023-08-13 16:16     Unifont static compiled and stack size Micah Waddoups
2023-08-14 10:06  1% ` Jeffrey R.Carter
2023-08-14 15:10  1%   ` Micah Waddoups
2023-08-18  7:18     Parameterised 'Image Attributes Rod Kay
2023-08-18  8:25     ` Luke A. Guest
2023-08-19  9:14       ` J-P. Rosen
2023-08-19 16:49         ` moi
2023-08-20  7:25           ` Randy Brukardt
2023-08-20  9:43             ` Dmitry A. Kazakov
2023-08-21 23:34               ` Randy Brukardt
2023-08-22  8:13                 ` Dmitry A. Kazakov
2023-08-23 10:20                   ` Stephen Davies
2023-08-23 16:16                     ` Dmitry A. Kazakov
2023-08-24 19:59                       ` Stephen Davies
2023-08-25  7:26                         ` Dmitry A. Kazakov
2023-08-25  9:04                           ` Stephen Davies
2023-08-25 13:02                             ` Dmitry A. Kazakov
2023-08-28  9:18                               ` Stephen Davies
2023-08-28 10:58                                 ` Dmitry A. Kazakov
2023-08-28 15:42                                   ` Stephen Davies
2023-08-28 16:09                                     ` Dmitry A. Kazakov
2023-08-28 17:33                                       ` G.B.
2023-08-28 19:08  1%                                     ` Dmitry A. Kazakov
2023-09-04  9:19     project euler 26 CSYH (QAQ)
2023-09-04 11:06     ` Niklas Holsti
2023-09-04 12:39       ` Dmitry A. Kazakov
2023-09-04 16:01         ` Ben Bacarisse
2023-09-04 19:20           ` Dmitry A. Kazakov
2023-09-04 20:18             ` Ben Bacarisse
2023-09-04 21:00               ` Dmitry A. Kazakov
2023-09-04 23:16  1%             ` Ben Bacarisse
2023-09-05  7:23  0%               ` Dmitry A. Kazakov
2023-09-05 15:18  0%                 ` Ben Bacarisse
2023-09-05 17:35  0%                 ` moi
2023-09-04 14:23  1% ` Dmitry A. Kazakov
2023-09-14 14:02  1% Aggregate with derived types Blady
2023-09-14 15:31  0% ` Jeffrey R.Carter
2023-09-14 20:00  0%   ` Blady
2023-09-22 19:30  1% Weird behavior of Get character with trailing new lines Blady
2023-09-22 19:52  0% ` Niklas Holsti
2023-09-23 20:22  1% Valid attribute and input operations Maciej Sobczak
2023-09-23 21:48  1% ` Jeffrey R.Carter
2023-09-26  6:13  0%   ` Randy Brukardt
2023-09-27 19:30     GNAT linking and macOS moi
2023-09-28 13:32     ` Simon Wright
2023-09-28 21:00       ` Simon Wright
2023-09-30  2:30  1%     ` Kenneth Wolcott
2023-10-02  2:42  1% get_immediate echoe character--compiled error? richardthiebaud
2023-10-02  5:48  0% ` Keith Thompson
2023-10-02 20:07  0%   ` richardthiebaud
2023-10-02 22:27         ` Keith Thompson
2023-10-02 22:47           ` richardthiebaud
2023-10-03  8:41             ` Niklas Holsti
2023-10-03 10:20               ` Simon Wright
2023-10-04  0:13                 ` Keith Thompson
2023-10-04  8:22                   ` Simon Wright
2023-10-04 10:48                     ` Jeffrey R.Carter
2023-10-04 11:38                       ` Simon Wright
2023-10-04 13:05  1%                     ` Jeffrey R.Carter
2023-10-05  0:43  0%                       ` Randy Brukardt
2023-10-04 21:14  0% ` Jeffrey R.Carter
2023-10-04 22:12  0%   ` Keith Thompson
2024-01-10 10:37  1% Renaming primitives Blady
2024-01-10 11:38  0% ` Jeffrey R.Carter
2024-01-11 10:06  0%   ` Blady
2024-01-10 12:13  0% ` Dmitry A. Kazakov

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