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: String_Access in unbounded string handling?
  2024-01-19  1:36  1%   ` Randy Brukardt
@ 2024-01-30 15:53  0%     ` Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2024-01-30 15:53 UTC (permalink / raw)


Le 19/01/2024 à 02:36, Randy Brukardt a écrit :
> "Tucker Taft" <tucker.taft@gmail.com> wrote in message
> news:afd791fa-853f-48fa-9223-759b12d4ed87n@googlegroups.com...
> On Sunday, January 14, 2024 at 6:05:45?AM UTC-5, Blady wrote:
>>> Hello,
>>>
>>> String_Access is defined in A.4.5 Unbounded-Length String Handling:
>>> 7 type String_Access is access all String;
>>>
>>> and note:
>>> 75 The type String_Access provides a (nonprivate) access type for
>>> explicit processing of unbounded-length strings.
>>>
>>> I wonder what String_Access is for and what could be "explicit
>>> processing"?
>>
>> The idea was to support the explicit use of new String'(...), X.all, and
>> Unchecked_Deallocation
>> rather than the implicit use of the heap inherent in Unbounded strings.  It
>> was recognized that you
>> need a single global access type to avoid having to do conversions all over
>> the place.  This
>> predated the availability of stand-alone objects of an anonymous access
>> type
>> (aka "SAOOAAATs" ;-), but those are not universally loved either.  It
>> certainly cannot be
>> removed now without potentially very painful disruption of existing users.
>> It could be moved
>> to a different package without too much disruption, but I haven't seen any
>> groundswell of interest
>> in doing that either.
> 
> I'm dubious that there are any such users. Certainly, in the handful of
> cases where I needed such a type, I just declared it (strong typing, you
> know?) and never thought of Ada.Strings.Unbounded as being a place to find
> such a type already defined. It is such an odd place I doubt anyone outside
> of perhaps the people who defined the type ever used it.
> 
> OTOH, I agree that the compatibility impact is non-zero (anyone who did use
> it would have to change their code), and the benefit of removing the type at
> this point is close to zero (junk declarations abound in long-term Ada
> packages, what's one more; and certainly there is a lot of unused stuff in
> any particular reusable package and any particular use), so the cost-benefit
> ratio doesn't seem to make a change here worth it. An Ada successor language
> would design Ada.Strings.Unbounded rather differently (so as to be able to
> use string literals directly with the type) and probably would include
> universal character support as well, so it's hard to find an important
> reason to change this.

At least, the type String_Access could be tagged as obsolescent.

Pascal.

^ permalink raw reply	[relevance 0%]

* Re: String_Access in unbounded string handling?
  @ 2024-01-19  1:36  1%   ` Randy Brukardt
  2024-01-30 15:53  0%     ` Blady
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2024-01-19  1:36 UTC (permalink / raw)


"Tucker Taft" <tucker.taft@gmail.com> wrote in message 
news:afd791fa-853f-48fa-9223-759b12d4ed87n@googlegroups.com...
On Sunday, January 14, 2024 at 6:05:45?AM UTC-5, Blady wrote:
>> Hello,
>>
>> String_Access is defined in A.4.5 Unbounded-Length String Handling:
>> 7 type String_Access is access all String;
>>
>> and note:
>> 75 The type String_Access provides a (nonprivate) access type for
>> explicit processing of unbounded-length strings.
>>
>> I wonder what String_Access is for and what could be "explicit 
>> processing"?
>
>The idea was to support the explicit use of new String'(...), X.all, and 
>Unchecked_Deallocation
>rather than the implicit use of the heap inherent in Unbounded strings.  It 
>was recognized that you
>need a single global access type to avoid having to do conversions all over 
>the place.  This
>predated the availability of stand-alone objects of an anonymous access 
>type
>(aka "SAOOAAATs" ;-), but those are not universally loved either.  It 
>certainly cannot be
>removed now without potentially very painful disruption of existing users. 
>It could be moved
>to a different package without too much disruption, but I haven't seen any 
>groundswell of interest
>in doing that either.

I'm dubious that there are any such users. Certainly, in the handful of 
cases where I needed such a type, I just declared it (strong typing, you 
know?) and never thought of Ada.Strings.Unbounded as being a place to find 
such a type already defined. It is such an odd place I doubt anyone outside 
of perhaps the people who defined the type ever used it.

OTOH, I agree that the compatibility impact is non-zero (anyone who did use 
it would have to change their code), and the benefit of removing the type at 
this point is close to zero (junk declarations abound in long-term Ada 
packages, what's one more; and certainly there is a lot of unused stuff in 
any particular reusable package and any particular use), so the cost-benefit 
ratio doesn't seem to make a change here worth it. An Ada successor language 
would design Ada.Strings.Unbounded rather differently (so as to be able to 
use string literals directly with the type) and probably would include 
universal character support as well, so it's hard to find an important 
reason to change this.

Also, I'm pretty sure we're discussed this within the ARG several times in 
the past, so this is well-trodden ground.

                  Randy.




^ permalink raw reply	[relevance 1%]

* Re: String_Access in unbounded string handling?
  2024-01-17  1:24  1%   ` Randy Brukardt
@ 2024-01-17  9:54  0%     ` Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2024-01-17  9:54 UTC (permalink / raw)


Le 17/01/2024 à 02:24, Randy Brukardt a écrit :
> "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message
> news:uo0fs5$dja6$1@dont-email.me...
>> On 2024-01-14 12:05, Blady wrote:
>>>
>>> String_Access is defined in A.4.5 Unbounded-Length String Handling:
>>> 7 type String_Access is access all String;
>>>
>>> and note:
>>> 75 The type String_Access provides a (nonprivate) access type for
>>> explicit processing of unbounded-length strings.
>>>
>>> I wonder what String_Access is for and what could be "explicit
>>> processing"?
>>
>> String_Access is a mistake that should not exist.
> 
> I agree with Jeffrey. Whatever reason it was initially put into the package
> has long since ceased to be relevant. And, as Dmitry notes, when you want
> such a type, it's usually because you didn't want to use
> Ada.Strings.Unbounded (or Bounded). So the placement is odd at best.
> 
>                 Randy.

Thanks for all your answers,

This is probably a very minor subject, however I submitted it:
https://github.com/Ada-Rapporteur-Group/User-Community-Input/issues/79

Pascal.

^ permalink raw reply	[relevance 0%]

* Re: String_Access in unbounded string handling?
  @ 2024-01-17  1:24  1%   ` Randy Brukardt
  2024-01-17  9:54  0%     ` Blady
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2024-01-17  1:24 UTC (permalink / raw)


"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message 
news:uo0fs5$dja6$1@dont-email.me...
> On 2024-01-14 12:05, Blady wrote:
>>
>> String_Access is defined in A.4.5 Unbounded-Length String Handling:
>> 7 type String_Access is access all String;
>>
>> and note:
>> 75 The type String_Access provides a (nonprivate) access type for 
>> explicit processing of unbounded-length strings.
>>
>> I wonder what String_Access is for and what could be "explicit 
>> processing"?
>
> String_Access is a mistake that should not exist.

I agree with Jeffrey. Whatever reason it was initially put into the package 
has long since ceased to be relevant. And, as Dmitry notes, when you want 
such a type, it's usually because you didn't want to use 
Ada.Strings.Unbounded (or Bounded). So the placement is odd at best.

               Randy.


^ permalink raw reply	[relevance 1%]

* Re: project euler 26
  @ 2023-09-04 14:23  1% ` Dmitry A. Kazakov
  0 siblings, 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: [Ann] WinRt - version 3
  @ 2023-09-03  9:07  2% ` AlexG
  0 siblings, 0 replies; 200+ results
From: AlexG @ 2023-09-03  9:07 UTC (permalink / raw)


Below is a simple example of the Api usage

--------------------------------------------------------------------------------
with Ada.Wide_Text_IO;
with Ada.Strings.Wide_Unbounded;
with WinRt;                             
with WinRt.Windows.Foundation;
with WinRt.Windows.Networking;
with WinRt.Windows.Networking.Sockets;
with WinRt.Windows.Storage.Streams;
with WinRt.Windows.Web.Http;
--------------------------------------------------------------------------------
procedure WinRt3Test2 is

    use WinRt;
    use Ada.Strings.Wide_Unbounded;
    
    Hr : HResult := 0;
    
    function "+"(value : Wide_String) return Unbounded_Wide_String renames To_Unbounded_Wide_String;
    function "+"(value : Unbounded_Wide_String) return Wide_String renames To_Wide_String;

begin
    Hr := RoInitialize;
    if Hr = 0 then
    
        declare
            Uri                   : Windows.Foundation.Uri := Windows.Foundation.Constructor (+"http://www.google.com");
            HttpClient      : Windows.Web.Http.HttpClient := Windows.Web.Http.Constructor;
            Result             : WString;
        begin
            Result := HttpClient.GetStringAsync (Uri);
            Ada.Wide_Text_IO.Put_Line (+Result);
            HttpClient.Close;
        end;
        
        declare
            Host                 : Windows.Networking.HostName := Windows.Networking.Constructor(+"www.google.com");
            Port                  : WString := +"80";
            Socket             : Windows.Networking.Sockets.StreamSocket := Windows.Networking.Sockets.Constructor;
            DataWriter      : Windows.Storage.Streams.DataWriter := Windows.Storage.Streams.Constructor (Socket.get_OutputStream);
        begin
            Socket.ConnectAsync (Host, Port);
            Socket.Close;
        end;
    
        RoUninitialize;
    end if;
end;

^ permalink raw reply	[relevance 2%]

* Re: Unifont static compiled and stack size...
  @ 2023-08-14  9:39  1%       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2023-08-14  9:39 UTC (permalink / raw)


On 2023-08-14 11:25, Kevin Chadwick wrote:

>> Doing something like that for bitmap fonts is just as simple. The only 
>> minor issue is creating an index map: code point to the bitmap image 
>> name (array), because a flat array would blow out.
> 
> What does blow out mean in this context?

If you tried:

    type Font_Type is array (Code_Point) of Bitmap_Ptr;

The range of code points is 0..16#10FFFF#. E.g. when I implemented 
Ada.Strings.Maps for Unicode, I could not use such arrays either as the 
native ASCII implementation does.

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

^ permalink raw reply	[relevance 1%]

* Re: Formal Package Compiler Differences
  2023-07-14 19:17  1% Formal Package Compiler Differences Jeffrey R.Carter
@ 2023-07-14 19:27  0% ` Jeffrey R.Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2023-07-14 19:27 UTC (permalink / raw)


On 2023-07-14 21:17, Jeffrey R.Carter wrote:
> I have a generic pkg;
> 
> with Ada.Containers.Vectors;
> 
> generic -- Vector_Conversions
>     type Index is range <>;
>     type Element is private;
>     type Fixed is array (Index range <>) of Element;
> 
>     with function "=" (Left : in Element; Right : in Element) return Boolean
>     is <>;

Oops! This "=" should be removed to get the behavior described.

> 
>     with package Unbounded is new Ada.Containers.Vectors
>        (Index_Type => Index, Element_Type => Element);
> package Vector_Conversions is
>     -- Empty
> end Vector_Conversions;
> 
> and an instantiation of
> 
> with Ada.Containers.Vectors;
> with Ada.Strings.Unbounded;
> with Vector_Conversions;
> 
> procedure Instance_Test is
>     use Ada.Strings.Unbounded;
> 
>     package String_Lists is new Ada.Containers.Vectors
>        (Index_Type => Positive, Element_Type => Unbounded_String);
> 
>     type String_List is array (Positive range <>) of Unbounded_String;
> 
>     package Conversions is new Vector_Conversions
>        (Index     => Positive,
>         Element   => Unbounded_String,
>         Fixed     => String_List,
>         Unbounded => String_Lists);
> begin -- Instance_Test
>     null;
> end Instance_Test;
> 
> Compiler G compiles this and it works fine.
> 
> Compiler O fails to compile the instantiation with the error msg "The subprogram 
> actuals for the formal package and actual package must statically denote the 
> same entity", pointing to the Unbounded parameter association and referencing 
> ARM 12.7(8). If I add an explicit "=" with "is <>" to Vector_Conversions, then 
> compiler O compiles it and it works fine.
> 
> Possibly one of the compilers has an error, but possibly they're both correct, 
> and I'm wondering if it's possible to tell which is the case.
> 
> (If anyone is interested, the actual generic pkg where I encountered this is 
> PragmARC.Conversions.Vectors from the PragmAda Reusable Components 
> [https://github.com/jrcarter/PragmARC]), and I will supply the actual code that 
> instantiates it on demand. What I've presented is a first attempt at a minimal 
> reproducer.)
> 

-- 
Jeff Carter
"Make sure your code 'does nothing' gracefully."
Elements of Programming Style
196

^ permalink raw reply	[relevance 0%]

* Formal Package Compiler Differences
@ 2023-07-14 19:17  1% Jeffrey R.Carter
  2023-07-14 19:27  0% ` Jeffrey R.Carter
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-07-14 19:17 UTC (permalink / raw)


I have a generic pkg;

with Ada.Containers.Vectors;

generic -- Vector_Conversions
    type Index is range <>;
    type Element is private;
    type Fixed is array (Index range <>) of Element;

    with function "=" (Left : in Element; Right : in Element) return Boolean
    is <>;

    with package Unbounded is new Ada.Containers.Vectors
       (Index_Type => Index, Element_Type => Element);
package Vector_Conversions is
    -- Empty
end Vector_Conversions;

and an instantiation of

with Ada.Containers.Vectors;
with Ada.Strings.Unbounded;
with Vector_Conversions;

procedure Instance_Test is
    use Ada.Strings.Unbounded;

    package String_Lists is new Ada.Containers.Vectors
       (Index_Type => Positive, Element_Type => Unbounded_String);

    type String_List is array (Positive range <>) of Unbounded_String;

    package Conversions is new Vector_Conversions
       (Index     => Positive,
        Element   => Unbounded_String,
        Fixed     => String_List,
        Unbounded => String_Lists);
begin -- Instance_Test
    null;
end Instance_Test;

Compiler G compiles this and it works fine.

Compiler O fails to compile the instantiation with the error msg "The subprogram 
actuals for the formal package and actual package must statically denote the 
same entity", pointing to the Unbounded parameter association and referencing 
ARM 12.7(8). If I add an explicit "=" with "is <>" to Vector_Conversions, then 
compiler O compiles it and it works fine.

Possibly one of the compilers has an error, but possibly they're both correct, 
and I'm wondering if it's possible to tell which is the case.

(If anyone is interested, the actual generic pkg where I encountered this is 
PragmARC.Conversions.Vectors from the PragmAda Reusable Components 
[https://github.com/jrcarter/PragmARC]), and I will supply the actual code that 
instantiates it on demand. What I've presented is a first attempt at a minimal 
reproducer.)

-- 
Jeff Carter
"Make sure your code 'does nothing' gracefully."
Elements of Programming Style
196

^ permalink raw reply	[relevance 1%]

* Re: [ANN] Release of UXStrings 0.5.0
  @ 2023-07-01 14:41  2%   ` Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2023-07-01 14:41 UTC (permalink / raw)


Hello Vincent,

Le 29/06/2023 à 10:49, Vincent D. a écrit :
> Hello Pascal,
> 
> Thank you for this contribution. Here are some comments:
> - since UTFString is a class ("a tagged record type"), why don't you create an abstract root "UXString" and then derive specialized object types ? Like UTF_8_XString, UTF_16_XString, ASCII_XString, Win_1252_XString, Latin_XString, etc.

Well, that's a possibility chosen in some other Ada Strings libraries.
I've preferred that the API of legacy Ada "string" types to be closed to 
those of Ada library so that the adaptation would be easy.
These are not intended to be used outside legacy code adaptation.
Note that I've renamed them as character arrays rather than strings in 
order to accentuate the semantic difference.

> - The default format to convert between different encodings should be UTF-8 as it is now ubiquitous.

Conversions are between UXString and encodings, not between encodings.

>> [...] moreover in the case of strings accentuated in French and strings containing emojis the process times are also improved (factor 7 to 8 by compared to UXStrings1
> - I find quite astonishing to have a factor 8 compared to UTF-8 encoding. Do you have an explanation ? This looks like a poor implementation because UTF-8 encoding is fast and allows direct manipulation in most cases. Maybe because random access is treated as sequential access for UTF-8 encoded strings but this again is poor implementation.

You got it: "most cases". Apart from complex implementations, if you 
want to access a specific position you have to parse from the beginning 
of the UTF-8 data as UXStrings1 does.
UXStrings2 always computes if the resulting data are all ASCII, so the 
access is then direct.
UXStrings3 is internally like an Unicode array, so the access is direct.

Best regards, Pascal.

^ permalink raw reply	[relevance 2%]

* Re: GnatStudio 20230501 released
  @ 2023-05-15 13:58  1%   ` Jeffrey R.Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2023-05-15 13:58 UTC (permalink / raw)


On 2023-05-15 12:41, Rod Kay wrote:
> 
>     Also, in the new binary, 'Find all references' appears to be broken (it 
> finds no references). I guess, the same would apply for the refactoring tool. 
> I've been advised to report the issue and will do so tomorrow. It might help to 
> know if other people also experience the same problem(s), before reporting ?

After typing "with Ada.Strings." I received a use clause as a suggested 
completion. After completing the subprogram name in a subprogram call, I was 
shown something other than the subprogram specification. After typing the '(' 
for the parameter list, I was shown something other than the formal parameters.

-- 
Jeff Carter
"Mixtures of similar characters (letter O and
digit 0, letter I and digit 1, etc.) are unsafe,
as are long identifiers that differ only at the
end."
Elements of Programming Style
187

^ permalink raw reply	[relevance 1%]

* Re: problemn with string'last
  2023-05-05 18:18  0%       ` Manuel Gomez
@ 2023-05-05 20:44  0%         ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2023-05-05 20:44 UTC (permalink / raw)


Manuel Gomez <mgrojo@gmail.com> writes:

> El 5/5/23 a las 18:33, Simon Wright escribió:
>> Manuel Gomez <mgrojo@gmail.com> writes:
>> 
>>> Or like this (doubling the quotes, which is the way to _escape_ the
>>> double quote inside Ada strings):
>>>
>>>     Data         : constant String         := "  PLUS_STRING    :
>>>     CONSTANT STRING(1..3) :=(1 =>'""' , 2 =>'+' , 3 =>'""');";
>> '"' is a single quote character.
>> """" is a string containing one quote character.
>
> Yes, and "'""'" is a string containing a quote as an Ada character
> (when displayed).

Oh, I see. Ugh.

^ permalink raw reply	[relevance 0%]

* Re: problemn with string'last
  2023-05-05 16:33  0%     ` Simon Wright
@ 2023-05-05 18:18  0%       ` Manuel Gomez
  2023-05-05 20:44  0%         ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Manuel Gomez @ 2023-05-05 18:18 UTC (permalink / raw)


El 5/5/23 a las 18:33, Simon Wright escribió:
> Manuel Gomez <mgrojo@gmail.com> writes:
> 
>> Or like this (doubling the quotes, which is the way to _escape_ the
>> double quote inside Ada strings):
>>
>>     Data         : constant String         := "  PLUS_STRING    :
>>     CONSTANT STRING(1..3) :=(1 =>'""' , 2 =>'+' , 3 =>'""');";
> 
> '"' is a single quote character.
> """" is a string containing one quote character.

Yes, and "'""'" is a string containing a quote as an Ada character (when 
displayed).

^ permalink raw reply	[relevance 0%]

* Re: problemn with string'last
  2023-05-05 16:28  1%   ` Manuel Gomez
@ 2023-05-05 16:33  0%     ` Simon Wright
  2023-05-05 18:18  0%       ` Manuel Gomez
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2023-05-05 16:33 UTC (permalink / raw)


Manuel Gomez <mgrojo@gmail.com> writes:

> Or like this (doubling the quotes, which is the way to _escape_ the
> double quote inside Ada strings):
>
>    Data         : constant String         := "  PLUS_STRING    :
>    CONSTANT STRING(1..3) :=(1 =>'""' , 2 =>'+' , 3 =>'""');";

'"' is a single quote character.
"""" is a string containing one quote character.

^ permalink raw reply	[relevance 0%]

* Re: problemn with string'last
  @ 2023-05-05 16:28  1%   ` Manuel Gomez
  2023-05-05 16:33  0%     ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Manuel Gomez @ 2023-05-05 16:28 UTC (permalink / raw)


El 5/5/23 a las 13:17, Jeffrey R.Carter escribió:
> On 2023-05-05 11:51, Daniel Gaudry wrote:
>>    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.
> 

Or like this (doubling the quotes, which is the way to _escape_ the 
double quote inside Ada strings):

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

^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  2022-04-03 16:51  1%   ` Thomas
@ 2023-04-04  0:02  2%     ` Thomas
  0 siblings, 0 replies; 200+ results
From: Thomas @ 2023-04-04  0:02 UTC (permalink / raw)


In article 
<fantome.forums.tDeContes-079FD6.18515603042022@news.free.fr>,
 Thomas <fantome.forums.tDeContes@free.fr.invalid> wrote:

> In article <f9d91cb0-c9bb-4d42-a1a9-0cd546da436cn@googlegroups.com>,
>  Vadim Godunko <vgodunko@gmail.com> wrote:
> 
> > On Sunday, April 18, 2021 at 1:03:14 AM UTC+3, DrPi wrote:
> 
> > > What's the way to manage Unicode correctly ? 


> > Ada doesn't have good Unicode support. :( So, you need to find suitable set 
> > of "workarounds".
> > 
> > There are few different aspects of Unicode support need to be considered:
> > 
> > 1. Representation of string literals. If you want to use non-ASCII 
> > characters 
> > in source code, you need to use -gnatW8 switch and it will require use of 
> > Wide_Wide_String everywhere.
> > 2. Internal representation during application execution. You are forced to 
> > use Wide_Wide_String at previous step, so it will be UCS4/UTF32.
> 
> > It is hard to say that it is reasonable set of features for modern world.
> 
> I don't think Ada would be lacking that much, for having good UTF-8 
> support.
> 
> the cardinal point is to be able to fill a 
> Ada.Strings.UTF_Encoding.UTF_8_String with a litteral.
> (once you got it, when you'll try to fill a Standard.String with a 
> non-Latin-1 character, it'll make an error, i think it's fine :-) )
> 
> does Ada 202x allow it ?


hi !

I think I found a quite nice solution!
(reading <t3lj44$fh5$1@dont-email.me> again)
(not tested yet)


it's not perfect as in the rules of the art,
but it is:

- Ada 2012 compatible
- better than writing UTF-8 Ada code and then telling gnat it is Latin-1
  (in this way it would take UTF_8_String for what it is:
  an array of octets, but it would not detect an invalid UTF-8 string,
  and if someone tells it's really UTF-8 all goes wrong)
- better than being limited to ASCII in string literals
- never need to explicitely declare Wide_Wide_String:
  it's always implicit, for very short time,
  and AFAIK eligible for optimization



package UTF_Encoding is

   subtype UTF_8_String is Ada.Strings.UTF_Encoding.UTF_8_String;

   function "+" (A : in Wide_Wide_String) return UTF_8_String
   renames Ada.Strings.UTF_Encoding.Wide_Wide_Strings.Encode;

end UTF_Encoding;


then we can do:


package User is

   use UTF_Encoding;

   My_String : UTF_8_String := + "Greek characters + smileys";

end User;


if you want to avoid "use UTF_Encoding;",
i think "use type UTF_Encoding.UTF_8_String;" doesn't work,
but this should work:


package UTF_Encoding is

   subtype UTF_8_String is Ada.Strings.UTF_Encoding.UTF_8_String;

   type Literals_For_UTF_8_String is new Wide_Wide_String;

   function "+" (A : in Literals_For_UTF_8_String) return UTF_8_String
   renames Ada.Strings.UTF_Encoding.Wide_Wide_Strings.Encode;

end UTF_Encoding;


package User is

   use type UTF_Encoding.Literals_For_UTF_8_String;

   My_String : UTF_Encoding.UTF_8_String
               := + "Greek characters + smileys";

end User;



what do you think about that ? good idea or not ? :-)

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

^ permalink raw reply	[relevance 2%]

* wait does not perform as expected
@ 2023-02-22 16:34  2% Daniel Gaudry
  0 siblings, 0 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 2%]

* Re: Text_io package's Positive_Count type
  2023-01-11 21:04  2%   ` Mace Ayres
@ 2023-01-11 21:42  0%     ` Niklas Holsti
  0 siblings, 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  2%   ` Mace Ayres
  2023-01-11 21:42  0%     ` Niklas Holsti
  0 siblings, 1 reply; 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 2%]

* Re: Gtk in ada using radiobuttons
  @ 2022-10-17  8:18  1%       ` Jeffrey R.Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2022-10-17  8:18 UTC (permalink / raw)


On 2022-10-17 00:14, Ludovic Brenta wrote:
> "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
>>
>> I know of no reason why the client of a GUI library would ever create
>> a single, independent radio button.  A single radio button is useless.
>> One always wants to create a set of linked buttons.
> 
> Yes but you create the radio buttons one at a time, so one of the
> buttons must be the first you create.

This may be necessary at a low level in the GUI, but there's no reason why the 
client-interface pkg of a library can't provide a higher-level interface. 
Consider the equivalent from Ada GUI 
(https://github.com/jrcarter/Ada_GUI/blob/master/ada_gui.ads):

    type Text_List is array (Positive range <>) of
       Ada.Strings.Unbounded.Unbounded_String
    with
       Dynamic_Predicate => Text_List'First = 1;

    type Orientation_ID is (Horizontal, Vertical);

    function New_Radio_Buttons (Row          : Positive := 1;
                                Column       : Positive := 1;
                                Label        : Text_List;
                                Break_Before : Boolean        := False;
                                Orientation  : Orientation_ID := Vertical)
    return Widget_ID with Pre => Set_Up and Label'Length > 1;
    -- Creates Label'Length radio buttons; Label contains the labels for the
    -- buttons
    -- Orientation = Horizontal results in a row of buttons
    --             = Vertical   has each button after the 1st below the preceding
                                buttons
    -- The button for Label'First will be active
    -- The operations Set_Active and Active for radio buttons take an Index;
    -- Index will refer to the button for Label (Index)

An implementation based on, say, GTK, will have to create the buttons 
individually as the GUI requires, but the client doesn't have to deal with that.

-- 
Jeff Carter
"The men get one hot meal a day: a bowl of steam."
Take the Money and Run
145


^ permalink raw reply	[relevance 1%]

* Gtk in ada using radiobuttons
@ 2022-10-15 14:28  1% ldries46
    0 siblings, 1 reply; 200+ results
From: ldries46 @ 2022-10-15 14:28 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

I realized a set of two radiobuttons that should operate in a group, 
either one or the other but I cannot find the correct way to combine 
these two radio buttons although I can see the dialog in which they are 
used. only both buttons are on and clicking on them cannot set either of 
the off. I tried to find an example how to do this on internet.  I just 
send the used files along. Can anybody help me.



[-- Attachment #2: CPP2Ada_Dialog_Type_Init.ads --]
[-- Type: text/plain, Size: 3285 bytes --]

------------------------------------------------------------------------------
--                                                                          --
--      Copyright (C) 2019 L. Dries                                         --
--                                                                          --
-- This library is free software;  you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your  option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
------------------------------------------------------------------------------
-- Version 1.00 dd. 19-07-2016 created by L. Dries                          --
------------------------------------------------------------------------------
-- Created from Template V1.00 by L. Dries on  23- 10- 2018                 --
------------------------------------------------------------------------------

pragma License(Unrestricted);

with Glib;                  use Glib;
with Gtk.Widget;            use Gtk.Widget;
with Gtk.Dialog;            use Gtk.Dialog;
with Gtk.Window;            use Gtk.Window;
with Gtk.Box;               use Gtk.Box;
with Gtk.Button;            use Gtk.Button;
with Gtk.Frame;             use Gtk.Frame;
with Gtk.Radio_Button;      use Gtk.Radio_Button;

package CPP2Ada_Dialog_Type_Init is

   type Type_Dialog_Record is new Gtk_Dialog_Record with record
      Dialog_Box   : Gtk_Box;
      Button_Box   : Gtk_Box;
      Frame_Box    : Gtk_Box;
      Frame        : Gtk_Frame;
      Radio_Frame  : Gtk_Window_Group;
      Radio_Header : Gtk_Radio_Button;
      Radio_CPP    : Gtk_Radio_Button;
      OK           : Gtk_Button;
      Wrong_File   : Gtk_Button;
   end record;

   type Type_Dialog_Access is access all Type_Dialog_Record'Class;

   Dialogsize_H     : Gint := 150;  -- Width of the dialog window
   Dialogsize_V     : Gint := 80;   -- Height of the dialog window
   Type_Dialog      : Type_Dialog_Access;
   Type_Dialog_Open : Boolean := false;

   procedure Type_New(TypeDialog : out Type_Dialog_Access);
   procedure Type_Init(TypeDialog : access Type_Dialog_Record'Class);

end CPP2Ada_Dialog_Type_Init;

[-- Attachment #3: CPP2Ada_Dialog_Type_Init.adb --]
[-- Type: text/plain, Size: 5933 bytes --]

------------------------------------------------------------------------------
--                                                                          --
--      Copyright (C) 2019 L. Dries                                         --
--                                                                          --
-- This library is free software;  you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your  option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
------------------------------------------------------------------------------
-- Version 1.00 dd. 19-07-2016 created by L. Dries                          --
------------------------------------------------------------------------------
-- Created from Template V1.00 by L. Dries on  23- 10- 2018                 --
------------------------------------------------------------------------------

pragma License(Unrestricted);

with Gtk.Enums;               use Gtk.Enums;
with Gtk.Handlers;            use Gtk.Handlers;
with Gtk.Combo_Box_Text;      use Gtk.Combo_Box_Text;
with Glib.Gslist;             use Glib.Gslist;
with Ada.Strings.Unbounded;   use Ada.Strings.Unbounded;
with CPP2Ada_Dialog_Type_CB; use CPP2Ada_Dialog_Type_CB;
with CPP2Ada_General;         use CPP2Ada_General;
with CPP2Ada_Main_Init;       use CPP2Ada_Main_Init;
with CPP2Ada_Languages;       use CPP2Ada_Languages;

package body CPP2Ada_Dialog_Type_Init is

   package Dialog_CBR is new
     Gtk.Handlers.Return_Callback (Gtk_Dialog_Record, Boolean);
   package Button is new
     Gtk.Handlers.Callback (Gtk_Button_Record);

   procedure Type_New(TypeDialog : out Type_Dialog_Access) is
   begin
      TypeDialog := new Type_Dialog_Record;
      CPP2Ada_Dialog_Type_Init.Type_Init (TypeDialog);
   end Type_New;

   procedure Type_Init(TypeDialog : access Type_Dialog_Record'Class) is
      pragma Suppress (All_Checks);
      Pixmaps_Dir : constant String := "pixmaps/";
      Items : String_List.Glist;
   begin
      Gtk.Dialog.Initialize (TypeDialog);
      TypeDialog.Set_Title (To_String(Type_Dialog_Title(Lan)));
      Set_Position (TypeDialog, Win_Pos_Center);
      Set_Modal (TypeDialog, true);
      Set_Resizable (TypeDialog, false);
      Set_Default_Size (TypeDialog, Dialogsize_H, Dialogsize_V);
      if Set_Icon_From_File(TypeDialog, Icon_Name) then
         On_Type_End(null);
      end if;
      Type_Dialog_Open := true;
      TypeDialog.Dialog_Box := Get_Content_Area(TypeDialog);
      Gtk_New(TypeDialog.Button_Box, Orientation_Horizontal, 0);
      Gtk_New(TypeDialog.Frame_Box, Orientation_Vertical, 0);
      Gtk_New(TypeDialog.Frame, To_String(Type_Frame_Title(lan)));
      Gtk_New (TypeDialog.Radio_Header);
      Gtk_New (TypeDialog.Radio_CPP);
      Pack_Start
        (TypeDialog.Frame_Box,
         TypeDialog.Frame,
         Expand  => True,
         Fill    => True,
         Padding => 0);
      Set_Label(TypeDialog.Radio_Header, To_String(Type_Header_Title(lan)));
      Pack_Start
        (TypeDialog.Frame_Box,
         TypeDialog.Radio_Header,
         Expand  => True,
         Fill    => True,
         Padding => 0);
      Set_Label(TypeDialog.Radio_CPP, To_String(Type_CPP_Title(lan)));
      Pack_Start
        (TypeDialog.Frame_Box,
         TypeDialog.Radio_CPP,
         Expand  => True,
         Fill    => True,
         Padding => 1);
      Gtk_New (TypeDialog.Wrong_File, To_String(Lan_Wrong_File(Lan)));
      Pack_Start
        (TypeDialog.Button_Box,
         TypeDialog.Wrong_File,
         Expand  => True,
         Fill    => True,
         Padding => 0);
      Gtk_New (TypeDialog.OK, To_String(Lan_OK(Lan)));
      Pack_Start
        (TypeDialog.Button_Box,
         TypeDialog.OK,
         Expand  => True,
         Fill    => True,
         Padding => 0);
        Pack_Start
        (TypeDialog.Dialog_Box,
         TypeDialog.Frame_Box,
         Expand  => True,
         Fill    => True,
         Padding => 0);
    Pack_Start
        (TypeDialog.Dialog_Box,
         TypeDialog.Button_Box,
         Expand  => True,
         Fill    => True,
         Padding => 0);
      TypeDialog.Radio_Frame := Get_Group(TypeDialog.Radio_Header'record);
      Set_Group(TypeDialog.Radio_CPP, TypeDialog.Radio_Frame);
      Set_Size_Request(TypeDialog, Dialogsize_H, Dialogsize_V);
      Dialog_CBR.Connect(TypeDialog, "delete_event",
                         Dialog_CBR.To_Marshaller(On_Type_Delete_Event'Access));
      Button.Connect(TypeDialog.OK, "clicked",
                     Button.To_Marshaller(On_Type_OK'Access));
      Button.Connect(TypeDialog.Wrong_File, "clicked",
                     Button.To_Marshaller(On_Type_End'Access));
   end Type_Init;

end CPP2Ada_Dialog_Type_Init;

^ permalink raw reply	[relevance 1%]

* Re: MS going to rust (and Linux too)
  @ 2022-09-24 17:49  1%         ` G.B.
  0 siblings, 0 replies; 200+ results
From: G.B. @ 2022-09-24 17:49 UTC (permalink / raw)


On 24.09.22 15:05, Luke A. Guest wrote:
> On 24/09/2022 12:41, G.B. wrote:
> 
>> Write a really good driver for Linux using Ada 2012 and do not use
>> capital letters in the source text, at least where Linux doesn't.
>> Be silent about the language. Can an Adaist do that, to save the
>> language?
> 
> The biggest problem is that the compiled runtime is compiler version dependent and the pain of making a runtime for linux kernel dev available for each and every compiler version, remember these things can also change on a version change too.

Won't the Ada run-time need very little?
Even the full Ravenscar profile seems to offer too much,
as, for example, Linux kernel drivers need no Ada tasking
at all. Would I want Ada exceptions in drivers?
And to hell with Ada Strings and non-kernel I/O ;-)

If a "kernel-profiled" flavor of protected types will be
an interesting approach to handling events and race
conditions, by basing protected objects on kernel primitives,
then I imagine their implementation to be another nice one
_not_ to brag about, but to just use. Every language is adding
"await" and "async", Java has gone lower than "synchronized"
many versions ago. Every language is not just catching up,
from users' POV...

Ada 2022 is full of popular niceties (cf. "Ada 2022 Overview posted").
Combine them with added insight into program properties
when using SPARK and similar features. The resulting language
needs no mention of the name "Ada" at all in order to be convincing.

^ permalink raw reply	[relevance 1%]

* Re: Non-standard functions in GNAT's Ada.Containers packages?
  2022-09-16 15:00  0%             ` Marius Amado-Alves
  2022-09-16 15:42  2%               ` Egil H H
@ 2022-09-16 18:53  2%               ` Björn Lundin
  1 sibling, 0 replies; 200+ results
From: Björn Lundin @ 2022-09-16 18:53 UTC (permalink / raw)


On 2022-09-16 17:00, Marius Amado-Alves 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.

well, yes . I thought the for looping stuff was the important part, 
since you done want to call Next.

in or of - does it really matter here?

   for C in My_Map.Iterate loop
or
   for C of My_Map loop
is not that hurtful to my eyes.

   for K,V in My_Map.Iterate loop
or
   for K,V of My_Map loop

getting Key and Value as a tuple would be nicer of course


Anyway, I forgot to instantiate the map. Here's a compileable variant



It outputs
Key = AA, Value =  1
Key = AB, Value =  5

----------------

with Ada.Containers.Hashed_Maps;
with Ada.Strings.Hash;
use Ada.Containers;
with Text_Io ; use Text_IO;

procedure Ite is

   subtype Test_Type is String(1..2);

   package Test_Map_Pkg is new Ada.Containers.Hashed_Maps
     (Test_Type,
      Integer,
      Ada.Strings.Hash,
      "=",
      "=");

   My_Map : Test_Map_Pkg.Map;
   use Test_Map_Pkg;
begin
   My_Map.Insert("AA",1);
   My_Map.Insert("AB",5);

   for C in My_Map.Iterate loop
     Put_Line ("Key = " & Key (C) & ", Value = " & Element (C)'Img);
   end loop;

end Ite;



-- 
/Björn

^ permalink raw reply	[relevance 2%]

* Re: Non-standard functions in GNAT's Ada.Containers packages?
  2022-09-16 15:00  0%             ` Marius Amado-Alves
@ 2022-09-16 15:42  2%               ` Egil H H
  2022-09-16 18:53  2%               ` Björn Lundin
  1 sibling, 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 2%]

* Re: Non-standard functions in GNAT's Ada.Containers packages?
  2022-09-16 11:33  1%           ` Björn Lundin
@ 2022-09-16 15:00  0%             ` Marius Amado-Alves
  2022-09-16 15:42  2%               ` Egil H H
  2022-09-16 18:53  2%               ` Björn Lundin
  0 siblings, 2 replies; 200+ results
From: Marius Amado-Alves @ 2022-09-16 15:00 UTC (permalink / raw)


> >> "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.

^ permalink raw reply	[relevance 0%]

* Re: Non-standard functions in GNAT's Ada.Containers packages?
  @ 2022-09-16 11:33  1%           ` Björn Lundin
  2022-09-16 15:00  0%             ` Marius Amado-Alves
  0 siblings, 1 reply; 200+ results
From: Björn Lundin @ 2022-09-16 11:33 UTC (permalink / raw)


On 2022-09-15 19:11, Marius Amado-Alves 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.


but you can as
 >https://programming-idioms.org/idiom/13/iterate-over-map-keys-and-value/1511/ada>

shows (as below)

--Access each key k with its value x from an associative array mymap,
-- and print them.

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;



-- 
/Björn

^ 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: use clauses
  @ 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: Unchecked_Deallocation with tagged types
  @ 2022-04-16  5:00  1%                   ` Thomas
  0 siblings, 0 replies; 200+ results
From: Thomas @ 2022-04-16  5:00 UTC (permalink / raw)


In article <b37bc687-b72f-4bc4-858c-77dc9b878cffn@googlegroups.com>,
 Gautier write-only address <gautier_niouzes@hotmail.com> wrote:

> > Well, P'Free can also be in another package... Of course, we are talking 
> > here only about the direct, actual deallocation. 
> > 
> > If you want to precisely know where deallocation is used, use AdaControl 
> > (for any solution). If you want to be confident that there is no direct 
> > deallocation in a module, the generic wins. 
> 
> It loses because you can have direct, immediate deallocation without the 
> "with Ada.Unchecked_Deallocation" somewhere in the context clause.
> 
> pack.ads:
> 
> with Ada.Unchecked_Deallocation;
> package Pack is
>   type IA is access Integer;
>   procedure Release is new Ada.Unchecked_Deallocation (Integer, IA);
> end;
> 
> ----
> proc.adb:
> 
> with Pack;
> procedure Proc is
>   use Pack;
>   P : IA;
> begin
>   P := new Integer;
>   Release (P);
> end;


what J-P. Rosen meant was that P'Free could be in the body of 
Pack.Release, and then it would not be in Proc either.


perso i like the design with the "generic".
(I'm used to it anyway, although of course it's worse than not needing 
explicit Deallocation.)

but the question is: why in the specification ???


actually i need to know more about your case:

- do you find it ok to put the access types in the package 
specification, and then not have control over what they become?

- or don't you want that, but you regularly become in situations where 
you have no choice (for example because you need components of which you 
are not the author)?


what's your opinion about String_Access and Free in 
Ada.Strings.Unbounded?

I don't understand what they are doing here, since this package is made 
to avoid needing them...

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

^ permalink raw reply	[relevance 1%]

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


"Vadim Godunko" <vgodunko@gmail.com> wrote in message 
news:3962d55d-10e8-4dff-9ad3-847d69c3c337n@googlegroups.com...
...
>I think ((Wide_)Wide_)(Character|String) is obsolete for modern systems and
>programming languages; more cleaner types and API is a requirement now.

...which essentially means Ada is obsolete in your view, as String in 
particular is way too embedded in the definition and the language-defined 
units to use anything else. You'd end up with a mass of conversions to get 
anything done (the main problem with Ada.Strings.Unbounded).

Or I suppose you could replace pretty much the entire library with a new 
one. But now you have two of everything to confuse newcomers and you still 
have a mass of old nonsense weighing down the language and complicating 
implementations.

>The only case when old character/string types is really makes value is low 
>resources embedded systems; ...

...which of course is at least 50% of the use of Ada, and probably closer to 
90% of the money. Any solution for Ada has to continue to meet the needs of 
embedded programmers. For instance, it would need to support fixed, bounded, 
and unbounded versions (solely having unbounded strings would not work for 
many applications, and indeed not just embedded systems need to restrict 
those -- any long-running server has to control dynamic allocation)

>...in other cases their use generates a lot of hidden issues, which is very 
>hard to detect.

At least some of which occur because a string is not an array, and the 
forcible mapping to them never worked very well. The Z-80 Pascals that we 
used to implement the very earliest versions of Ada had more functional 
strings than Ada does (by being bounded and using a library for most 
operations) - they would have been way easier to extend (as the Python ones 
were, as an example).

                        Randy.


^ permalink raw reply	[relevance 2%]

* Re: Ada and Unicode
  2022-04-09  4:05  1%                         ` Randy Brukardt
@ 2022-04-09 10:27  0%                           ` DrPi
    0 siblings, 1 reply; 200+ results
From: DrPi @ 2022-04-09 10:27 UTC (permalink / raw)



Le 09/04/2022 à 06:05, Randy Brukardt a écrit :
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:t2q3cb$bbt$1@gioia.aioe.org...
>> On 2022-04-08 21:19, Simon Wright wrote:
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>>
>>>> On 2022-04-08 10:56, Simon Wright wrote:
>>>>> "Randy Brukardt" <randy@rrsoftware.com> writes:
>>>>>
>>>>>> 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).
>>>>>
>>>>> Just off the top of my head, wouldn't it be better to use
>>>>> UTF32-encoded Wide_Wide_Character internally?
>>>>
>>>> Yep, that is the exactly the problem, a confusion between interface
>>>> and implementation.
>>>
>>> Don't understand. My point was that *when you are implementing this* it
>>> mught be easier to deal with 32-bit charactrs/code points/whatever the
>>> proper jargon is than with UTF8.
>>
>> I think it would be more difficult, because you will have to convert from
>> and to UTF-8 under the hood or explicitly. UTF-8 is de-facto interface
>> standard and I/O standard. That would be 60-70% of all cases you need a
>> string. Most string operations like search, comparison, slicing are
>> isomorphic between code points and octets. So you would win nothing from
>> keeping strings internally as arrays of code points.
> 
> I basically agree with Dmitry here. The internal representation is an
> implementation detail, but it seems likely that you would want to store
> UTF-8 strings directly; they're almost always going to be half the size
> (even for languages using their own characters like Greek) and for most of
> us, they'll be just a bit more than a quarter the size. The amount of bytes
> you copy around matters; the number of operations where code points are
> needed is fairly small.
> 
> The main problem with UTF-8 is representing the code point positions in a
> way that they (a) aren't abused and (b) don't cost too much to calculate.
> Just using character indexes is too expensive for UTF-8 and UTF-16
> representations, and using octet indexes is unsafe (since the splitting a
> character representation is a possibility). I'd probably use an abstract
> character position type that was implemented with an octet index under the
> covers.
> 
> I think that would work OK as doing math on those is suspicious with a UTF
> representation. We're spoiled from using Latin-1 representations, of course,
> but generally one is interested in 5 characters, not 5 octets. And the
> number of octets in 5 characters depends on the string. So most of the sorts
> of operations that I tend to do (for instance from some code I was fixing
> earlier today):
> 
>       if Fort'Length > 6 and then
>          Font(2..6) = "Arial" then
> 
> This would be a bad idea if one is using any sort of universal
> representation -- you don't know how many octets is in the string literal so
> you can't assume a number in the test string. So the slice is dangerous
> (even though in this particular case it would be OK since the test string is
> all Ascii characters -- but I wouldn't want users to get in the habit of
> assuming such things).
> 
> [BTW, the above was a bad idea anyway, because it turns out that the
> function in the Ada library returned bounds that don't start at 1. So the
> slice was usually out of range -- which is why I was looking at the code.
> Another thing that we could do without. Slices are evil, since they *seem*
> to be the right solution, yet rarely are in practice without a lot of
> hoops.]
> 
>> The situation is comparable to Unbounded_Strings. The implementation is
>> relatively simple, but the user must carry the burden of calling To_String
>> and To_Unbounded_String all over the application and the processor must
>> suffer the overhead of copying arrays here and there.
> 
> Yes, but that happens because Ada doesn't really have a string abstraction,
> so when you try to build one, you can't fully do the job. One presumes that
> a new language with a universal UTF-8 string wouldn't have that problem. (As
> previously noted, I don't see much point in trying to patch up Ada with a
> bunch of UTF-8 string packages; you would need an entire new set of
> Ada.Strings libraries and I/O libraries, and then you'd have all of the old
> stuff messing up resolution, using the best names, and confusing everything.
> A cleaner slate is needed.)
> 
>                                     Randy.
> 
> 

In Python-2, there is the same kind of problem. A string is a byte 
array. This is the programmer responsibility to encode/decode to/from 
UTF8/Latin1/... and to manage everything correctly. Litteral strings can 
be considered as encoded or decoded depending on the notation ("" or u"").

In Python-3, a string is a character(glyph ?) array. The internal 
representation is hidden to the programmer.
UTF8/Latin1/... encoded "strings" are of type bytes (byte array).
Writing/reading to/from a file is done with bytes type.
When writing/reading to/from a file in text mode, you have to specify 
the encoding to use. The encoding/decoding is then internally managed.
As a general rule, all "external communications" are done with bytes 
(byte array). This is the programmer responsability to encode/decode 
where needed to convert from/to strings.
The source files (.py) are considered to be UTF8 encoded by default but 
one can declare the actual encoding at the top of the file in a special 
comment tag. When a badly encoded character is found, an exception is 
raised at parsing time. So, literal strings are real strings, not bytes.

I think the Python-3 way of doing things is much more understandable and 
really usable.

On the Ada side, I've still not understood how to correctly deal with 
all this stuff.


Note : In Python-3, bytes type is not reserved to encoded "strings". It 
is a versatile type for what it's named : a byte array.

^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  @ 2022-04-09  4:05  1%                         ` Randy Brukardt
  2022-04-09 10:27  0%                           ` DrPi
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2022-04-09  4:05 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:t2q3cb$bbt$1@gioia.aioe.org...
> On 2022-04-08 21:19, Simon Wright wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>
>>> On 2022-04-08 10:56, Simon Wright wrote:
>>>> "Randy Brukardt" <randy@rrsoftware.com> writes:
>>>>
>>>>> 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).
>>>>
>>>> Just off the top of my head, wouldn't it be better to use
>>>> UTF32-encoded Wide_Wide_Character internally?
>>>
>>> Yep, that is the exactly the problem, a confusion between interface
>>> and implementation.
>>
>> Don't understand. My point was that *when you are implementing this* it
>> mught be easier to deal with 32-bit charactrs/code points/whatever the
>> proper jargon is than with UTF8.
>
> I think it would be more difficult, because you will have to convert from 
> and to UTF-8 under the hood or explicitly. UTF-8 is de-facto interface 
> standard and I/O standard. That would be 60-70% of all cases you need a 
> string. Most string operations like search, comparison, slicing are 
> isomorphic between code points and octets. So you would win nothing from 
> keeping strings internally as arrays of code points.

I basically agree with Dmitry here. The internal representation is an 
implementation detail, but it seems likely that you would want to store 
UTF-8 strings directly; they're almost always going to be half the size 
(even for languages using their own characters like Greek) and for most of 
us, they'll be just a bit more than a quarter the size. The amount of bytes 
you copy around matters; the number of operations where code points are 
needed is fairly small.

The main problem with UTF-8 is representing the code point positions in a 
way that they (a) aren't abused and (b) don't cost too much to calculate. 
Just using character indexes is too expensive for UTF-8 and UTF-16 
representations, and using octet indexes is unsafe (since the splitting a 
character representation is a possibility). I'd probably use an abstract 
character position type that was implemented with an octet index under the 
covers.

I think that would work OK as doing math on those is suspicious with a UTF 
representation. We're spoiled from using Latin-1 representations, of course, 
but generally one is interested in 5 characters, not 5 octets. And the 
number of octets in 5 characters depends on the string. So most of the sorts 
of operations that I tend to do (for instance from some code I was fixing 
earlier today):

     if Fort'Length > 6 and then
        Font(2..6) = "Arial" then

This would be a bad idea if one is using any sort of universal 
representation -- you don't know how many octets is in the string literal so 
you can't assume a number in the test string. So the slice is dangerous 
(even though in this particular case it would be OK since the test string is 
all Ascii characters -- but I wouldn't want users to get in the habit of 
assuming such things).

[BTW, the above was a bad idea anyway, because it turns out that the 
function in the Ada library returned bounds that don't start at 1. So the 
slice was usually out of range -- which is why I was looking at the code. 
Another thing that we could do without. Slices are evil, since they *seem* 
to be the right solution, yet rarely are in practice without a lot of 
hoops.]

> The situation is comparable to Unbounded_Strings. The implementation is 
> relatively simple, but the user must carry the burden of calling To_String 
> and To_Unbounded_String all over the application and the processor must 
> suffer the overhead of copying arrays here and there.

Yes, but that happens because Ada doesn't really have a string abstraction, 
so when you try to build one, you can't fully do the job. One presumes that 
a new language with a universal UTF-8 string wouldn't have that problem. (As 
previously noted, I don't see much point in trying to patch up Ada with a 
bunch of UTF-8 string packages; you would need an entire new set of 
Ada.Strings libraries and I/O libraries, and then you'd have all of the old 
stuff messing up resolution, using the best names, and confusing everything. 
A cleaner slate is needed.)

                                   Randy.


^ permalink raw reply	[relevance 1%]

* Re: Ada_GUI
  @ 2022-04-08 20:56  1%               ` Jeffrey R.Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R.Carter @ 2022-04-08 20:56 UTC (permalink / raw)


On 2022-04-08 16:31, Jeffrey R.Carter wrote:
> 
> I upgraded to a new version of Firefox last night and now favicon.ico is 
> appearing again if I have boot.html without "favicon.ico" in it. It still hangs 
> on startup for the version of boot.html with it.
> 
> ada_gui-gnoga-server-connection.adb at line 574 modifies boot.html to replace 
> "favicon.ico" with the icon name passed to Set_Up, if it contains that string 
> and a non-null icon name was given. Apparently that, or processing the modified 
> file, hangs. If boot.html does not contain that string, apparently favicon.ico 
> is used if it exists.

The replacement is done with procedure String_Replace, in Ada_Gui.Gnoga:

    procedure String_Replace
      (Source      : in out Ada.Strings.Unbounded.Unbounded_String;
       Pattern     : in     String;
       Replacement : in     String);
    --  Replace all instances of Pattern with Replacement in Source

However, there is a logic error in String_Replace: if Pattern = Replacement, it 
becomes an infinite loop. So the default value of Icon for Set_Up, or an 
explicit value of "favicon.ico", results in an infinite loop when this 
replacement is done.

Correcting it to return immediately in that case, and using the version of 
boot.html that contains the text that results in the replacement being 
performed, I get favicon.ico with the default value for Icon, and the specified 
file with an explicit value, provided that I clear cache between runs.

I will update Github with the correction soon, but in the meantime, interested 
persons can make the change themselves to use a different icon file.

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

^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  @ 2022-04-07  1:30  2%               ` Randy Brukardt
    0 siblings, 1 reply; 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 2%]

* Re: Ada and Unicode
  @ 2022-04-03 19:20  2%     ` Thomas
  0 siblings, 0 replies; 200+ results
From: Thomas @ 2022-04-03 19:20 UTC (permalink / raw)


In article <lyfszm5xv2.fsf@pushface.org>,
 Simon Wright <simon@pushface.org> 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

if i understand,  Eric Botcazou is a gnu admin who decided to reject your bug?
i find him very "low portability thinking"!

it is the responsability of compilers and other underlying tools, to manage various underlying OS and FS,
not of the user to avoid those that the compiler devs find too bad!
(or to use the right encoding. i heard that Windows uses UTF-16, do you know about it?)


clearly, To_Lower takes Latin-1.
and this kind of problems would be easier to avoid if string types were stronger ...


after:

package Ada.Strings.UTF_Encoding
    ...
    type UTF_8_String is new String;
    ...
end Ada.Strings.UTF_Encoding;

i would have also made:

package Ada.Directories
    ...
    type File_Name_String is new Ada.Strings.UTF_Encoding.UTF_8_String;
    ...
end Ada.Directories;

with probably a validity check and a Dynamic_Predicate which allows "".

then, i would use File_Name_String in all Ada.Directories and Ada.*_IO.

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

^ permalink raw reply	[relevance 2%]

* Re: Ada and Unicode
  @ 2022-04-03 18:37  1%           ` Thomas
  0 siblings, 0 replies; 200+ results
From: Thomas @ 2022-04-03 18:37 UTC (permalink / raw)


In article <s5n8nj$cec$1@franka.jacob-sparre.dk>,
 "Randy Brukardt" <randy@rrsoftware.com> wrote:

> "Luke A. Guest" <laguest@archeia.com> wrote in message 
> news:s5jute$1s08$1@gioia.aioe.org...
> >
> >
> > On 19/04/2021 13:52, Dmitry A. Kazakov wrote:
> >
> > > It is practical solution. Ada type system cannot express differently
> > represented/constrained string/array/vector subtypes. Ignoring Latin-1 and 
> > using String as if it were an array of octets is the best available 
> > solution.
> > >
> >
> > They're different types and should be incompatible, because, well, they 
> > are. What does Ada have that allows for this that other languages doesn't? 
> > Oh yeah! Types!
> 
> If they're incompatible, you need an automatic way to convert between 
> representations, since these are all views of the same thing (an abstract 
> string type). You really don't want 35 versions of Open each taking a 
> different string type.

i need not 35 versions of Open.
i need a version of Open with an Unicode string type (not Latin-1 - 
preferably UTF-8), which will use Ada.Strings.UTF_Encoding.Conversions 
as far as needed, regarding the underlying API.


> 
> It's the fact that Ada can't do this that makes Unbounded_Strings unusable 
> (well, barely usable).

knowing Ada, i find it acceptable.
i don't say the same about Ada.Strings.UTF_Encoding.UTF_8_String.

> Ada 202x fixes the literal problem at least, but we'd 
> have to completely abandon Unbounded_Strings and use a different library 
> design in order for for it to allow literals. And if you're going to do 
> that, you might as well do something about UTF-8 as well -- but now you're 
> going to need even more conversions. Yuck.

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.


> 
> I think the only true solution here would be based on a proper abstract 
> Root_String type. But that wouldn't work in Ada, since it would be 
> incompatible with all of the existing code out there. Probably would have to 
> wait for a follow-on language.

of course, it would be very nice to have a more thicker language with a 
garbage collector, only 1 String type which allows all what we need, etc.

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

^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  @ 2022-04-03 18:04  1%           ` Thomas
    0 siblings, 1 reply; 200+ results
From: Thomas @ 2022-04-03 18:04 UTC (permalink / raw)


In article <s5k0ai$bb5$1@dont-email.me>, "J-P. Rosen" <rosen@adalog.fr> 
wrote:

> Le 19/04/2021 à 15:00, Luke A. Guest a écrit :
> > They're different types and should be incompatible, because, well, they 
> > are. What does Ada have that allows for this that other languages 
> > doesn't? Oh yeah! Types!
> 
> They are not so different. For example, you may read the first line of a 
> file in a string, then discover that it starts with a BOM, and thus 
> decide it is UTF-8.

could you give me an example of sth that you can do yet, and you could 
not do if UTF_8_String was private, please?
(to discover that it starts with a BOM, you must look at it.)


> 
> BTW, the very first version of this AI had different types, but the ARG 
> felt that it would just complicate the interface for the sake of abusive 
> "purity".

could you explain "abusive purity" please?

i guess it is because of ASCII.
i guess a lot of developpers use only ASCII in a lot of situation, and 
they would find annoying to need Ada.Strings.UTF_Encoding.Strings every 
time.

but I think a simple explicit conversion is acceptable, for a not fully 
compatible type which requires some attention.


the best would be to be required to use ASCII_String as intermediate, 
but i don't know how it could be designed at language level:

UTF_8_Var := UTF_8_String (ASCII_String (Latin_1_Var));
Latin_1_Var:= String (ASCII_String (UTF_8_Var));

and this would be forbidden :
UTF_8_Var := UTF_8_String (Latin_1_Var);

this would ensures to raise Constraint_Error when there are somme 
non-ASCII characters.

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

^ permalink raw reply	[relevance 1%]

* Re: Ada and Unicode
  @ 2022-04-03 16:51  1%   ` Thomas
  2023-04-04  0:02  2%     ` Thomas
  0 siblings, 1 reply; 200+ results
From: Thomas @ 2022-04-03 16:51 UTC (permalink / raw)


In article <f9d91cb0-c9bb-4d42-a1a9-0cd546da436cn@googlegroups.com>,
 Vadim Godunko <vgodunko@gmail.com> wrote:

> On Sunday, April 18, 2021 at 1:03:14 AM UTC+3, DrPi wrote:

> > What's the way to manage Unicode correctly ? 
> > 
> 
> Ada doesn't have good Unicode support. :( So, you need to find suitable set 
> of "workarounds".
> 
> There are few different aspects of Unicode support need to be considered:
> 
> 1. Representation of string literals. If you want to use non-ASCII characters 
> in source code, you need to use -gnatW8 switch and it will require use of 
> Wide_Wide_String everywhere.
> 2. Internal representation during application execution. You are forced to 
> use Wide_Wide_String at previous step, so it will be UCS4/UTF32.

> It is hard to say that it is reasonable set of features for modern world.

I don't think Ada would be lacking that much, for having good UTF-8 
support.

the cardinal point is to be able to fill a 
Ada.Strings.UTF_Encoding.UTF_8_String with a litteral.
(once you got it, when you'll try to fill a Standard.String with a 
non-Latin-1 character, it'll make an error, i think it's fine :-) )

does Ada 202x allow it ?

if not, it would probably be easier if it was
    type UTF_8_String is new String;
instead of
    subtype UTF_8_String is String;


for all subprograms it's quite easy:
we just have to duplicate them with the new type, and to mark the old 
one as Obsolescent.

but, now that "subtype UTF_8_String" exists, i don't know what we can do 
for types.
(is the only way to choose a new name?)


> To 
> fix some of drawbacks of current situation we are developing new text 
> processing library, know as VSS. 
> 
> https://github.com/AdaCore/VSS

(are you working at AdaCore ?)

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

^ permalink raw reply	[relevance 1%]

* [ANN] UXStrings package available (UXS_20220226).
@ 2022-03-01 20:47  2% Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2022-03-01 20:47 UTC (permalink / raw)


Hello,

The objective of UXStrings is Unicode and dynamic length support for 
strings in Ada.

UXStrings API is inspired from Ada.Strings.Unbounded in order to 
minimize adaptation work from existing Ada source codes.

Changes from last publication:
- Ada.Strings.UTF_Encoding.Conversions fix is no longer needed with GNAT 
CE 2021
- A few fix

Available on GitHub (https://github.com/Blady-Com/UXStrings) and also on 
Alire (https://alire.ada.dev/crates/uxstrings.html).

Feedback is welcome on actual use cases.

Regards, Pascal.

^ permalink raw reply	[relevance 2%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  2022-01-10 10:19  1%         ` Marius Amado-Alves
@ 2022-01-11  5:20  0%           ` 1.AAC0832
  0 siblings, 0 replies; 200+ results
From: 1.AAC0832 @ 2022-01-11  5:20 UTC (permalink / raw)


On 1/10/22 5:19 AM, Marius Amado-Alves wrote:
>> Hate typing long things ... made one-liners S2U() and
>> U2S() if you can guess what those are :-)
> 
> This is totally line with the strict typing of Ada (no implicit conversion).
> Most of us abbreviate even more as "+".
> 
> Sorry, but I fail to see any reason the standard Ada.Strings Index functions would not work for your usecases. If possible please provide a succint explanation.

   It is suggested that the "needle" is a String string
   instead of an unbounded. I'll check that out and report
   once I finish my other project.

   Oh well, meanwhile, I just wrote one that DOES work
   with unboundeds.

^ permalink raw reply	[relevance 0%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  @ 2022-01-10 10:19  1%         ` Marius Amado-Alves
  2022-01-11  5:20  0%           ` 1.AAC0832
  0 siblings, 1 reply; 200+ results
From: Marius Amado-Alves @ 2022-01-10 10:19 UTC (permalink / raw)


> Hate typing long things ... made one-liners S2U() and 
> U2S() if you can guess what those are :-) 

This is totally line with the strict typing of Ada (no implicit conversion).
Most of us abbreviate even more as "+".

Sorry, but I fail to see any reason the standard Ada.Strings Index functions would not work for your usecases. If possible please provide a succint explanation.

^ permalink raw reply	[relevance 1%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  2022-01-07 11:48  2%     ` G.B.
@ 2022-01-10  4:49  0%       ` 1.AAC0832
  0 siblings, 0 replies; 200+ results
From: 1.AAC0832 @ 2022-01-10  4:49 UTC (permalink / raw)


On 1/7/22 6:48 AM, G.B. wrote:
> On 07.01.22 03:31, 1.AAC0832 wrote:
> 
>>    Gnat wants FOUR params ... and it's the last "map" related
>>    one that's most mysterious. I'd also seen examples using
>>    only TWO params ... but the compiler balks.
>>
>>    In any case :
>>    Idx := Index
>>          (Source  => S,
>>           Pattern => P,
>>           From    => Idx + 1);
>>
>>    won't compile no matter what you put in "from".
> 
> In case you use the opaque type Unbounded_String everywhere,
> and then the Index function, it is documented to want a String,
> not an Unbounded_String for the Pattern. So, if that's the case,
> get a normal (fixes size array) String from an Unbounded_String
> object first.
> 
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> 
> function pos2 (hay_stack : Unbounded_String; needle : Unbounded_String)
>    return Natural
> is
>     result : Natural;
> begin
>     result := Index (Source  => hay_stack,
>                      Pattern => To_String(needle),
>                      From    => 2);
>     return result;
> end pos2;

   I'll try it as writ.

   Someone else said the "needle" is a straight-up STRING
   however ... and I'd been sending an unbounded.


^ permalink raw reply	[relevance 0%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  2022-01-07  9:49  2%     ` Jeffrey R.Carter
@ 2022-01-10  4:46  0%       ` 1.AAC0832
  0 siblings, 0 replies; 200+ results
From: 1.AAC0832 @ 2022-01-10  4:46 UTC (permalink / raw)


On 1/7/22 4:49 AM, Jeffrey R.Carter wrote:
> On 2022-01-07 03:41, 1.AAC0832 wrote:
>>>
>>> and lists 6 functions named Index (and 2 for Index_Non_Blank). Of 
>>> these I mostly use the one at paragraph 9:
>>>
>>> 9  function Index (Source   : in String;
>>>                     Pattern  : in String;
>>>                     Going    : in Direction := Forward;
>>>                     Mapping  : in Maps.Character_Mapping
>>>                                  := Maps.Identity)
>>>        return Natural;
>>>
>>> with the defaults for the last 2 parameters. Occasionally I've used a 
>>> Going => Backward,
>>
>>
>>    I'm using unbounded strings and there's a version in
>>    that library with the same params - but Gnat seems
>>    to DEMAND the last two params. Might try the fixed
>>    library by casting my unbounded to string ...
> 
> I missed that detail in your original msg. Ada.Strings.Unbounded (ARM 
> A.4.5) has similar Index functions, but note that Source is 
> Unbounded_String and Pattern is String. As Brukardt said, without more 
> detail we can't tell what is really going on, but my experience is that 
> GNAT will not require defaulted parameters. More likely GNAT is trying 
> to do overload resolution when there is no visible subprogram that 
> matches the parameters you are passing; the resulting error msgs are not 
> clear.


   Hmmmm .... I *may* be using another unbounded for the "needle".
   I'll have to check that. Maybe it's not upset about the last
   two params, but the unbounded needle !

   DID write my own function to accomplish the task - one that
   uses unbounded for everything. Works fine. But if a standard
   library function can do it ...

> Experienced Ada users find that Unbounded_String is needed a lot less 
> than is expected by people coming from languages where strings are 
> magic. Unless you need data structures with varying-length strings, you 
> don't often need them.

   Having to re-DECLARE fixed strings over and over, and
   deeper and deeper if you need nested logic, is just
   unbearable. It's UGLY.

   But I wanted to learn a little Ada ...


>>    I've been programming since a tad before the dawn of the
>>    Apples and Commodores - punch cards and serial terminals
>>    wired to the mini-mainframe, FORTRAN, COBOL, that horrible
>>    stuff. For some reason I just can't grock a lot of the Ada
>>    docs. Lots and lots of DESCRIPTIONS about how to do things
>>    but a "picture" is worth a thousand words ...
> 
> I also started out with FORTRAN-66 on punched cards, but my experience 
> is the opposite: Ada (without the features that were mistakes) supports 
> very well the way I engineer S/W.

   Different people find different languages just click
   with the way they think. If it's Ada for you, fine,
   you should be able to accomplish most anything you
   need to do. 'C' and Pascal are more in my way of
   thinking. Did learn Python quite well - but I don't
   use classes.

   But if you want a buzz ... assembler  -) Way back in
   at the dawn of the home computer era I knew this guy,
   classic so-smart-he-was-crazy type, who made a living
   re-writing commercial video game cartridges. He
   wrote everything on a PET ML monitor - in BINARY -
   before burning it to cartridges. Said it gave him a buzz.

   I'll do asssembler for PICs/8051s/etc but not much binary
   unless it's to set flag groups.

   I think the human brain really can't handle anything much
   above the IQ-160 level. After that, one gain requires the
   loss of some other function. The aforementioned guy, I'd
   put him right around IQ-200, and he was NOT "right".

   In any case, thanks for the input. This group is so packed
   with spam that I wondered if anybody real still used it.
   I consider Ada "important" enough to know something about.
   Heh ... though my new Pascal project - have been using
   double-quoted string constants and "&" instead of "+"
   rather often  :-)

   Wanted to do Modula-2/3 experiments - but GNU GM2 isn't
   right on the current distros and throws all kinds of
   errors even with "Hello World". Found an M3 compiler
   but it's going to need some tuning-in.

^ permalink raw reply	[relevance 0%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  2022-01-07  2:31  0%   ` 1.AAC0832
  @ 2022-01-07 11:48  2%     ` G.B.
  2022-01-10  4:49  0%       ` 1.AAC0832
  1 sibling, 1 reply; 200+ results
From: G.B. @ 2022-01-07 11:48 UTC (permalink / raw)


On 07.01.22 03:31, 1.AAC0832 wrote:

>    Gnat wants FOUR params ... and it's the last "map" related
>    one that's most mysterious. I'd also seen examples using
>    only TWO params ... but the compiler balks.
> 
>    In any case :
>    Idx := Index
>          (Source  => S,
>           Pattern => P,
>           From    => Idx + 1);
> 
>    won't compile no matter what you put in "from".

In case you use the opaque type Unbounded_String everywhere,
and then the Index function, it is documented to want a String,
not an Unbounded_String for the Pattern. So, if that's the case,
get a normal (fixes size array) String from an Unbounded_String
object first.

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

function pos2 (hay_stack : Unbounded_String; needle : Unbounded_String)
   return Natural
is
    result : Natural;
begin
    result := Index (Source  => hay_stack,
                     Pattern => To_String(needle),
                     From    => 2);
    return result;
end pos2;

^ permalink raw reply	[relevance 2%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  2022-01-07  2:41  0%   ` 1.AAC0832
@ 2022-01-07  9:49  2%     ` Jeffrey R.Carter
  2022-01-10  4:46  0%       ` 1.AAC0832
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2022-01-07  9:49 UTC (permalink / raw)


On 2022-01-07 03:41, 1.AAC0832 wrote:
>>
>> and lists 6 functions named Index (and 2 for Index_Non_Blank). Of these I 
>> mostly use the one at paragraph 9:
>>
>> 9  function Index (Source   : in String;
>>                     Pattern  : in String;
>>                     Going    : in Direction := Forward;
>>                     Mapping  : in Maps.Character_Mapping
>>                                  := Maps.Identity)
>>        return Natural;
>>
>> with the defaults for the last 2 parameters. Occasionally I've used a Going => 
>> Backward,
> 
> 
>    I'm using unbounded strings and there's a version in
>    that library with the same params - but Gnat seems
>    to DEMAND the last two params. Might try the fixed
>    library by casting my unbounded to string ...

I missed that detail in your original msg. Ada.Strings.Unbounded (ARM A.4.5) has 
similar Index functions, but note that Source is Unbounded_String and Pattern is 
String. As Brukardt said, without more detail we can't tell what is really going 
on, but my experience is that GNAT will not require defaulted parameters. More 
likely GNAT is trying to do overload resolution when there is no visible 
subprogram that matches the parameters you are passing; the resulting error msgs 
are not clear.

Experienced Ada users find that Unbounded_String is needed a lot less than is 
expected by people coming from languages where strings are magic. Unless you 
need data structures with varying-length strings, you don't often need them.

>    I've been programming since a tad before the dawn of the
>    Apples and Commodores - punch cards and serial terminals
>    wired to the mini-mainframe, FORTRAN, COBOL, that horrible
>    stuff. For some reason I just can't grock a lot of the Ada
>    docs. Lots and lots of DESCRIPTIONS about how to do things
>    but a "picture" is worth a thousand words ...

I also started out with FORTRAN-66 on punched cards, but my experience is the 
opposite: Ada (without the features that were mistakes) supports very well the 
way I engineer S/W.

-- 
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail
08

^ permalink raw reply	[relevance 2%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  2022-01-05 13:01  1% ` Jeffrey R.Carter
@ 2022-01-07  2:41  0%   ` 1.AAC0832
  2022-01-07  9:49  2%     ` Jeffrey R.Carter
  0 siblings, 1 reply; 200+ results
From: 1.AAC0832 @ 2022-01-07  2:41 UTC (permalink / raw)


On 1/5/22 8:01 AM, Jeffrey R.Carter wrote:
> On 2022-01-05 01:54, 1.AAC0831 wrote:
>>
>> The docs say to use Index(source,substr,<something>,<something-identity>)
> 
> I don't know what "docs" you mean. Anyone using Ada should be familiar 
> with its standard library, which is documented in Annex A of the ARM at
> 
> http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A.html
> 
> (I provide the link to the AARM as the annotations are sometimes useful.)
> 
> The documentation for Ada.Strings.Fixed is at
> 
> http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A-4-3.html
> 
> and lists 6 functions named Index (and 2 for Index_Non_Blank). Of these 
> I mostly use the one at paragraph 9:
> 
> 9  function Index (Source   : in String;
>                     Pattern  : in String;
>                     Going    : in Direction := Forward;
>                     Mapping  : in Maps.Character_Mapping
>                                  := Maps.Identity)
>        return Natural;
> 
> with the defaults for the last 2 parameters. Occasionally I've used a 
> Going => Backward,


   I'm using unbounded strings and there's a version in
   that library with the same params - but Gnat seems
   to DEMAND the last two params. Might try the fixed
   library by casting my unbounded to string ...

   Anyway, in frustration I just wrote my own. Works good
   and I was able to finish what I wanted to do.


> The Mapping/Test parameters are for specialized needs, such as 
> case-insensitive matching or folding accented characters together, and 
> the default will work if you don't need anything like that.

   I've been programming since a tad before the dawn of the
   Apples and Commodores - punch cards and serial terminals
   wired to the mini-mainframe, FORTRAN, COBOL, that horrible
   stuff. For some reason I just can't grock a lot of the Ada
   docs. Lots and lots of DESCRIPTIONS about how to do things
   but a "picture" is worth a thousand words ...

   But I really really like Pascal better.

^ permalink raw reply	[relevance 0%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  2022-01-05  5:49  1% ` Rod Kay
@ 2022-01-07  2:31  0%   ` 1.AAC0832
    2022-01-07 11:48  2%     ` G.B.
  0 siblings, 2 replies; 200+ results
From: 1.AAC0832 @ 2022-01-07  2:31 UTC (permalink / raw)


On 1/5/22 12:49 AM, Rod Kay wrote:
> On 5/1/22 11:54 am, 1.AAC0831 wrote:
>>
>> Ok ... ADA online documentation is POOR. Lots of
>> definitions, often NO practical examples of even
>> the simplest things. You'd expect more for an
>> "official DOD" language.
>>
> 
> With a duckduckgo search on "ada string index", the first hit is ...
> 
> https://learn.adacore.com/courses/intro-to-ada/chapters/standard_library_strings.html 


   Gnat wants FOUR params ... and it's the last "map" related
   one that's most mysterious. I'd also seen examples using
   only TWO params ... but the compiler balks.

   In any case :
   Idx := Index
         (Source  => S,
          Pattern => P,
          From    => Idx + 1);

   won't compile no matter what you put in "from".

   Oh well, I actually wrote my own. It works just fine
   and I was able to finish what I had in mind. Progressive
   slices of the source string compared against the "needle"
   string with "unbounded_slice" as the cutter-upper. DID
   do a quick pre-scan to see if at least the first char of
   the needle appears in the source and where. We start
   slicing from there, which saves iterations.



> ... which provides a simple example of the 'Index' function.
> 
> 
>> Problem : I want to find out if/where a substring
>> is in another string (lets assume unbounded strings).
>>
>> The docs say to use Index(source,substr,<something>,<something-identity>)
>>
>> Well, I can guess what the first two are. The third probably
>> is "forward" or maybe '1' for "start at first'. However all
>> examples of Index have some kind of mapping param for #4
>> and I've used every search engine and CANNOT figure out what
>> goes in there.
> 
> 
> https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-4-2.html 
> 
> 
> https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-4-3.html 
> 
> 
>     In many/most cases, the default parameters for 'Mapping' are fine.
> 
> 
>> All that works fine. The very last thing I wanted to
>> add was a "is substring in string" function - might
>> return a boolean, but I might cheat and return a real
>> with the listindex .point. position-in-str sort of format.
>>
> 
> function Contains (Source : in String;   Pattern : in String)
> return Boolean
> is
>     use Ada.Strings.Fixed;
> begin
>     return Index (Source, Pattern) /= 0;
> end Contains;> 


   None of my strings are fixed. Those get "stuck" in
   size the first time you assign them and are mostly
   useless IMHO. Tried to use the library with "to_string()"
   but still no joy.

   Anyway, thanks for the input - I'll try a few suggested
   variations from your docs. For now though it's back to
   Lazarus/FPC for a different practical project - the
   kind they pay you for  :-)

   I'm not gonna buy $100 books for a language I was only
   curious about. Adaic seems to have some fair online
   info though.


>     In summary, Ada is one of the the best documented languages in 
> existence. Consider the 'Language Reference Manual', the 'Ada 
> Rationale's and the 'Ada Quality and Style Guide's.
> 
>     Furthermore the resources at 'https://learn.adacore.com' and 
> 'https://www.adacore.com/gems' provide many examples of best practices 
> in specific areas of interest.
> 
>     Finally, forums such as 'comp.lang.ada' and the '#ada' irc channel 
> on the 'irc.libera.chat' server are great places to quickly find answers.
> 
> 
> Regards.

^ permalink raw reply	[relevance 0%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
    2022-01-05  5:49  1% ` Rod Kay
@ 2022-01-05 13:01  1% ` Jeffrey R.Carter
  2022-01-07  2:41  0%   ` 1.AAC0832
  1 sibling, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2022-01-05 13:01 UTC (permalink / raw)


On 2022-01-05 01:54, 1.AAC0831 wrote:
> 
> The docs say to use Index(source,substr,<something>,<something-identity>)

I don't know what "docs" you mean. Anyone using Ada should be familiar with its 
standard library, which is documented in Annex A of the ARM at

http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A.html

(I provide the link to the AARM as the annotations are sometimes useful.)

The documentation for Ada.Strings.Fixed is at

http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A-4-3.html

and lists 6 functions named Index (and 2 for Index_Non_Blank). Of these I mostly 
use the one at paragraph 9:

9  function Index (Source   : in String;
                    Pattern  : in String;
                    Going    : in Direction := Forward;
                    Mapping  : in Maps.Character_Mapping
                                 := Maps.Identity)
       return Natural;

with the defaults for the last 2 parameters. Occasionally I've used a Going => 
Backward,

The Mapping/Test parameters are for specialized needs, such as case-insensitive 
matching or folding accented characters together, and the default will work if 
you don't need anything like that.

-- 
Jeff Carter
"When and now is this guitar piece from Stottlemeyer?
Yes, it's with Mr. Dog in Gertrude's pinball forest."
The World's Funniest Joke
133

^ permalink raw reply	[relevance 1%]

* Re: Ok - WHAT are those "Maps.Identity" things ???
  @ 2022-01-05  5:49  1% ` Rod Kay
  2022-01-07  2:31  0%   ` 1.AAC0832
  2022-01-05 13:01  1% ` Jeffrey R.Carter
  1 sibling, 1 reply; 200+ results
From: Rod Kay @ 2022-01-05  5:49 UTC (permalink / raw)


On 5/1/22 11:54 am, 1.AAC0831 wrote:
> 
> Ok ... ADA online documentation is POOR. Lots of
> definitions, often NO practical examples of even
> the simplest things. You'd expect more for an
> "official DOD" language.
> 

With a duckduckgo search on "ada string index", the first hit is ...

https://learn.adacore.com/courses/intro-to-ada/chapters/standard_library_strings.html

... which provides a simple example of the 'Index' function.


> Problem : I want to find out if/where a substring
> is in another string (lets assume unbounded strings).
> 
> The docs say to use Index(source,substr,<something>,<something-identity>)
> 
> Well, I can guess what the first two are. The third probably
> is "forward" or maybe '1' for "start at first'. However all
> examples of Index have some kind of mapping param for #4
> and I've used every search engine and CANNOT figure out what
> goes in there.


https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-4-2.html

https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-4-3.html

    In many/most cases, the default parameters for 'Mapping' are fine.


> All that works fine. The very last thing I wanted to
> add was a "is substring in string" function - might
> return a boolean, but I might cheat and return a real
> with the listindex .point. position-in-str sort of format.
> 

function Contains (Source : in String;   Pattern : in String)
return Boolean
is
    use Ada.Strings.Fixed;
begin
    return Index (Source, Pattern) /= 0;
end Contains;



    In summary, Ada is one of the the best documented languages in 
existence. Consider the excellent 'Language Reference Manual', the 'Ada 
Rationale's and the 'Ada Quality and Style Guide's.

    Furthermore the resources at 'https://learn.adacore.com' and 
'https://www.adacore.com/gems' provide many examples of best practices 
in specific areas of interest.

    Finally, forums such as 'comp.lang.ada' and the '#ada' irc channel 
on the 'irc.libera.chat' server are great places to quickly find answers.


Regards.

^ permalink raw reply	[relevance 1%]

* Ada.Numerics.Big_Numbers.Big_Integer has a limit of 300 digits?
@ 2021-12-22  5:57  2% 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 2%]

* Re: String Buffer
  @ 2021-12-02 20:51  2% ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2021-12-02 20:51 UTC (permalink / raw)


Kevin Chadwick <kevc3no4@gmail.com> writes:

> In Go they have strings.Builder. I assume that is what Text_Buffer is
> aimed to be. (Actually Go seems to have copied a lot from Ada such as
> AWS API, unless they both are similar to something else like JAVA).
>
> Is Text_Buffer usable today with GCC 11?

If you mean Universal Text Buffers, no. There is
Ada.Strings.Text_Output, but it looks as though that's actually an
internal package to support T'Put_Image - so probably best avoided.

GCC 12 has universal text buffers.

But I don't see that Ada.Strings.Text_Buffers.Unbounded is going to be
any more or less efficient than Unbounded_Strings?

I seem to remember that AdaCore made considerable performance
improvements to Unbounded_Strings, for example copy-on-write sharing.

^ permalink raw reply	[relevance 2%]

* Re: Empty String confusion; Positive and Natural
  2021-11-30  8:21  1%   ` Simon Wright
@ 2021-11-30 12:39  0%     ` ldries46
  0 siblings, 0 replies; 200+ results
From: ldries46 @ 2021-11-30 12:39 UTC (permalink / raw)


Op 30-11-2021 om 9:21 schreef Simon Wright:
> ldries46 <bertus.dries@planet.nl> writes:
>
>> Empty_String : Unbounded_String := To_Unbounded_String("");
> * Given the name, you should probably declare it constant.
>
> * You don't need to initialize it, ARM 4.5(73) [1] says "If an object of
>    type Unbounded_String is not otherwise initialized, it will be
>    initialized to the same value as Null_Unbounded_String".
>
> * Ada.Strings.Unbounded.Null_Unbounded_String is a constant empty
>    string.
>
> [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-4-5.html#p73
You are right. it should be

Empty_String : constant Unbounded_String := To_Unbounded_String("");

^ permalink raw reply	[relevance 0%]

* Re: Empty String confusion; Positive and Natural
    2021-11-30  8:29  2%     ` Simon Wright
@ 2021-11-30  8:34  2%     ` Niklas Holsti
  1 sibling, 0 replies; 200+ results
From: Niklas Holsti @ 2021-11-30  8:34 UTC (permalink / raw)


On 2021-11-30 0:50, Kevin Chadwick wrote:
>> It would clarify your question if you would show the declaration of that
>> record type. Does it use the String type, or the Unbounded_String type?
> 
> Hopefully I will have a doh moment when I get into the office in the
> morning and post code. I am getting a range check exception when I
> assign "" to a standard.String

Although Standard.String is an unconstrained array type (that is, its 
index range is defined as "Positive range <>"), every object of this 
type is constrained to a fixed length, set when the object is created.

So if you have, for example:

    S : String (1 .. 10);

then S'Length is always 10. If you try to assign to S a string of a 
different length, for example "", you will get an exception because the 
lengths do not match.

If you want a string object that is flexible in terms of length, you 
should use the type Ada.Strings.Unbounded.Unbounded_String, or make an 
instance of Ada.Strings.Bounded.Bounded_String with a suitable maximum 
length.

Or you could use a fixed-length string but always pad it with blanks (or 
whatever) up to the fixed length -- see Ada.Strings.Fixed for several 
useful operations on such strings. Depends on what you want...

^ permalink raw reply	[relevance 2%]

* Re: Empty String confusion; Positive and Natural
  @ 2021-11-30  8:29  2%     ` Simon Wright
  2021-11-30  8:34  2%     ` Niklas Holsti
  1 sibling, 0 replies; 200+ results
From: Simon Wright @ 2021-11-30  8:29 UTC (permalink / raw)


Kevin Chadwick <kevc3no4@gmail.com> writes:

>> It would clarify your question if you would show the declaration of
>> that record type. Does it use the String type, or the
>> Unbounded_String type?
>
> Hopefully I will have a doh moment when I get into the office in the
> morning and post code. I am getting a range check exception when I
> assign "" to a standard.String in a record by returning the record
> from a function. Surely, I must have caused it somehow.

If you declare S : String (1 .. 5) and you want to assign a string "foo"
to the whole of S you are forbidden to do so by the language: you have
to assign 5 characters, no more, no fewer.

This can be a royal pain, so we have Ada.Strings.Bounded (if you know
the maximum length) or .Unbounded (if you don't, and can afford more
overhead), both of which support variable-length strings.

^ permalink raw reply	[relevance 2%]

* Re: Empty String confusion; Positive and Natural
  2021-11-30  7:40  2% ` ldries46
@ 2021-11-30  8:21  1%   ` Simon Wright
  2021-11-30 12:39  0%     ` ldries46
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2021-11-30  8:21 UTC (permalink / raw)


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

> Empty_String : Unbounded_String := To_Unbounded_String("");

* Given the name, you should probably declare it constant.

* You don't need to initialize it, ARM 4.5(73) [1] says "If an object of
  type Unbounded_String is not otherwise initialized, it will be
  initialized to the same value as Null_Unbounded_String".

* Ada.Strings.Unbounded.Null_Unbounded_String is a constant empty
  string.

[1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-4-5.html#p73

^ permalink raw reply	[relevance 1%]

* Re: Empty String confusion; Positive and Natural
    @ 2021-11-30  7:40  2% ` ldries46
  2021-11-30  8:21  1%   ` Simon Wright
  1 sibling, 1 reply; 200+ results
From: ldries46 @ 2021-11-30  7:40 UTC (permalink / raw)


Op 29-11-2021 om 18:34 schreef Kevin Chadwick:
> I suspect that I am doing something outside of Ada norms.
>
> Are empty strings avoided in Ada?
>
> I have a function to create a record containing strings amongst other things like a subtyped integer, simply to group the outputs neatly of another function.
>
> If something goes wrong and I run the create function with "" then the strings length is zero. Why is a string type Positive and not Natural, because empty strings are in fact useless?
>
> I guess I shall consider re-engineering my functions, rather than add checks, but all thoughts are welcome.
 From your description, I suspect that you are using different 
declarations for the strings you use for instance while " " in fact is a 
string(1.1) you try to put this in a string(1 .. 5).
To avoid this kind of problems I generally use the package 
Ada.Strings.Unbounded where have possibilities to operate strings 
without caring for the length. Changing between strings and unbounded 
strings is possible with functions in the package.
I would then advice you to create an variable at a position where it is 
reachable from all packages where you use it:
Empty_String : Unbounded_String := To_Unbounded_String("");

^ permalink raw reply	[relevance 2%]

* Re: GNAT Community 2021 and PolyORB: Can't find source for a-sttebu.ali
  @ 2021-11-07 16:38  1% ` Jesper Quorning
  0 siblings, 0 replies; 200+ results
From: Jesper Quorning @ 2021-11-07 16:38 UTC (permalink / raw)


søndag den 7. november 2021 kl. 11.41.35 UTC+1 skrev Frank Jørgen Jørgensen:
> When I compile the bank application in the PolyORB or my own DSA application I get an error referring to a-sttebu.ali which I suspect is something new in GNAT 2021 to handle the improved 'Img functionality in Ada 202X. 

a-sttebu.ali is the package Ada.Strings.Text_Buffers (.ali), which is a recent invention [1].
It is not part of FSF 10.3.0 or FSF 11.2.0.

> I am guessing that the issue here is that the PolyORB is not up to date with GNAT 2021 compiler, or have I missed something in installation? 
I do not know why it is needed by your application.


Jesper

[1] https://learn-staging.adacore.com/courses/ada_2022_whats_new/chapters/image_redefine.html#

^ permalink raw reply	[relevance 1%]

* Re: Postcondition on Strings.Maps.To_Sequence
  2021-08-29  9:38  1% Postcondition on Strings.Maps.To_Sequence mockturtle
@ 2021-09-01 21:07  0% ` Stephen Leake
  0 siblings, 0 replies; 200+ results
From: Stephen Leake @ 2021-09-01 21:07 UTC (permalink / raw)


mockturtle <framefritti@gmail.com> writes:

>    pragma Assert (Edge.On_Input /= Null_Set);
>    pragma Assert (To_Sequence (Edge.On_Input)'Length > 0);
>
> where On_Input is a Character_Set (from Ada.Strings.Maps).
> SPARK accepts the first (that is, it can prove that On_Input is not
> empty), but complains that cannot prove the second (that is, that the
> same set converted to string can give an empty string).  

<snip>

I have used Spark some, but am not an expert.

So just guessing; does Spark actually understand 'Length?

For example, can it prove "a"'Length = 1?
and then To_Sequence (To_Set ('a'))'Length = 1?

> My question is: is this problem due to just a "weak" contract of
> To_Sequence or can actually To_Sequence return the empty string for some
> non Null_Set input?

My guess is neither; Spark is simply not smart enough yet. You'll have
to add some additional intermediate assertions in the body of
To_Sequence, especially one that relates the size of On_Input to the
size of the result string.

-- 
-- Stephe

^ permalink raw reply	[relevance 0%]

* Postcondition on Strings.Maps.To_Sequence
@ 2021-08-29  9:38  1% mockturtle
  2021-09-01 21:07  0% ` Stephen Leake
  0 siblings, 1 reply; 200+ results
From: mockturtle @ 2021-08-29  9:38 UTC (permalink / raw)


Dear.all,
in a code that I am trying to prove with SPARK I have the following two consecutive lines  [I am a beginner with SPARK and I am trying to learn... it is quite fun, if you have masochistic tendencies... ;-)] 

   pragma Assert (Edge.On_Input /= Null_Set);
   pragma Assert (To_Sequence (Edge.On_Input)'Length > 0);

where On_Input is a Character_Set (from Ada.Strings.Maps).
SPARK accepts the first (that is, it can prove that On_Input is not empty), but complains that cannot prove the second (that is, that the same set converted to string can give an empty string).  Actually, the contract of To_Sequence looks like 

function To_Sequence (Set : Character_Set) return Character_Sequence with
     Post =>
       (if Set = Null_Set then To_Sequence'Result'Length = 0)
          and then
       (for all Char in Character =>
          (if Is_In (Char, Set)
           then (for some X of To_Sequence'Result => Char = X)))
          and then
       (for all Char of To_Sequence'Result => Is_In (Char, Set))
          and then
       (for all J in To_Sequence'Result'Range =>
          (for all K in To_Sequence'Result'Range =>
             (if J /= K
              then To_Sequence'Result (J) /= To_Sequence'Result (K))));

and it shows clearly that if the input is Null_Set, then the output is the empty string, but does no explicit claim about the opposite case (if the input is not empty, then the output is not empty as well).

My question is: is this problem due to just a "weak" contract of To_Sequence or can actually To_Sequence return the empty string for some non Null_Set input?

^ permalink raw reply	[relevance 1%]

* Re: XMLAda & unicode symbols
  @ 2021-06-21 15:26  1%     ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2021-06-21 15:26 UTC (permalink / raw)


"196...@googlemail.com" <1963bib@googlemail.com> writes:

> 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.

You might equally have meant angular degrees.

> Both of these exist in Unicode.Names.Letterlike_Symbols, and probably
> elsewhere,but trying to shoehorn these in seems impossible.

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!

You could build a Unicode_Char to UTF_8_String converter using
Ada.Strings.UTF_Encoding.Wide_Wide_Strings, ARM 4.11(30)
http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-4-11.html#p30

> 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.

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). It wants a utf-8-encoded string (though XML/Ada doesn't seem to say
so - RFC 3076 implies it, 7303 (8.1) recommends it).

OK, Text_IO might not prove the point to you, but what about this?

   with Ada.Characters.Latin_1;
   with DOM.Core.Documents;
   with DOM.Core.Elements;
   with DOM.Core.Nodes;
   with DOM.Core;
   with Unicode.CES;
   with Unicode.Encodings;

   procedure Utf is
      Impl : DOM.Core.DOM_Implementation;
      Doc : DOM.Core.Document;
      Dummy, Element : DOM.Core.Node;
      Fifty_Degrees_Latin1 : constant String
        := "50" & Ada.Characters.Latin_1.Degree_Sign;
      Fifty_Degrees_UTF8 : constant Unicode.CES.Byte_Sequence
        := Unicode.Encodings.Convert
          (Fifty_Degrees_Latin1,
           From => Unicode.Encodings.Get_By_Name ("iso-8859-15"),
           To => Unicode.Encodings.Get_By_Name ("utf-8"));
   begin
      Doc := DOM.Core.Create_Document (Impl);

      Element := DOM.Core.Documents.Create_Element (Doc, "utf");
      DOM.Core.Elements.Set_Attribute (Element, "temp", Fifty_Degrees_UTF8);
      Dummy := DOM.Core.Nodes.Append_Child (Doc, Element);

      DOM.Core.Nodes.Print (Doc);
   end Utf;

^ permalink raw reply	[relevance 1%]

* Re: Unable to use "Find all references" with GPS CE 2020 !?
  2020-08-28 10:35  1%     ` Jérôme Haguet
@ 2021-06-18 11:02  0%       ` Jérôme Haguet
  0 siblings, 0 replies; 200+ results
From: Jérôme Haguet @ 2021-06-18 11:02 UTC (permalink / raw)


Le vendredi 28 août 2020 à 12:35:39 UTC+2, Jérôme Haguet a écrit :
> Le mercredi 26 août 2020 à 16:47:08 UTC+2, Jérôme Haguet a écrit : 
> > > > These days, I tried to use GPS from Gnat CE 2020, Windows x64. 
> > > > Unfortunatly, 'Find all references' does not seems to work. 
> > > > It happens on 2 different PCS, with any project I have tried, including the one used in the tutorial. 
> > > I have probably an identical setup: 2 PCs, Windows 10, x64, GNAT CE 2020. On both, 'Find all references' works perfectly, even on a relatively low-powered laptop (2 cores, 2 logical processors, 1.1 GHz). I'd say it works better than previously: in earlier versions, the reference finder gave up due to (perhaps) a time-out, or sometimes didn't want to work at all for the whole session. 
> > > Perhaps your problem is with the path? "C:\GNAT\2020\bin;" or equivalent should come first. It's important if you have multiple GNAT installations. 
> > Thanks Gauthier for the suggestion, I have simplified the PATH. But it did not make it work. 
> > I have made some additional tests with a new computer, and it works successfully. 
> > 
> > But I am still facing the problem with my own computer. 
> > I have found one difference using ProcessExplorer : subprocess ada_language_server.exe is not running after my .gpr project is opened. 
> > It can be successfully started from command line "C:\GNAT\2020\libexec\gnatstudio\als\ada_language_server.exe ...", but it is not started from GPS. 
> > 
> > Any idea where to check ? Any log option to activate ? 
> > 
> > Jérôme
> Seen in http://docs.adacore.com/live/wave/gps/html/gps_ug/environment.html#the-ada-language-server 
> "One known limitation of this server is that it doesn’t support file paths that are not valid UTF-8." 
> 
> And in %USERPROFILE%\home\.gnatstudio\log, I found : 
> ... 
> [GPS.KERNEL.XREF] Set up xref database: :memory: (12:24:25.635) 
> [SQL.INSPECT] Loading data from data into database (12:24:25.651) 
> [ENTITIES.TIMING] Created database: 0.017679200 s (12:24:25.653) 
> [GPS.KERNEL.GPS_KERNEL] Refresh_Context: no child focused (12:24:25.668) 
> [GPS.KERNEL.MSG] Not loading C:\GNAT\2020\share\examples\gnatstudio\tutorial\obj\sdc-msg.xml (12:24:25.668) 
> [GPS.LSP_CLIENT] Starting 'C:\GNAT\2020\libexec\gnatstudio\als\ada_language_server.exe' (12:24:25.834) 
> [HOOKS.EXCEPTIONS] While running project_view_changed:GPS.LSP_MODULE.ON_PROJECT_VIEW_CHANGED 
> _HOOKS.EXCEPTIONS_ raised ADA.STRINGS.UTF_ENCODING.ENCODING_ERROR : bad input at Item (34) 
> ... 
> 
> But I do not understand which file path is not valid UTF-8 : I have used standard installation, and I am testing sdc.gpr, which is provided as a tutorial 
> 
> Regards 
> Jérôme

FYI : 
This specific problem was due to an environment variable with French characters
For example : 
C> set ONE_VAR=Déjà
C> gnatstudio.exe 
....
and ada_language_server.exe process will fail to start when opening the 1st gpr project.

Same problem with gnatstudio from GNAT CE 2021

^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  2021-04-19  9:08  2% ` Stephen Leake
  2021-04-19 11:56  2%   ` Luke A. Guest
@ 2021-04-19 16:14  0%   ` DrPi
  1 sibling, 0 replies; 200+ results
From: DrPi @ 2021-04-19 16:14 UTC (permalink / raw)


Le 19/04/2021 à 11:08, Stephen Leake a écrit :
> DrPi <314@drpi.fr> writes:
> 
>> Any way to use source code encoded in UTF-8 ?
> 
>        for Switches ("non_ascii.ads") use ("-gnatiw", "-gnatW8");
> 
That's interesting.
Using these switches at project level is not OK. Project source files 
not always use the same encoding. Especially when using libraries.
Using these switches at source level is better. A little bit complicated 
to use but better.

> from the gnat user guide, 4.3.1 Alphabetical List of All Switches:
> 
> `-gnati`c''
>       Identifier character set (`c' = 1/2/3/4/8/9/p/f/n/w).  For details
>       of the possible selections for `c', see *note Character Set
>       Control: 4e.
> 
> This applies to identifiers in the source code
> 
> `-gnatW`e''
>       Wide character encoding method (`e'=n/h/u/s/e/8).
> 
> This applies to string and character literals.
> 
>> What's the way to manage Unicode correctly ?
> 
> There are two issues: Unicode in source code, that the compiler must
> understand, and Unicode in strings, that your program must understand.
> 
> (I've never written a program that dealt with utf strings other than
> file names).
>   
> -gnati8 tells the compiler that the source code uses utf-8 encoding.
> 
> -gnatW8 tells the compiler that string literals use utf-8 encoding.
> 
> package Ada.Strings.UTF_Encoding provides some facilities for dealing
> with utf. It does _not_ provide walking a string by code point, which
> would seem necessary.
> 
> We could be more helpful if you show what you are trying to do, you've
> tried, and what errors you got.
> 

^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  2021-04-19 12:13  0%     ` Luke A. Guest
@ 2021-04-19 15:48  0%       ` DrPi
  0 siblings, 0 replies; 200+ results
From: DrPi @ 2021-04-19 15:48 UTC (permalink / raw)


Le 19/04/2021 à 14:13, Luke A. Guest a écrit :
> 
> On 19/04/2021 12:56, Luke A. Guest wrote:
> 
>>
>> package Ada.Strings.UTF_Encoding
>>    ...
>>    subtype UTF_8_String is String;
>>    ...
>> end Ada.Strings.UTF_Encoding;
>>
>> Was absolutely and totally wrong.
> 
> ...and, before someone comes back with "but all the upper half of latin 
> 1" are represented and have the same values." Yes, they do, in Code 
> points which is a 32 bit number. In UTF-8 they are encoded as 2 octets!
A code point has no size. Like universal integers in Ada.

^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  2021-04-19 11:56  2%   ` Luke A. Guest
  2021-04-19 12:13  0%     ` Luke A. Guest
@ 2021-04-19 12:52  0%     ` Dmitry A. Kazakov
    1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2021-04-19 12:52 UTC (permalink / raw)


On 2021-04-19 13:56, Luke A. Guest wrote:
> On 19/04/2021 10:08, Stephen Leake wrote:
>>> What's the way to manage Unicode correctly ?
>>
>> There are two issues: Unicode in source code, that the compiler must
>> understand, and Unicode in strings, that your program must understand.
> 
> And this is there the Ada standard gets it wrong, in the encodings 
> package re utf-8.
> 
> Unicode is a superset of 7-bit ASCII not Latin 1. The high bit in the 
> leading octet indicates whether there are trailing octets. See 
> https://github.com/Lucretia/uca/blob/master/src/uca.ads#L70 for the data 
> layout. The first 128 "characters" in Unicode match that of 7-bit ASCII, 
> not 8-bit ASCII, and certainly not Latin 1. Therefore this:
> 
> package Ada.Strings.UTF_Encoding
>    ...
>    subtype UTF_8_String is String;
>    ...
> end Ada.Strings.UTF_Encoding;
> 
> Was absolutely and totally wrong.

It is practical solution. Ada type system cannot express differently 
represented/constrained string/array/vector subtypes. Ignoring Latin-1 
and using String as if it were an array of octets is the best available 
solution.

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

^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  2021-04-19 11:56  2%   ` Luke A. Guest
@ 2021-04-19 12:13  0%     ` Luke A. Guest
  2021-04-19 15:48  0%       ` DrPi
  2021-04-19 12:52  0%     ` Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: Luke A. Guest @ 2021-04-19 12:13 UTC (permalink / raw)



On 19/04/2021 12:56, Luke A. Guest wrote:

> 
> package Ada.Strings.UTF_Encoding
>    ...
>    subtype UTF_8_String is String;
>    ...
> end Ada.Strings.UTF_Encoding;
> 
> Was absolutely and totally wrong.

...and, before someone comes back with "but all the upper half of latin 
1" are represented and have the same values." Yes, they do, in Code 
points which is a 32 bit number. In UTF-8 they are encoded as 2 octets!

^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  2021-04-19  9:08  2% ` Stephen Leake
@ 2021-04-19 11:56  2%   ` Luke A. Guest
  2021-04-19 12:13  0%     ` Luke A. Guest
  2021-04-19 12:52  0%     ` Dmitry A. Kazakov
  2021-04-19 16:14  0%   ` DrPi
  1 sibling, 2 replies; 200+ results
From: Luke A. Guest @ 2021-04-19 11:56 UTC (permalink / raw)


On 19/04/2021 10:08, Stephen Leake wrote:
>> What's the way to manage Unicode correctly ?
> 
> There are two issues: Unicode in source code, that the compiler must
> understand, and Unicode in strings, that your program must understand.

And this is there the Ada standard gets it wrong, in the encodings 
package re utf-8.

Unicode is a superset of 7-bit ASCII not Latin 1. The high bit in the 
leading octet indicates whether there are trailing octets. See 
https://github.com/Lucretia/uca/blob/master/src/uca.ads#L70 for the data 
layout. The first 128 "characters" in Unicode match that of 7-bit ASCII, 
not 8-bit ASCII, and certainly not Latin 1. Therefore this:

package Ada.Strings.UTF_Encoding
    ...
    subtype UTF_8_String is String;
    ...
end Ada.Strings.UTF_Encoding;

Was absolutely and totally wrong.

^ permalink raw reply	[relevance 2%]

* Re: Ada and Unicode
    @ 2021-04-19  9:08  2% ` Stephen Leake
  2021-04-19 11:56  2%   ` Luke A. Guest
  2021-04-19 16:14  0%   ` DrPi
    2 siblings, 2 replies; 200+ results
From: Stephen Leake @ 2021-04-19  9:08 UTC (permalink / raw)


DrPi <314@drpi.fr> writes:

> Any way to use source code encoded in UTF-8 ?

      for Switches ("non_ascii.ads") use ("-gnatiw", "-gnatW8");

from the gnat user guide, 4.3.1 Alphabetical List of All Switches:

`-gnati`c''
     Identifier character set (`c' = 1/2/3/4/8/9/p/f/n/w).  For details
     of the possible selections for `c', see *note Character Set
     Control: 4e.

This applies to identifiers in the source code

`-gnatW`e''
     Wide character encoding method (`e'=n/h/u/s/e/8).

This applies to string and character literals.

> What's the way to manage Unicode correctly ?

There are two issues: Unicode in source code, that the compiler must
understand, and Unicode in strings, that your program must understand.

(I've never written a program that dealt with utf strings other than
file names).
 
-gnati8 tells the compiler that the source code uses utf-8 encoding.

-gnatW8 tells the compiler that string literals use utf-8 encoding.

package Ada.Strings.UTF_Encoding provides some facilities for dealing
with utf. It does _not_ provide walking a string by code point, which
would seem necessary.

We could be more helpful if you show what you are trying to do, you've
tried, and what errors you got.

-- 
-- Stephe

^ permalink raw reply	[relevance 2%]

* Re: array from static predicate on enumerated type
  @ 2021-03-16  6:58  1%         ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2021-03-16  6:58 UTC (permalink / raw)


"Matt Borchers" <mattborchers@gmail.com> wrote in message 
news:8f7d1d02-c5f0-4ed5-8003-09c6f467d63cn@googlegroups.com...
> On Friday, March 12, 2021 at 11:55:54 PM UTC-5, Randy Brukardt wrote:
>> Just don't use them with obsolete data structures. :-)
>
> I can't tell if you are you being facetious?  If not, can you give me some 
> reasons on
>why you think arrays are obsolete data structures?  To me, they remain one 
>of the
>basic building blocks of all programs.

If you're talking *representation*, then surely arrays are the root of 
everything. But a general purpose programming language should hide 
representation issues as much as possible. For most uses, how a data 
structure is implemented is irrelevant; you want to ask for the fundamental 
data.structure that you need and let the implementation chose the best 
implementation to meet your needs.

And an array is not a fundamental data structure: those are bags and 
sequences and maps (and trees and graphs, but those aren't relevant here). 
Arrays have features of all of these, as well as some others -- they're not 
a fundamental data structure at all.

Moreover, Ada in particular merges in additional features that have little 
to do with data structures, and end up with a mixed up mess where one gets 
surprises from super-null arrays and arrays whose lower isn't 'First and 
holey arrays and other such nonsense.

For instance, the primary reason that Ada cannot have holey arrays is 
because of the slice (mis)feature, in particular because a slice can be 
assigned and (worse) passed as an in out parameter. If one has holey arrays, 
one also would expect to have holey slices (else the language would be quite 
inconsistent). But implementing a holey slice is problematic. For parameter 
passing, pretty much the only way to implement that would be to provide a 
call-back subprogram with every parameter that knows how to write each index 
of the slice. But that would be a classic distributed overhead -- it would 
be incurred for *every* array parameter since one can always create a holey 
slice of an array -- even of a type that is not itself holey. That would 
make passing strings and other arrays *much* more expensive.

Consider the following (illegal) example:

     subtype Trouble is Positive with Static_Predicate => Trouble in 1 | 2 | 
8 | 10;

     Message : String := "Barb Judge!"

     Put_Line (Message(Trouble)); -- Illegal.

If this was legal, the Put_Line would have to output "Bad!". Now, you can 
probably think of ways to implement such a slice, but they'd require copying 
it at the call site. That would work for Put_Line of a few characters, but 
it could be too expensive for larger arrays. Moreover, consider 
Ada.Strings.Overwrite:

     Ada.Strings.Overwrite (Message(Trouble), Position => 2, "ooo");

This would be asking the compiler to somehow figure out that it needs to 
write the 2nd, 8th, and 10th characters of Message. And still be able to 
handle the more normal kinds of slices as well.

And then (if you want a completely consistent language), remember that array 
components can be by-reference types, that are not allowed to be copied when 
passed as parameters.

The point is that holey arrays are a massive can of worms, and its 
impossible to have a consistent language if discontiguous subtypes exist. 
Tucker likes to say that sometimes language design is like a bump under a 
carpet -- you can move the bump around, but you can't get rid of it without 
ripping out the carpet and starting over (with a different language design). 
This is one of those cases.

                                      Randy.


^ permalink raw reply	[relevance 1%]

* Re: [ANN] UXStrings package available (UXS_20210207).
  2021-02-27  9:14  0%   ` Blady
@ 2021-03-06 18:13  0%     ` Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2021-03-06 18:13 UTC (permalink / raw)


Le 27/02/2021 à 10:14, Blady a écrit :
> Le 11/02/2021 à 09:19, Emmanuel Briot a écrit :
>> There is clearly a need here, given the number of implementations out 
>> there. I had also implemented GNATCOLL.Strings 4 years ago, with 
>> similar goals to yours:
>>    - unicode support (via generic formal parameters and traits 
>> packages, so you can use UTF8, UTF16,... internally)
>>    - unbounded strings (with optional copy-on-write)
>>    - task safety (using traits to chose what kind of counter to use)
>>    - performance (small-string optimization: no memory alloc for 
>> strings of 18 characters or less)
>>    - extended API (all missing subprograms from Ada.Strings.Unbounded)
>>    - extensive testing
>>
>> I must admit I am not sure why AdaCore chose to write VSS instead of 
>> improving one of their string implementations (ada.strings.unbounded, 
>> gnatcoll.strings,...)
>> My initial idea had been that it would be possible to provide a nice 
>> generic package, highly configurable via traits, on top of which we 
>> could reimplement ada.strings.unbounded,
>> ada.strings.bounded,...) but I left AdaCore before that could be 
>> accomplished.
> 
> I'm preparing some optimization when the character set is reduced thus 
> the internal structure will adapt to the actual content.
> But the memory management is bad, the set of API is very basic.
> I'll be glad that you can help.
> 
>> I took a look at VSS and find the API confusing. Your API UXString is 
>> at least much clearer (if lacking doc at the moment :-)
> 
> Some documentation has been added in a form of comments of each API:
> https://github.com/Blady-Com/UXStrings/commit/2bee0ab61841f5e319533b67d2747dda66aa9bd7#diff-90cde6014508061fab9d62e58b327815a954859e5da8a1fd655fa4e5854e7ac5 
> 
>> I am hoping that the work on Alire (Ada package manager) will 
>> ultimately help us find one implementation that is good enough for 
>> everyone,
>> and could ultimately become part of the language.

UXStrings is now available with Alire 
(https://alire.ada.dev/crates/uxstrings), in your Alire project, just 
add UXStrings dependency:

% alr with uxstrings

Thus you can import the UXStrings package in your programs.

Pascal.

PS: for French readers, while referencing UXStrings on Alire, I make the 
opportunity to write a short howto with ALire:
https://blady.pagesperso-orange.fr/a_savoir.html#alire


^ permalink raw reply	[relevance 0%]

* Re: [ANN] UXStrings package available (UXS_20210207).
  2021-02-11  8:19  2% ` Emmanuel Briot
@ 2021-02-27  9:14  0%   ` Blady
  2021-03-06 18:13  0%     ` Blady
  0 siblings, 1 reply; 200+ results
From: Blady @ 2021-02-27  9:14 UTC (permalink / raw)


Le 11/02/2021 à 09:19, Emmanuel Briot a écrit :
> There is clearly a need here, given the number of implementations out there. I had also implemented GNATCOLL.Strings 4 years ago, with similar goals to yours:
>    - unicode support (via generic formal parameters and traits packages, so you can use UTF8, UTF16,... internally)
>    - unbounded strings (with optional copy-on-write)
>    - task safety (using traits to chose what kind of counter to use)
>    - performance (small-string optimization: no memory alloc for strings of 18 characters or less)
>    - extended API (all missing subprograms from Ada.Strings.Unbounded)
>    - extensive testing
> 
> I must admit I am not sure why AdaCore chose to write VSS instead of improving one of their string implementations (ada.strings.unbounded, gnatcoll.strings,...)
> My initial idea had been that it would be possible to provide a nice generic package, highly configurable via traits, on top of which we could reimplement ada.strings.unbounded,
> ada.strings.bounded,...) but I left AdaCore before that could be accomplished.

I'm preparing some optimization when the character set is reduced thus 
the internal structure will adapt to the actual content.
But the memory management is bad, the set of API is very basic.
I'll be glad that you can help.

> I took a look at VSS and find the API confusing. Your API UXString is at least much clearer (if lacking doc at the moment :-)

Some documentation has been added in a form of comments of each API:
https://github.com/Blady-Com/UXStrings/commit/2bee0ab61841f5e319533b67d2747dda66aa9bd7#diff-90cde6014508061fab9d62e58b327815a954859e5da8a1fd655fa4e5854e7ac5

> I am hoping that the work on Alire (Ada package manager) will ultimately help us find one implementation that is good enough for everyone,
> and could ultimately become part of the language.

Alire registration is on the way:
https://github.com/alire-project/alire-index/pull/250

Pascal.

^ permalink raw reply	[relevance 0%]

* Re: set_index and and end_of_file with just a stream reference
  @ 2021-02-23 17:21  2%           ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2021-02-23 17:21 UTC (permalink / raw)


On Saturday, February 20, 2021 at 12:08:16 PM UTC-7, 0012com wrote:
> Okay :-) 
> what I wanted is: 
> I read an acronyme in the stream file, if good I input the adjacent record type, otherwise I would advance on the stream until the next acronyme with set_index(stream_access, index(stream_access) + composite_type_stream_size) and read the next acronyme (unbounded_string). 
> Now I just input both objects and verify the acronyme. 
> But I don't like writing an object that maybe won't be used.
Hm, what are your datatypes? Is this ONLY text, or are you able to impose your own structure?
You could have something like this:

-- Instantiated Container Packages.
Package String_Holder is new Ada.Containers.Indefinite_Holders(
       Element_Type => String,
       "="          => Ada.Strings.Equal_Case_Insensitive
      );
Package String_Map is new Ada.Containers.Indefinite_Ordered_Maps(
       "<"          => Ada.Strings.Less_Case_Insensitive,
       "="          => Ada.Strings.Equal_Case_Insensitive,
       Key_Type     => String,
       Element_Type => String
      );

-- The heart of the operating program.
With String_Holder, String_Map;
Package Acronyms is
  -- Because this is it's own type, you can put other things in the record, like a link to the place that it's defined, if needed.
  Type Initialism is new String_Holder.Holder with null record;

  Function Expand( Acronym : Initialism ) return String;
  Procedure Register( Acronym, Expansion : String );
--...
End Acronyms;

Package Body Acronyms is
    Acronym_Map : String_Map.Map;
  Procedure Register( Acronym, Expansion : String ) is
  Begin
    Acronym_Map.Insert( New_Item => Expansion, Key => Acronym );
  End Register;  

  Function Expand( Acronym : Initialism ) return String is
  Begin
    Return Acronym_Map( Acronym );
  Exception
    when others => Return Acronym; -- I forget if it's CONSTRAINT_ERROR or ASSERT_ERROR when the element is not present.
  End Expand;
End Acronyms;

-- in your main Acronym-Stream package...
-- Text_Soup is a variant record for handling portions of an acronym-expanding string; your main data-structure would probably be an Indefinite_Vector of Text_Soup'Class,
-- you might not need Input or output, depending on your usage, but for automatically expanding the initialism you'd need to use Acronyms.Expand.

    Type Text_Soup(<>) is tagged private;
    procedure Output(
       Stream : not null access Ada.Streams.Root_Stream_Type'Class;
       Item   : in Text_Soup'Class);
    function Input(
       Stream : not null access Ada.Streams.Root_Stream_Type'Class)
       return Text_Soup'Class;

   -- Other public operations.
PRIVATE
    For Text_Soup'Class'Input  use Input;
    For Text_Soup'Class'Output use Output;

Type Text_Soup(Length : Natural) is record
  case Length is
    when 0 => Acronym : Initialism;
    when others => Text : String(1..Length);
  end case;
end record;
--...


^ permalink raw reply	[relevance 2%]

* Re: [ANN] UXStrings package available (UXS_20210207).
  2021-02-08 11:22  1% [ANN] UXStrings package available (UXS_20210207) Blady
@ 2021-02-11  8:19  2% ` Emmanuel Briot
  2021-02-27  9:14  0%   ` Blady
  0 siblings, 1 reply; 200+ results
From: Emmanuel Briot @ 2021-02-11  8:19 UTC (permalink / raw)


There is clearly a need here, given the number of implementations out there. I had also implemented GNATCOLL.Strings 4 years ago, with similar goals to yours:
  - unicode support (via generic formal parameters and traits packages, so you can use UTF8, UTF16,... internally)
  - unbounded strings (with optional copy-on-write)
  - task safety (using traits to chose what kind of counter to use)
  - performance (small-string optimization: no memory alloc for strings of 18 characters or less)
  - extended API (all missing subprograms from Ada.Strings.Unbounded)
  - extensive testing

I must admit I am not sure why AdaCore chose to write VSS instead of improving one of their string implementations (ada.strings.unbounded, gnatcoll.strings,...)
My initial idea had been that it would be possible to provide a nice generic package, highly configurable via traits, on top of which we could reimplement ada.strings.unbounded,
ada.strings.bounded,...) but I left AdaCore before that could be accomplished.

I took a look at VSS and find the API confusing. Your API UXString is at least much clearer (if lacking doc at the moment :-)

I am hoping that the work on Alire (Ada package manager) will ultimately help us find one implementation that is good enough for everyone,
and could ultimately become part of the language.

Emmanuel

^ permalink raw reply	[relevance 2%]

* [ANN] UXStrings package available (UXS_20210207).
@ 2021-02-08 11:22  1% Blady
  2021-02-11  8:19  2% ` Emmanuel Briot
  0 siblings, 1 reply; 200+ results
From: Blady @ 2021-02-08 11:22 UTC (permalink / raw)


UXStrings is now available on Github with the whole API implemented 
(version UXS_20210207 [1]).

The objectives are Unicode and dynamic length support for strings, those 
are closed to VSS [2] from Adacore.

However, the UXStrings API is inspired from Ada.Strings.Unbounded in 
order to minimize adaptation work from existing Ada source codes.
Gnoga and Zanyblue has been adapted to UXString with success, see Gnoga 
announcement [3].

This is a first implementation POC. UTF-8 encoding is chosen for 
internal representation. The Strings_Edit [4] library is used for UTF-8 
encoding management.
It has not been intensively tested but this implementation is for 
demonstrate the possible usages of UXString. A test program is also 
provided with some features demonstrated [5].

See readme [6] for full details.

Comments especially on specifications [7] are welcome and others too ;-)

Enjoy, Pascal.

[1] https://github.com/Blady-Com/UXStrings/releases/tag/UXS_20210207
[2] https://github.com/AdaCore/VSS
[3] https://sourceforge.net/p/gnoga/mailman/message/37199377/
[4] http://www.dmitry-kazakov.de/ada/strings_edit.htm
[5] 
https://github.com/Blady-Com/UXStrings/blob/master/tests/test_uxstrings.adb
[6] https://github.com/Blady-Com/UXStrings/blob/master/readme.md
[7] https://github.com/Blady-Com/UXStrings/blob/master/src/uxstrings1.ads

^ permalink raw reply	[relevance 1%]

* Problem with unbounded string input
@ 2021-01-27 19:59  2% 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 2%]

* Re: Lower bounds of Strings
  2021-01-15 10:24  2%   ` Stephen Davies
@ 2021-01-15 11:48  1%     ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2021-01-15 11:48 UTC (permalink / raw)


On 1/15/21 11:24 AM, Stephen Davies wrote:
> 
> I think the root of the problem is that Ada Strings almost always
> start at 1 (note that the functions in Ada.Strings.Fixed all
> return Strings that start at 1), so the cases when they don't
> are at best annoying, and potentially erroneous.

There are many cases where having String values with a lower bound other than 1 
is more convenient, clearer, and less error prone than if all String values have 
a lower bound of 1. For example

loop
    exit when End_Of_File;

    declare
       Line : constant String := Get_Line;
    begin
       Idx := 0;

       loop
          Idx := Index (Line (Idx + 1 .. Line'Last), Pattern);

          exit when Idx = 0;

          Put_Line (Item => Idx'Image);
       end loop;
    end;
end loop;

where Index is Ada.Strings.Fixed.Index. Even without comments and descriptive 
loop and block names, this is reasonably clear.

Compare that to a language where the slice slides to have a lower bound of 1 
(because Index takes a String, which always has a lower bound of 1), and you'll 
see that it is more complex, less clear, and has more opportunities for error 
than current Ada.

A string, being a sequence, should usually have a lower bound of 1, but a decent 
language needs to also allow string values with other lower bounds. Maybe 
something like

type String_Base is array (Positive range <>) of Character;
subtype String is String_Base (Positive range 1 .. <>);

Slices would be String_Base, not String, and Index would take String_Base.

-- 
Jeff Carter
"[I]t is more important to make the purpose
of the code unmistakable than to display
virtuosity. Even storage requirements and
execution time are unimportant by
comparison ..."
Elements of Programming Style
184

^ permalink raw reply	[relevance 1%]

* Re: Lower bounds of Strings
  @ 2021-01-15 10:24  2%   ` Stephen Davies
  2021-01-15 11:48  1%     ` Jeffrey R. Carter
  0 siblings, 1 reply; 200+ results
From: Stephen Davies @ 2021-01-15 10:24 UTC (permalink / raw)


On Thursday, 14 January 2021 at 11:38:29 UTC, AdaMagica wrote:
> Stephen Davies schrieb am Dienstag, 5. Januar 2021 um 12:04:33 UTC+1: 
> I really do not see the problem here. If I want the first element,
> I write X(X'First). Where's the problem? 

Long_String_Name(1..2) is much nicer than
Long_String_Name(Long_String_Name'First..Long_String_Name'First+1)

subtype Some_Range is Positive range 4..5;
Some_String(Some_Range) -- erroneous if Some_String'First/=1

I think the root of the problem is that Ada Strings almost always
start at 1 (note that the functions in Ada.Strings.Fixed all
return Strings that start at 1), so the cases when they don't
are at best annoying, and potentially erroneous.

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)

^ permalink raw reply	[relevance 2%]

* Re: Lower bounds of Strings
  2021-01-09  2:31  1%             ` Randy Brukardt
@ 2021-01-11 21:35  0%               ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2021-01-11 21:35 UTC (permalink / raw)


On Friday, January 8, 2021 at 7:31:40 PM UTC-7, Randy Brukardt wrote:
> "Shark8" wrote in message 
> news:37ada5ff-eee7-408...
> On Thursday, January 7, 2021 at 3:03:54 PM UTC-7, Randy Brukardt wrote:
> ....
> >> So either you are talking about a complication without value, or an 
> >> extremely expensive implementation that doesn't meet the goals for a 
> >> language like Ada. What's the point? 
> >In the matter of the "ABSTRACT INTERFACE" idea, we could define 
> >things in such a way at the language level that: 
> > (1) we could specify the notional types (eg Universal_Float, 
> > Universal_Fixed, etc) 
> >in this system, providing the interface of that type for the usage of the 
> >language; 
> > (2) the specification of these notional-types would allow for less 
> > verbiage in the 
> > standard, and possibly allow proving on the classes they encompass.
> I again don't see the point. The thing that you can't do with the Ada 
> universals is name them, because they don't have a dynamic presence.
But that's the point, it's not about them having a dynamic presence, it's about the ability to classify and categorize.
Kind of like how SPARK's Ghost-code is there to help the prover, not be part of the actual program. Likewise, these ABSTRACT INTERFACES are about making an interface into a type, and doing so consistently, language-wide; kind of like how the containers use special aspects, and also like how generic formal parameters provide minimal information [to the implementation] the less-definite you get.

Perhaps a psuedo-Ada example would work.

Abstract Type DISCRETE_ITEM is (<>);
Abstract Type CONSTRAINED_ITEM is private;
Abstract Type ARRAY_ITEM( Index : DISCRETE_ITEM; Element : CONSTRAINED_ITEM ) is private
  with Access => Element At ARRAY_ITEM(Index); -- Get an ELEMENT by accessing through Index.

>There's 
> no problem proving anything with them, they're already explicitly defined in 
> the RM. All you would be doing is changing the syntax in the subclauses of 
> 4.5. For a totally new language, that might be useful, but I fail to see any 
> benefit for Ada -- it's a lot of work without changing much of anything.
The idea here is to build a system wherein you can (a) define the interfaces of any type, (b) give names to the notional entities [like Universal_Integer], (c) have a construct that is itself robust/provable enough that you can use it to describe/redefine Ada's type-system in its terms, allowing the subclause to be shortened [hopefully], machine translatable, and machine provable.

Much like moving from:
  Function Foo( I : Integer ) return Natural;
  * Foo's parameter must be in the range of -1 and System.Integer'Last;
  * Exception Program_Error is raised on any negative number, except -1.
to:
  Function Foo(I : Integer) return Natural
    with Pre => I in -1..System.Integer'Last or else raise Program_Error;
eliminates English verbiage in favor of language-defined constructs can [hopefully] reduce the size/complexity of the standard, as well as increase the machine-translatability,

> 
> ...
> >> Slices fall on the wrong side of this boundary for me; the nonsense 
> >> required 
> >> to implement them seems reasonable at first but rapidly disappears as of 
> >> the 
> >> many other things that cannot be done in their presense. 
> >Can you give some examples here?
> All of the super-null nonsense occurs because of slices, which slows down 
> any code that uses them.
What do you mean "super-null" nonsense?

>And they are designed to be a "window" into an 
> existing contiguous single-dimensioned array. But syntactically, they appear 
> to be some sort of general concept.
Pretty much the only times I've used slicing [aside from "copy me this substring, and continue on"] have been windowing, though that's typically with a renames.

> Which is why you always hear people 
> talking about slices of multi-dimensional arrays. But those would require 
> dealing with discontiguous chunks of an array, which would have a heavy 
> distributed overhead (since you can assign into them, just making a copy 
> isn't an implementation option). So you would have to pass an assignment 
> "thunk" (compiler-generated subprogram) with any writable array parameter -- 
> even if you never, ever passed a slice to that parameter. The cost would be 
> massive.
Ah, I think I see now.

> >The proliferation of strings in Ada is lamentable; I would love to be able 
> >to 
> >have a set of generics so you could instantiate with 
> >[[Wide_]Wide_]Character 
> >and get the current-Ada hierarchy.
> That wouldn't work for UTF-8 and UTF-16, which makes it pointless at this 
> point. The default String should be UTF-8, the others should be reserved for 
> special cases (interfacing in particular).
Why wouldn't it?
UTF- 8, and UTF-16 are both 8/16 bits, so their underlying "sequence of codepoints" should be 8/16... but then, Unicode makes everyone's lives harder while pretending to be helpful.

>You don't want the default string 
> type to restrict the contents, and you don't want it to waste a lot of 
> space. As Dmitry has said in the past, operations that go at a character at 
> a time through a string are rare, and most of those are properly implemented 
> in Ada.Strings -- users shouldn't be reinventing those wheels in the first 
> place.
Right, which is why if I could I'd 'collapse' the [[Wide_]Wide_]String into a single generic, then we would have less to maintain.
GNAT, for example is *still* missing Wide_Wide_Equal_Case_Insensitive.

> (That's especially true as many of them can do octet operations 
> rather than character indexing.) So UTF-8 is the best trade-off for general 
> use. 
True, but my usage is typically either ASCII, LATIN-1, or Wide_Wide_Character.

^ permalink raw reply	[relevance 0%]

* Re: Lower bounds of Strings
  @ 2021-01-09  2:31  1%             ` Randy Brukardt
  2021-01-11 21:35  0%               ` Shark8
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2021-01-09  2:31 UTC (permalink / raw)


"Shark8" <onewingedshark@gmail.com> wrote in message 
news:37ada5ff-eee7-4082-ad20-3bd65b5a2778n@googlegroups.com...
On Thursday, January 7, 2021 at 3:03:54 PM UTC-7, Randy Brukardt wrote:
....
>> So either you are talking about a complication without value, or an
>> extremely expensive implementation that doesn't meet the goals for a
>> language like Ada. What's the point?
>In the matter of the "ABSTRACT INTERFACE" idea, we could define
>things in such a way at the language level that:
> (1) we could specify the notional types (eg Universal_Float, 
> Universal_Fixed, etc)
>in this system, providing the interface of that type for the usage of the 
>language;
> (2) the specification of these notional-types would allow for less 
> verbiage in the
> standard, and possibly allow proving on the classes they encompass.

I again don't see the point. The thing that you can't do with the Ada 
universals is name them, because they don't have a dynamic presence. There's 
no problem proving anything with them, they're already explicitly defined in 
the RM. All you would be doing is changing the syntax in the subclauses of 
4.5. For a totally new language, that might be useful, but I fail to see any 
benefit for Ada -- it's a lot of work without changing much of anything.

...
>> Slices fall on the wrong side of this boundary for me; the nonsense 
>> required
>> to implement them seems reasonable at first but rapidly disappears as of 
>> the
>> many other things that cannot be done in their presense.
>Can you give some examples here?

All of the super-null nonsense occurs because of slices, which slows down 
any code that uses them. And they are designed to be a "window" into an 
existing contiguous single-dimensioned array. But syntactically, they appear 
to be some sort of general concept. Which is why you always hear people 
talking about slices of multi-dimensional arrays. But those would require 
dealing with discontiguous chunks of an array, which would have a heavy 
distributed overhead (since you can assign into them, just making a copy 
isn't an implementation option). So you would have to pass an assignment 
"thunk" (compiler-generated subprogram) with any writable array parameter --  
even if you never, ever passed a slice to that parameter. The cost would be 
massive.

Any sort of consistent slice interface would run into the same problem, 
since you always want the invariant that

   A(1..3) = A(1) & A(2) & A(3)

and that is extremely difficult to do with writable slices.

If you could only *read* a slice (which would cover 90% of the uses), things 
would be better. But I doubt anyone wants to go in that direction.

>> And they're mainly useful for strings, which are not arrays to begin 
>> with.
>The proliferation of strings in Ada is lamentable; I would love to be able 
>to
>have a set of generics so you could instantiate with 
>[[Wide_]Wide_]Character
>and get the current-Ada hierarchy.

That wouldn't work for UTF-8 and UTF-16, which makes it pointless at this 
point. The default String should be UTF-8, the others should be reserved for 
special cases (interfacing in particular). You don't want the default string 
type to restrict the contents, and you don't want it to waste a lot of 
space. As Dmitry has said in the past, operations that go at a character at 
a time through a string are rare, and most of those are properly implemented 
in Ada.Strings -- users shouldn't be reinventing those wheels in the first 
place. (That's especially true as many of them can do octet operations 
rather than character indexing.) So UTF-8 is the best trade-off for general 
use.

                           Randy.


^ permalink raw reply	[relevance 1%]

* Re: Lower bounds of Strings
  @ 2021-01-05 11:57  1% ` Dmitry A. Kazakov
      2 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-01-05 11:57 UTC (permalink / raw)


On 2021-01-05 12:04, Stephen Davies wrote:
> 
> I'm sure this must have been discussed before, but the issue doesn't
> seem to have been resolved and I think it makes Ada code look ugly and
> frankly reflects poorly on the language.

There is no issue, it must be this way.

> I'm referring to the fact that any subprogram with a String
> parameter, e.g. Expiration_Date, has to use something like
> Expiration_Date (Expiration_Date'First .. Expiration_Date'First + 1)
> to refer to the first two characters rather than simply saying
> Expiration_Date (1..2).

This is a different operation. See function Head in Ada.Strings.Fixed. I 
does what you want.

> Not only is it ugly, but it's potentially dangerous if code uses the
> latter and works for ages until one day somebody passes a slice instead
> of a string starting at 1 (yes, compilers might generate warnings,
> but that doesn't negate the issue, imho).

Yes, slicing using constant values is dangerous. Slicing using indices 
is safe and consitent.

> There must be many possible solutions, without breaking compatibility
> for those very rare occasions where code actually makes use of the
> lower bound of a string.
> 
> e.g. Perhaps the following could be made legal and added to Standard:
> 
> subtype Mono_String is String (1 .. <>);

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

> One question with this would be whether or not to allow procedure bodies
> to specify parameters as Mono_String when the corresponding procedure
> declaration uses String.

There are two separate issues.

1. Explicit forced index sliding. There is no operation for that, though 
it could be easily implemented, e.g.

    function "abs" (S : String) return String is
       Result : constant String (1..S'Length) := S;
    begin
       return Result;
    end "abs";

2. Position-based indices an slices. One could add [] brackets for that 
stuff to make C crowd happy.

    S [1] - First array element
    S (1) - Array element at index 1

Same with slices. Differently to #1, this is would not require excessive 
string copying.

------------------
The real problem is though, that traditionally integer types were used 
for array indices since very beginning of computing.

They never should be because indices are not additive:

    A'First + A'First

is garbage. It is same as with Time and Duration. Time is index (a fixed 
point on the time axis). Duration is position, an offset to some 
unspecified epoch. You can do Time + Duration and Duration + Duration, 
but not Time + Time. So addition must apply to index and position or two 
positions only.

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

^ permalink raw reply	[relevance 1%]

* Re: Messing with access types...
  @ 2020-12-28 19:53  1%         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2020-12-28 19:53 UTC (permalink / raw)


On 2020-12-28 19:56, Marek wrote:

> I think I'll try another approach: just write extra layer in C, which
> will direct communicate with host and will provide prepared data for Ada
> part.

The standard approach is somewhat different:

1. Thin Ada bindings mapping to C, mostly 1-to-1 with minor adjustments, 
e.g.

- replacing BOOL with Ada Boolean
- translating C strings into Ada Strings
- replacing C pointer parameters with Ada out or in out, as appropriate
- making proper functions where C cannot, e.g. returning string results 
where C API uses a buffer to store string copy. The buffer is made 
local, C function is called to fill it. Then the contents is converted 
to Ada string and returned out.

2. On top of that you do thick Ada bindings:

- reasonable interfaces
- all implementation types made private
- return codes replaced with exceptions
- C's malloc/free pairs wrapped by Ada controlled types
- similarly resources seizing/releasing pairs go into controlled types
- messages/events loops encapsulated into Ada tasks
- these tasks are wrapped by a controlled type (AKA active object)

You do not need to change anything on the C side. You can incrementally 
advance #2 as far as you feel necessary since you can always fall back 
to #1.

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

^ permalink raw reply	[relevance 1%]

* Re: Advent of Code Day 6
  2020-12-06  8:39  1% Advent of Code Day 6 John Perry
@ 2020-12-06 11:07  0% ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2020-12-06 11:07 UTC (permalink / raw)


On 12/6/20 9:39 AM, John Perry wrote:
> Today was quite easy, so I used the opportunity to learn about Ada.Strings.Maps, and that made for a much simpler solution to look at.
> 
> I do wonder about the efficiency, though. For instance, the only way I could find to count the number of elements in a Character_Set was by converting it to a Character_Sequence. Is there another way?

Probably one of the set pkgs in Ada.Containers or 
PragmARC.Data_Structures.Sets.Discrete might be a better choice than Character_Set

-- 
Jeff Carter
“[T]here are lots of people out there writing software
that should really be out cleaning toilets instead.”
Brian Catlin
173

^ permalink raw reply	[relevance 0%]

* Advent of Code Day 6
@ 2020-12-06  8:39  1% John Perry
  2020-12-06 11:07  0% ` Jeffrey R. Carter
  0 siblings, 1 reply; 200+ results
From: John Perry @ 2020-12-06  8:39 UTC (permalink / raw)


Today was quite easy, so I used the opportunity to learn about Ada.Strings.Maps, and that made for a much simpler solution to look at.

I do wonder about the efficiency, though. For instance, the only way I could find to count the number of elements in a Character_Set was by converting it to a Character_Sequence. Is there another way?

^ permalink raw reply	[relevance 1%]

* Advent of Code day 2
@ 2020-12-02 22:47  1% Stephen Leake
  0 siblings, 0 replies; 200+ results
From: Stephen Leake @ 2020-12-02 22:47 UTC (permalink / raw)


This is an example of the customer problem spec not being complete; in
the example, all the letter positions are single digit, so my first
draft assumed that, which made finding the values trivial. But then the
real input has 1 or 2 digit numbers.

Handling that took me a while; first I had to actually understand the
semantics of Ada.Strings.Index (Source, Set, Test); "the smallest index
satisfying the test" does _not_ produce a span of characters matching
the test; I should have used Gnatcoll.regexp.

Then I found an indent bug in the development version of emacs ada-mode,
which I took a detour to fix. Which is one reason to do this contest;
writing Ada code is a good way to find bugs in ada-mode. (just out of
curiosity; what development environments are you all using?)

Then for the second puzzle, the fact that Ada String slices _don't_ have
first index 1 confused things; I ended up writing a Slide function to
keep the logic simpler.

Finally got it right.

I was hoping to use 'Reduce in the sled rental count, but GNAT Community
2020 -gnat2020 -gnatX doesn't support that. I did use @, which I like a
lot.

-- 
-- Stephe

Written from unceded ancestral homelands of the Huichiun, an Ohlone
people,for which I pay Shuumi Land Tax

^ permalink raw reply	[relevance 1%]

* Re: Visibility issue
  @ 2020-09-17 21:47  1% ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2020-09-17 21:47 UTC (permalink / raw)


On Friday, September 11, 2020 at 4:37:29 AM UTC-6, Daniel wrote:
> Hello, 
> I want to use a tagged type as a link to communicate users of a library, in the way to make one part visible to them and also to hide some content that is only needed for the implementing of the library.

Here's how that's normally achieved; I've compiled the following but haven't written a testbed/driver:

-- Daniel.ads
Package Daniel with Pure is
   -- Base Interface which all API objects implement.
   Type Abstract_Base is interface;
   
   -- All common methods.
   Function As_String(Object : Abstract_Base) return String is abstract;
   
   -- All Classwide methods.
   Function Print( Object : Abstract_Base'Class ) return String;
   
   
   -- The Callback type.
   Type Callback is access
     procedure(Item : in out Abstract_Base'Class);
   
Private
   -- The classwide "Print" returns the given object's As_String result.
   Function Print( Object : Abstract_Base'Class ) return String is
      (Object.As_String);
End Daniel;

-----------------------------------------------
-- Daniel-Implementation.ads
With
Ada.Finalization,
Ada.Strings.Equal_Case_Insensitive,
Ada.Strings.Less_Case_Insensitive,
Ada.Containers.Indefinite_Ordered_Maps;

Private Package Daniel.Implementation with Preelaborate is
   -- Fwd decl.
   Type Implementation_Base(Name_Length : Positive) is tagged private;
   
   -- Implementation_Base and its descendents have a Name, that is within the
   -- private-portion of the implementation and therefore we need an accessor.
   -- Note: Name is unique and case-insensitive.
   Function Get_Name(Object: Implementation_Base'Class) Return String;

   -- Given a name, this retrieves the object; raises constraint-error if that
   -- name is not associated with an object.
   Function Make  (Name : String) return Implementation_Base'Class;
   Function Create(Name : String) return Implementation_Base;
   Function "="(Left, Right : Implementation_Base) return Boolean;
   
Private
   -- Full decl. Note, also, that this is hidden from the API package.
   Type Implementation_Base(Name_Length : Positive) is
     new Ada.Finalization.Controlled with record
      Name : String(1..Name_Length);
   End record;
   
   -- Finalization; this will remove the registered Name from the object-map.
   overriding
   procedure Finalize   (Object : in out Implementation_Base);

   -- Instantiate the package mapping Names to Objects.
   Package Name_Map is new Ada.Containers.Indefinite_Ordered_Maps(
         Key_Type     => String,
         Element_Type => Implementation_Base'Class,
         "<" => Ada.Strings.Less_Case_Insensitive,
         "=" => "="
        );
   
   -- This is the map that associates objects and their names.
   Core_Map : Name_Map.Map;
End Daniel.Implementation;

------------------------------------------------
-- Daniel-API.ads
Private With
Daniel.Implementation;

Private Package Daniel.API with Preelaborate is
   -- The base API-visable type.
   Type API_Base(<>) is new Abstract_Base with private;
   
   -- Creation functions.
   Function Create(Name : String) return API_Base;
   Function Create(Name : String; Op : Callback) return API_Base;
   
   -- Interface functions.
   Function As_String (Object :        API_Base) return String;
   Procedure Execute  (Object : in out API_Base);
Private
   -- We derive from implementation's base, and add a discriminant for the
   -- callback and another fata-field.
   Type API_Base( CBK : Callback; Length : Positive ) is
     new Daniel.Implementation.Implementation_Base( Name_Length => Length )
     and Abstract_Base with record
      A_1 : Character := 'C';
   end record;
   
   -- We raise an exception when there is no callback given.
   Function Create(Name : String) return API_Base is
     (raise Program_Error with "Callback MUST be specified.");
   
   -- Finally, we construct an object from a call to implementation's create
   -- and fill-in the missing information using an "extension aggrigate".
   Function Create(Name : String; Op : Callback) return API_Base is
     (Implementation.Create(Name) with
      CBK => Op, Length => Name'Length, others => <>);
   
End Daniel.API;

------------------------------------------------------------------------------
-- Daniel-Implementation.adb
with
Ada.Exceptions,
Ada.Finalization;

use
Ada.Finalization;

Package Body Daniel.Implementation is
   Function "=" (Left, Right : String) return Boolean
    renames Ada.Strings.Equal_Case_Insensitive;
   
   Function Get_Name(Object: Implementation_Base'Class) Return String is
     (Object.Name);

   Function Make(Name : String) return Implementation_Base'Class is
   Begin
      Return Core_Map(Name);
   Exception
      when PE : Program_Error =>
         raise Constraint_Error with Ada.Exceptions.Exception_Message(PE);
   End Make;

   Function "="(Left, Right : Implementation_Base) return boolean is
      (Left.Name = Right.Name);
   
   Function Create(Name : String) return Implementation_Base is
   begin
      Return Result : Constant Implementation_Base :=
        (Controlled with Name_Length => Name'Length, Name => Name) do
         Core_Map.Include(New_Item => Result, Key => Name);
      end return;
   end Create;
   
   Procedure Finalize(Object : in out Implementation_Base) is
   Begin
      Core_Map.Delete( Object.Name );
   End Finalize;
   
End Daniel.Implementation;

------------------------------------------------------
-- Daniel-API.adb
Package Body Daniel.API is
   Procedure Execute  (Object : in out API_Base) is
   Begin
      Object.CBK.All(Object);
   End Execute;

   Function As_String (Object : in API_Base) return String is
   Begin
      Return '(' & Object.Get_Name & ", " & Object.A_1 & ')';
   End As_String;
End Daniel.API;

^ permalink raw reply	[relevance 1%]

* Re: Unable to use "Find all references" with GPS CE 2020 !?
  @ 2020-08-28 10:35  1%     ` Jérôme Haguet
  2021-06-18 11:02  0%       ` Jérôme Haguet
  0 siblings, 1 reply; 200+ results
From: Jérôme Haguet @ 2020-08-28 10:35 UTC (permalink / raw)


Le mercredi 26 août 2020 à 16:47:08 UTC+2, Jérôme Haguet a écrit :
> > > These days, I tried to use GPS from Gnat CE 2020, Windows x64. 
> > > Unfortunatly, 'Find all references' does not seems to work. 
> > > It happens on 2 different PCS, with any project I have tried, including the one used in the tutorial. 
> > I have probably an identical setup: 2 PCs, Windows 10, x64, GNAT CE 2020. On both, 'Find all references' works perfectly, even on a relatively low-powered laptop (2 cores, 2 logical processors, 1.1 GHz). I'd say it works better than previously: in earlier versions, the reference finder gave up due to (perhaps) a time-out, or sometimes didn't want to work at all for the whole session. 
> > Perhaps your problem is with the path? "C:\GNAT\2020\bin;" or equivalent should come first. It's important if you have multiple GNAT installations.
> Thanks Gauthier for the suggestion, I have simplified the PATH. But it did not make it work. 
> I have made some additional tests with a new computer, and it works successfully. 
> 
> But I am still facing the problem with my own computer. 
> I have found one difference using ProcessExplorer : subprocess ada_language_server.exe is not running after my .gpr project is opened. 
> It can be successfully started from command line "C:\GNAT\2020\libexec\gnatstudio\als\ada_language_server.exe ...", but it is not started from GPS. 
> 
> Any idea where to check ? Any log option to activate ? 
> 
> Jérôme

Seen in http://docs.adacore.com/live/wave/gps/html/gps_ug/environment.html#the-ada-language-server
"One known limitation of this server is that it doesn’t support file paths that are not valid UTF-8."

And in %USERPROFILE%\home\.gnatstudio\log, I found : 
...
   [GPS.KERNEL.XREF] Set up xref database: :memory: (12:24:25.635)
   [SQL.INSPECT] Loading data from data into database (12:24:25.651)
   [ENTITIES.TIMING] Created database: 0.017679200 s (12:24:25.653)
   [GPS.KERNEL.GPS_KERNEL] Refresh_Context: no child focused (12:24:25.668)
   [GPS.KERNEL.MSG] Not loading C:\GNAT\2020\share\examples\gnatstudio\tutorial\obj\sdc-msg.xml (12:24:25.668)
   [GPS.LSP_CLIENT] Starting 'C:\GNAT\2020\libexec\gnatstudio\als\ada_language_server.exe' (12:24:25.834)
   [HOOKS.EXCEPTIONS] While running project_view_changed:GPS.LSP_MODULE.ON_PROJECT_VIEW_CHANGED
   _HOOKS.EXCEPTIONS_ raised ADA.STRINGS.UTF_ENCODING.ENCODING_ERROR : bad input at Item (34)
...

But I do not understand which file path is not valid UTF-8 : I have used standard installation, and I am testing sdc.gpr, which is provided as a tutorial 

Regards
Jérôme

^ permalink raw reply	[relevance 1%]

* Re: Proposal: Auto-allocation of Indefinite Objects
  @ 2020-07-27 20:31  2%     ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2020-07-27 20:31 UTC (permalink / raw)


On 7/27/20 7:48 PM, Brian Drummond wrote:
> 
> Is there any way we could generalise the (storage, access and lifetime
> aspects of) Unbounded_String for unconstrained arrays and discriminated
> records in such a way that Unbounded_String can be a simple instantiation
> of one of these?

Ada.Strings.Unbounded can be considered a combination of 
Ada.Containers.Indefinite_Holders instantiated for String and 
Ada.Containers.Vectors instantiated with Positive and Character, with some 
additional operations added.

The To_String and To_Unbounded_String operations of Unbounded_String are similar 
to the Element and Replace_Element operations of Holder, which do not exist for 
Vector.

The indexed operations of Unbounded_String are similar to the indexed operations 
of Vector, which do not exist for Holder.

If Ada.Containers.Vectors had an additional generic formal type

    type Fixed is array (Index_Type range <>) of Element_Type;

and 2 new operations

    function To_Fixed (From : Vector) return Fixed;
    function To_Vector (From : Fixed) return Vector;

then we wouldn't need Ada.Strings.Unbounded.

-- 
Jeff Carter
"Blessed is just about anyone with a vested interest in the status quo."
Monty Python's Life of Brian
73

^ permalink raw reply	[relevance 2%]

* Re: Put the access value
  @ 2020-04-20 23:02  2%   ` Robert A Duff
  0 siblings, 0 replies; 200+ results
From: Robert A Duff @ 2020-04-20 23:02 UTC (permalink / raw)


"J-P. Rosen" <rosen@adalog.fr> writes:

> In Ada, a pointer is not an integer and has no 'Image attribute.

Sure it does.  ;-)

So do records and everything else.  See AI12-0020-1 (don't pay attention
to details; they're changing).  I implemented that recently, so the
latest development version of GNAT has it.

This program:

with Ada.Strings.Text_Output.Formatting; use Ada.Strings.Text_Output;
procedure Access_Image is
   type R is record
      This : Integer;
      That : String (1..10);
   end record;

   type A is access all R;

   X : A := new R'(This => 123, That => "helloworld");
begin
   Formatting.Put ("\1, \2\n", X'Image, X.all'Image);
end Access_Image;

prints:

(access 162b740),
(this =>  123,
 that => "helloworld")

> 1) Use Unchecked_Conversion to convert it to an appropriate integer type
>
> 2) use package Address_To_Access conversion to convert your pointer to
> an address, then System.Storage_Elements.To_Integer to convert the
> address to Integer_Address, which is an integer type.

Right, these are good workarounds if you don't have the latest
version.

- Bob

^ permalink raw reply	[relevance 2%]

* Image attribute (yet again)
@ 2020-04-20 15:24  1% Stephen Davies
  0 siblings, 0 replies; 200+ results
From: Stephen Davies @ 2020-04-20 15:24 UTC (permalink / raw)


Whilst looking at the new features for Ada 2020, I spotted:

 An implementation may transform the image generated by the default
 implementation of S'Put_Image for a composite subtype S in the
 following ways: 

 - If S is a composite subtype, the leading character of the image of
   a component value or index value is a space, and the immediately
   preceding character is an open parenthesis, then the space may be
   omitted. The same transformation is also permitted if the leading
   character of the component image is a space (in which case one of
   the two spaces may be omitted). [AARM note: This means that it is
   permitted to generate "(1 => 123, 2 => 456)" instead of
   "( 1 => 123, 2 => 456)".] 

Whilst it is nice that those in charge of the language are finally
acknowledging how annoying the leading space on numeric images is,
that just makes it more galling that they appear to still be doing
about it for scalar numeric types.

I understand that the default behaviour of "'Image" cannot possibly
be changed as it would cause massive incompatibility. But there are
other, simple solutions, e.g. new attribute, optional parameters, ...

One justification that might be given for doing nothing is that
"Trim(S'Image, Left)" can be used instead, but I disagree because:

- It requires adding with/use clauses for Ada.Strings and
  Ada.Strings.Fixed.

- "S'Trim_Image" would still be nicer (just as "First_Element(C)"
  can be used instead of "Element(First(C))".

^ permalink raw reply	[relevance 1%]

* Re: Proposal: Auto-allocation of Indefinite Objects
  2020-04-03 23:45  2% ` Stephen Leake
@ 2020-04-04 10:54  0%   ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2020-04-04 10:54 UTC (permalink / raw)


On 4/4/20 1:45 AM, Stephen Leake wrote:
> 
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> 
> declare
>     Foo : Unbounded_String; -- empty
> begin
>     Foo := To_Unbounded ("hi"); -- allocated on the heap
>     Foo := Foo & To_Unbounded ("bye"); -- allocation grows

Foo := Foo & "bye";

Those should be To_Unbounded_String;

For an issue related to the OP's idea, consider

with System;

procedure Boom is
    type Very_Large_Item is ...;
    type Very_Large_Index is mod System.Max_Binary_Modulus;
    type Very_Large_List is array (Very_Large_Index range <>) of Very_Large_Item;

    Last : constant := ...;

    List : Very_Large_List (0 .. Last);
begin -- Boom
    ... -- Do some thing useful with List
end Boom;

There exists a value N > 0 such that Last = N works and Last = N + 1 results in 
Storage_Error. The actual value of N may vary depending on the compiler, target, 
and the actual machine on which the program is executed.

If you want to handle a List with Last > N, you have to make it an access to 
Very_Large_List unless you care where it is allocated. There is still a value M 
which will result in Storage_Error, but on most machines where you'd try to 
process such a large object, M >> N because on such machines the heap is much 
larger than the stack. Implicit dereferencing makes this change less painful 
than it would be without implicit dereferencing, but there are still usually 
places where explicit dereferencing will be needed, so there is still some pain 
involved even though you don't care where the object is allocated.

It would be nice if there were a compiler option where objects that don't fit on 
the stack would be automatically allocated on the heap, and automatically 
deallocated when they go out of scope.

Similar arguments can be made for a compiler option where all numeric types 
would be accepted, with some implemented in terms of the compiler's ability to 
calculate static expressions exactly, rather than the user having to switch from 
a numeric type to an unbounded-number pkg. This has the added value that such 
pkgs usually lose the automated checks that numeric types have.

All of these issues have been around for some time, and the ARG is aware of them 
and has chosen to take no action. That seems unlikely to change.

-- 
Jeff Carter
"I'm a vicious jungle beast!"
Play It Again, Sam
131

^ permalink raw reply	[relevance 0%]

* Re: Proposal: Auto-allocation of Indefinite Objects
  @ 2020-04-03 23:45  2% ` Stephen Leake
  2020-04-04 10:54  0%   ` Jeffrey R. Carter
    1 sibling, 1 reply; 200+ results
From: Stephen Leake @ 2020-04-03 23:45 UTC (permalink / raw)


On Friday, April 3, 2020 at 3:48:43 PM UTC-7, Stephen Davies wrote:
> Firstly, apologies if this has already been discussed or,
> more likely, if it's a really stupid idea for some reason
> that I haven't thought of.
> 
> My proposal is that it should (sometimes?) be possible to declare
> objects of indefinite types such as String and have the compiler
> automatically declare the space for them without the programmer
> having to resort to access types.

declare
   Foo : String := ...;
begin
   ...
end;

Foo is allocated on the stack; size is taken from the initialization expression.

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

declare
   Foo : Unbounded_String; -- empty
begin
   Foo := To_Unbounded ("hi"); -- allocated on the heap
   Foo := Foo & To_Unbounded ("bye"); -- allocation grows
end;
-- deallocated.

-- Stephe

^ permalink raw reply	[relevance 2%]

* Re: Good/best way to enforce library-level instantiation a generic package
  2020-03-18  9:23  0%       ` Jeffrey R. Carter
@ 2020-03-20 20:37  0%         ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2020-03-20 20:37 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:r4sp9u$m59$1@dont-email.me...
> On 3/18/20 2:03 AM, Randy Brukardt wrote:
>> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message
>> news:r4qbs8$192$1@dont-email.me...
>>>
>>> type T is abstract tagged null record;
>>> Name : constant String := Ada.Tags.Expanded_Name (T);
>>> pragma Assert
>>>     (Ada.Strings.Fixed.Index (Name (Name'First .. Name'Last - 2), ".") = 
>>> 0,
>>>      "Generic_Name must be instantiated at library level");
>>
>> That would reject an instance in a library-level child package, which
>> probably isn't what the OP wants.
>
> An instance IN a child pkg is not a library-level instance, so the OP 
> would want to reject it. But an instance AS a library-level child pkg 
> would be rejected, so this doesn't work.

??? Any declaration in a library-level *package* is a library-level 
declaration. That's not true for other kinds units, of course. 3.10.2(22) 
explains that "library-level" is determined by the accessibility of a 
declaration, and a declaration in a package has the same accessibility as 
the package.

                          Randy.


^ permalink raw reply	[relevance 0%]

* Re: Good/best way to enforce library-level instantiation a generic package
  2020-03-18  1:03  0%     ` Randy Brukardt
@ 2020-03-18  9:23  0%       ` Jeffrey R. Carter
  2020-03-20 20:37  0%         ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2020-03-18  9:23 UTC (permalink / raw)


On 3/18/20 2:03 AM, Randy Brukardt wrote:
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message
> news:r4qbs8$192$1@dont-email.me...
>>
>> type T is abstract tagged null record;
>> Name : constant String := Ada.Tags.Expanded_Name (T);
>> pragma Assert
>>     (Ada.Strings.Fixed.Index (Name (Name'First .. Name'Last - 2), ".") = 0,
>>      "Generic_Name must be instantiated at library level");
> 
> That would reject an instance in a library-level child package, which
> probably isn't what the OP wants.

An instance IN a child pkg is not a library-level instance, so the OP would want 
to reject it. But an instance AS a library-level child pkg would be rejected, so 
this doesn't work.

AFAICT, a child pkg can only be a library-level pkg, so "library-level child 
pkg" seems like overqualification.

-- 
Jeff Carter
"My mind is aglow with whirling, transient nodes of
thought, careening through a cosmic vapor of invention."
Blazing Saddles
85

^ permalink raw reply	[relevance 0%]

* Re: Good/best way to enforce library-level instantiation a generic package
  2020-03-17 11:21  1%   ` Jeffrey R. Carter
@ 2020-03-18  1:03  0%     ` Randy Brukardt
  2020-03-18  9:23  0%       ` Jeffrey R. Carter
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2020-03-18  1:03 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:r4qbs8$192$1@dont-email.me...
...
> You can also use Ada.Tags.Expanded_Name on a tagged type declared in the 
> generic:
>
> type T is abstract tagged null record;
> Name : constant String := Ada.Tags.Expanded_Name (T);
> pragma Assert
>    (Ada.Strings.Fixed.Index (Name (Name'First .. Name'Last - 2), ".") = 0,
>     "Generic_Name must be instantiated at library level");

That would reject an instance in a library-level child package, which 
probably isn't what the OP wants.

                Randy.


^ permalink raw reply	[relevance 0%]

* Re: Good/best way to enforce library-level instantiation a generic package
  2020-03-17  1:21  2% ` Randy Brukardt
@ 2020-03-17 11:21  1%   ` Jeffrey R. Carter
  2020-03-18  1:03  0%     ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2020-03-17 11:21 UTC (permalink / raw)


On 3/17/20 2:21 AM, Randy Brukardt wrote:
> "Vincent Marciante" <vincent.marciante@l3harris.com> wrote in message
> news:6bcc6133-8c8b-4252-a8e6-fd64a5eec2ca@googlegroups.com...
>> I made a generic package that I want only to be instantiated at library
>> level.
>> I'm working on compile-time a way to enforce that desire which involves
>> access
>> type accessibility level checking but have not yet set it up correctly.
>> Is there a better/standard way?
> 
> For Ada 95, deriving from Controlled does the trick, but that was eliminated
> (at substantial cost) in Ada 2005 and later.
> 
> I suppose you could use type String_Access (which is a library-level access
> type) for this:
> 
>     with Ada.Strings.Unbounded;
>     generic
>         ...
>     package My_Generic is
>         -- Real stuff here.
> 
>         Library-Level : constant aliased String := "Library-Level";
>         Check : Ada.Strings.Unbounded.String_Access := Library_Level'Access;
>              -- 'Access is illegal if My_Generic is not instantiated at the
> library level.
>     end My_Generic;

Check should be constant, too.

For the OP:

You can also use Ada.Tags.Expanded_Name on a tagged type declared in the generic:

type T is abstract tagged null record;
Name : constant String := Ada.Tags.Expanded_Name (T);
pragma Assert
    (Ada.Strings.Fixed.Index (Name (Name'First .. Name'Last - 2), ".") = 0,
     "Generic_Name must be instantiated at library level");

-- 
Jeff Carter
"Gentlemen, you can't fight in here. This is the War Room!"
Dr. Strangelove
30

^ permalink raw reply	[relevance 1%]

* Re: Good/best way to enforce library-level instantiation a generic package
  @ 2020-03-17  1:21  2% ` Randy Brukardt
  2020-03-17 11:21  1%   ` Jeffrey R. Carter
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2020-03-17  1:21 UTC (permalink / raw)


"Vincent Marciante" <vincent.marciante@l3harris.com> wrote in message 
news:6bcc6133-8c8b-4252-a8e6-fd64a5eec2ca@googlegroups.com...
>I made a generic package that I want only to be instantiated at library 
>level.
> I'm working on compile-time a way to enforce that desire which involves 
> access
> type accessibility level checking but have not yet set it up correctly.
> Is there a better/standard way?

For Ada 95, deriving from Controlled does the trick, but that was eliminated 
(at substantial cost) in Ada 2005 and later.

I suppose you could use type String_Access (which is a library-level access 
type) for this:

   with Ada.Strings.Unbounded;
   generic
       ...
   package My_Generic is
       -- Real stuff here.

       Library-Level : constant aliased String := "Library-Level";
       Check : Ada.Strings.Unbounded.String_Access := Library_Level'Access;
            -- 'Access is illegal if My_Generic is not instantiated at the 
library level.
   end My_Generic;

String_Access is a silly type that isn't used in the spec of 
Ada.Strings.Unbounded, and thus shouldn't be there, but it does work for 
this use. :-)

You can of course use any library-level access type in your program for this 
purpose; I picked this one 'cause it is already sitting around.

Hope this helps.

                   Randy.


^ permalink raw reply	[relevance 2%]

* Re: GNATCOLL-Mmap example
  @ 2020-01-28 18:53  2%   ` Bob Goddard
  0 siblings, 0 replies; 200+ results
From: Bob Goddard @ 2020-01-28 18:53 UTC (permalink / raw)


On Tuesday, 28 January 2020 08:25:25 UTC, Dmitry A. Kazakov  wrote:
> On 2020-01-25 22:52, Bob Goddard wrote:
> 
> > I need to map the RPi's GPIO memory addresses so that I can do what I need to do.
> 
> See files under:
> 
>     /sys/class/gpio
> 
> You can use standard Ada I/O to read and set GPIO pins. E.g.
> 
>     /sys/class/gpio/gpio/XXX/value

This was the way I started, but could not get it to read anything. It just blocks trying to read a single character. My c code works fine using the wiringPi libs.

Stephen Leake:
Mmap is used to read more than just disk files. Opening /dev/mem, or even /dev/gpiomem, is just another file.

Regardless, I got it to work. The moral of the story, is never assume example code in the library source works, or even can compile. I got it running a couple of days ago, and have since spent time banging my head against a wall.

This works, both with System.Mmap & GNATCOLL.Mmap...

with Ada.Unchecked_Conversion;
with Ada.Text_IO;
with GNATCOLL.Mmap; use GNATCOLL.Mmap;
with Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO;

procedure Mmaptest is
   package Mmap renames GNATCOLL.Mmap;

   File : Mmap.Mapped_File;
   Reg  : Mmap.Mapped_Region;
   Str  : Mmap.Str_Access;
   Offs : Mmap.File_Size := 0;
   Page : constant Mmap.File_Size := Mmap.File_Size (Mmap.Get_Page_Size);
begin
   File := Mmap.Open_Write ("/tmp/file_on_disk");
   
   while Offs < Mmap.Length (File) loop
      Mmap.Read (File, Reg, Offs, Length => Page, Mutable => False);
      Str := Mmap.Data (Reg);
      Ada.Strings.Unbounded.Text_IO.Put (Ada.Strings.Unbounded.To_Unbounded_String (
                                              Str (Integer (Offs - Mmap.Offset (Reg)) + 1 .. Mmap.Last (Reg)))
                                             );
      Offs := Offs + Page; --  Mmap.File_Size (Mmap.Last (Reg));
   end loop;
   
   Mmap.Free (Reg);
   
   if Reg /= Mmap.Invalid_Mapped_Region then
      Ada.Text_IO.Put_Line ("Mapped region still valid");
   end if;
   
   Mmap.Close (File);
   
   if File /= Mmap.Invalid_Mapped_File then
      Ada.Text_IO.Put_Line ("Mapped file still valid");
   end if;
end Mmaptest;

^ permalink raw reply	[relevance 2%]

* Re: I need to show extended Ascii codes in GtkAda environment
  2019-11-22 21:22  2%   ` Randy Brukardt
@ 2019-11-22 21:36  2%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2019-11-22 21:36 UTC (permalink / raw)


On 2019-11-22 22:22, Randy Brukardt wrote:

>      Slash_Null : constant String :=
>            Ada.Strings.UTF_Encoding.Strings.Encode (Character'Val(216) & "");

Or using array aggregate

    Ada.Strings.UTF_Encoding.Strings.Encode ((1=>Character'Val(216)));

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


^ permalink raw reply	[relevance 2%]

* Re: I need to show extended Ascii codes in GtkAda environment
  @ 2019-11-22 21:22  2%   ` Randy Brukardt
  2019-11-22 21:36  2%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2019-11-22 21:22 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:qr8qbp$15gp$1@gioia.aioe.org...
> On 2019-11-22 14:09, L Dries wrote:
>> In a GtkAda environment I have the need to present some characters or 
>> strings with characters in the Extended character Ascii range for 
>> instance O with slash (216). I create a constant character with
>>
>> Slash_null : constant string(1 .. 1) := "" & character'Val(216);
>
> GTK is UTF-8. You must encode and decode anything that is not ASCII 7-bit. 
> [A pragmatic approach is to ignore the reference manual and treat all 
> strings UTF-8 rather than mandated Latin 1.]
>
> Anyway, assuming you need the LATIN CAPITAL LETTER O WITH STROKE character 
> (code point 216), encoded in UTF-8 it is C3 98. Note, two octets. Thus:
>
>    Slash_Null : constant String :=
>                    Character'Val (16#C3#) & Character'Val (16#98#);
>
> With Strings Edit for Ada you could also write:
>
>    Slash_Null : constant String := Strings_Edit.UTF8.Image (216);

You could of course use Ada.Strings.UTF_Encoding (a standard part of Ada 
2012) to do this as well, by converting the "standard" Latin-1 String to 
UTF-8:

    with Ada.Strings.UTF_Encoding.Strings;
    ...
    Slash_Null : constant String :=
          Ada.Strings.UTF_Encoding.Strings.Encode (Character'Val(216) & "");

Note that concatenating the character with the null string effectively 
creates a string with one character. (You could of course use the literal 
directly if your editor/implementation supports that - tough to do that on 
the Internet, though.)

                                         Randy.





^ permalink raw reply	[relevance 2%]

* Re: How to Iterate over all elements of a hashed_map.
  2019-10-29 15:02  0%   ` joakimds
@ 2019-10-29 21:56  0%     ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2019-10-29 21:56 UTC (permalink / raw)


<joakimds@kth.se> wrote in message 
news:1559a685-7483-4f2f-8674-d7b61c23bfe8@googlegroups.com...
> Den tisdag 29 oktober 2019 kl. 15:20:43 UTC+1 skrev Alain De Vos:
>> I found code which takes a different approach, here there is a function 
>> .Iterate public ... ,
>>
>> with Ada.Containers.Indefinite_Hashed_Maps;
>> with Ada.Strings.Hash;
>>
>> with Ada.Text_IO; use Ada.Text_IO;
>>
>> procedure Show_Hashed_Map is
>>
>>    package Integer_Hashed_Maps is new
>>      Ada.Containers.Indefinite_Hashed_Maps
>>        (Key_Type        => String,
>>         Element_Type    => Integer,
>>         Hash            => Ada.Strings.Hash,
>>         Equivalent_Keys => "=");
>>
>>    use Integer_Hashed_Maps;
>>
>>    M : Map;
>>    --  Same as:  M : Integer_Hashed_Maps.Map;
>> begin
>>    M.Include ("Alice", 24);
>>    M.Include ("John",  40);
>>    M.Include ("Bob",   28);
>>
>>    if M.Contains ("Alice") then
>>       Put_Line ("Alice's age is "
>>                 & Integer'Image (M ("Alice")));
>>    end if;
>>
>>    --  Update Alice's age
>>    --  Key must already exist in M.
>>    --  Otherwise an exception is raised.
>>    M ("Alice") := 25;
>>
>>    New_Line; Put_Line ("Name & Age:");
>>    for C in M.Iterate loop
>>       Put_Line (Key (C) & ": " & Integer'Image (M (C)));
>>    end loop;
>>
>> end Show_Hashed_Map;
>
> I confirm that when you want to iterate over a hashed map and want both 
> key and value you need to use the .Iterate function as you do in the 
> example.

That's the reason it exists, of course. Not everything makes sense just with 
elements alone. (A cursor-based iterator is also much more like the existing 
iteration of Ada 95 than the element-based iterators of Ada 2005 and later.)

                          Randy. 



^ permalink raw reply	[relevance 0%]

* Re: How to Iterate over all elements of a hashed_map.
  2019-10-29 14:20  2% ` Alain De Vos
@ 2019-10-29 15:02  0%   ` joakimds
  2019-10-29 21:56  0%     ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: joakimds @ 2019-10-29 15:02 UTC (permalink / raw)


Den tisdag 29 oktober 2019 kl. 15:20:43 UTC+1 skrev Alain De Vos:
> I found code which takes a different approach, here there is a function .Iterate public ... ,
> 
> with Ada.Containers.Indefinite_Hashed_Maps;
> with Ada.Strings.Hash;
> 
> with Ada.Text_IO; use Ada.Text_IO;
> 
> procedure Show_Hashed_Map is
> 
>    package Integer_Hashed_Maps is new
>      Ada.Containers.Indefinite_Hashed_Maps
>        (Key_Type        => String,
>         Element_Type    => Integer,
>         Hash            => Ada.Strings.Hash,
>         Equivalent_Keys => "=");
> 
>    use Integer_Hashed_Maps;
> 
>    M : Map;
>    --  Same as:  M : Integer_Hashed_Maps.Map;
> begin
>    M.Include ("Alice", 24);
>    M.Include ("John",  40);
>    M.Include ("Bob",   28);
> 
>    if M.Contains ("Alice") then
>       Put_Line ("Alice's age is "
>                 & Integer'Image (M ("Alice")));
>    end if;
> 
>    --  Update Alice's age
>    --  Key must already exist in M.
>    --  Otherwise an exception is raised.
>    M ("Alice") := 25;
> 
>    New_Line; Put_Line ("Name & Age:");
>    for C in M.Iterate loop
>       Put_Line (Key (C) & ": " & Integer'Image (M (C)));
>    end loop;
> 
> end Show_Hashed_Map;

I confirm that when you want to iterate over a hashed map and want both key and value you need to use the .Iterate function as you do in the example.

Best regards,
Joakim

^ permalink raw reply	[relevance 0%]

* Re: How to Iterate over all elements of a hashed_map.
  2019-10-29 13:43  1% How to Iterate over all elements of a hashed_map Alain De Vos
@ 2019-10-29 14:20  2% ` Alain De Vos
  2019-10-29 15:02  0%   ` joakimds
  0 siblings, 1 reply; 200+ results
From: Alain De Vos @ 2019-10-29 14:20 UTC (permalink / raw)


I found code which takes a different approach, here there is a function .Iterate public ... ,

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

with Ada.Text_IO; use Ada.Text_IO;

procedure Show_Hashed_Map is

   package Integer_Hashed_Maps is new
     Ada.Containers.Indefinite_Hashed_Maps
       (Key_Type        => String,
        Element_Type    => Integer,
        Hash            => Ada.Strings.Hash,
        Equivalent_Keys => "=");

   use Integer_Hashed_Maps;

   M : Map;
   --  Same as:  M : Integer_Hashed_Maps.Map;
begin
   M.Include ("Alice", 24);
   M.Include ("John",  40);
   M.Include ("Bob",   28);

   if M.Contains ("Alice") then
      Put_Line ("Alice's age is "
                & Integer'Image (M ("Alice")));
   end if;

   --  Update Alice's age
   --  Key must already exist in M.
   --  Otherwise an exception is raised.
   M ("Alice") := 25;

   New_Line; Put_Line ("Name & Age:");
   for C in M.Iterate loop
      Put_Line (Key (C) & ": " & Integer'Image (M (C)));
   end loop;

end Show_Hashed_Map;


^ permalink raw reply	[relevance 2%]

* How to Iterate over all elements of a hashed_map.
@ 2019-10-29 13:43  1% Alain De Vos
  2019-10-29 14:20  2% ` Alain De Vos
  0 siblings, 1 reply; 200+ results
From: Alain De Vos @ 2019-10-29 13:43 UTC (permalink / raw)


I want to use an "associative array" , and have some code for a "string -> string" hash,

with Ada.Containers.Hashed_Maps;
----BEGIN MYHASH
   function Equivalent_Key (Left, Right : Unbounded_String) return Boolean is
   begin
      return Left = Right;
   end Equivalent_Key;
   function Hash_Func (Key : Unbounded_String) return Ada.Containers.Hash_Type is
   begin
      return Ada.Strings.Hash (To_String (Key));
   end Hash_Func;
   package My_Hash is new Ada.Containers.Hashed_Maps (Key_Type => Unbounded_String,
       Element_Type => Unbounded_String,
       Hash => Hash_Func,
       Equivalent_Keys => Equivalent_Key);
----END MYHASH
declare
Hash : My_Hash.Map;
begin
Hash.Insert ( Key => ... , New_Item => ...)
Hash.Insert ( Key => ... , New_Item => ...)

But now I want to iterate over all elements of this Hash and print the keys and items ?


^ permalink raw reply	[relevance 1%]

* Re: gnat.string_split , howto manipulate slice numbers
  @ 2019-10-29  8:17  2% ` briot.emmanuel
  0 siblings, 0 replies; 200+ results
From: briot.emmanuel @ 2019-10-29  8:17 UTC (permalink / raw)


> This does not work.
> Error :
> lsblk.adb:91:44: operator for type "Slice_Number" defined at g-arrspl.ads:116, instance at g-strspl.ads:39 is not directly visible

You need to make operators for the type visible.
Either with:

    use type GNAT.String_Split.Slice_Number;

or 
    use GNAT.String_Split;



You might want to take a look at GNATCOLL.Strings (also distributed by AdaCore, and generally installed with the compiler nowadays), which provides services similar to Ada.Strings.Unbounded but also has a split operation.

^ permalink raw reply	[relevance 2%]

* Re: Latest suggestion for 202x
  2019-06-15 23:59  1% Latest suggestion for 202x Micah Waddoups
  2019-06-16  7:17  0% ` Dmitry A. Kazakov
  2019-06-16 19:34  0% ` Optikos
@ 2019-06-23 20:17  0% ` Per Sandberg
  2 siblings, 0 replies; 200+ results
From: Per Sandberg @ 2019-06-23 20:17 UTC (permalink / raw)


Just a humble comment concerning using square brackets for for indexing 
arrays.
Why care if it is an array or function ?
That's just some implementation details that is of interest when using 
assembler.
/P



On 6/16/19 1:59 AM, Micah Waddoups wrote:
> Following is my comment of appreciation AND my suggestion that is a very basic and important level of support for Unicode.
> 
> Frankly, the former rules for directly specifying the contents of an array were perfect, when you can only use parenthesis.  Being able to use square brackets to improve the readability of an array is brilliant because it is familiar to those who use other languages and it does very little to change what is already part of the language definition (square brackets are already use in a way that does not conflict).  Therefore, it is not confusing, just new.
> 
> As for the other uses, I can't fully wrap my head around it, because I don't have time to study that part yet.
> 
> I have a suggestion, and I am sorry I haven't searched thoroughly to see if someone has suggested this already, though I don't believe they have.  Unicode and UTF are supported very well, however, the support is simply limited to the packages starting at Ada.Strings.UTF_Encoding.  There is no connection to Character_Set found in Maps.  Since many lines of code are designed around the traditional Character_Set in Ada.Strings, the categories of UTF should be conveyable as a (Wide_+)Character_Set so that the much existing code does not have to be fundamentally or completely redesigned in order to use the support to Unicode.  Please consider making Unicode categories available as character_sets (obviously omitting any characters from a category that are out of the range of the string, such as String, sans block drawing, vs. Wide_String, with block drawing).
> 
> If the character_set support for Unicode is not included in the pre-built standard libraries, then it will be much elaboration and unnecessary code to try to implement it correctly.
> 
> Does anybody agree or disagree with this very simple, but very impactful suggestion?
> 
> 
> 


^ permalink raw reply	[relevance 0%]

* Re: Latest suggestion for 202x
  2019-06-15 23:59  1% Latest suggestion for 202x Micah Waddoups
  2019-06-16  7:17  0% ` Dmitry A. Kazakov
@ 2019-06-16 19:34  0% ` Optikos
  2019-06-23 20:17  0% ` Per Sandberg
  2 siblings, 0 replies; 200+ results
From: Optikos @ 2019-06-16 19:34 UTC (permalink / raw)


On Saturday, June 15, 2019 at 6:59:41 PM UTC-5, Micah Waddoups wrote:
> Following is my comment of appreciation AND my suggestion that is a very basic and important level of support for Unicode.
> 
> Frankly, the former rules for directly specifying the contents of an array were perfect, when you can only use parenthesis.  Being able to use square brackets to improve the readability of an array is brilliant because it is familiar to those who use other languages

1) Fortran and Ada are the mainstream languages that utilize parentheses () for array indexing, following the reason #3 below.
2) Algol-family languages (especially the widely-influential Algol60 and the otherwise-influential-on-Ada Algol68) utilize brackets [] for array indexing.  Nearly all other programming languages (which often are little more than Algol60 rejiggered a little bit) have followed Algol's lead on array indexing via bracket [] syntax.
3) Mathematics utilizes subscripts on variables for the customary equivalent of array indexing, although mathematics could be said to also permit modeling array indexing as a narrower application of the generalized function-parenthesis notation f(i), just like Ada emulates.  Hence, Fortran & Ada are more true to mathematics' f(i) notation for representing array indexing as a function-invocation syntax.

> and it does very little to change what is already part of the language definition (square brackets are already use in a way that does not conflict).  Therefore, it is not confusing, just new.
> 
> As for the other uses, I can't fully wrap my head around it, because I don't have time to study that part yet.
> 
> I have a suggestion, and I am sorry I haven't searched thoroughly to see if someone has suggested this already, though I don't believe they have.  Unicode and UTF are supported very well, however, the support is simply limited to the packages starting at Ada.Strings.UTF_Encoding.  There is no connection to Character_Set found in Maps.  Since many lines of code are designed around the traditional Character_Set in Ada.Strings, the categories of UTF should be conveyable as a (Wide_+)Character_Set so that the much existing code does not have to be fundamentally or completely redesigned in order to use the support to Unicode.  Please consider making Unicode categories available as character_sets (obviously omitting any characters from a category that are out of the range of the string, such as String, sans block drawing, vs. Wide_String, with block drawing).
> 
> If the character_set support for Unicode is not included in the pre-built standard libraries, then it will be much elaboration and unnecessary code to try to implement it correctly.
> 
> Does anybody agree or disagree with this very simple, but very impactful suggestion?

^ permalink raw reply	[relevance 0%]

* Re: Latest suggestion for 202x
  2019-06-15 23:59  1% Latest suggestion for 202x Micah Waddoups
@ 2019-06-16  7:17  0% ` Dmitry A. Kazakov
  2019-06-16 19:34  0% ` Optikos
  2019-06-23 20:17  0% ` Per Sandberg
  2 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2019-06-16  7:17 UTC (permalink / raw)


On 2019-06-16 01:59, Micah Waddoups wrote:

> I have a suggestion, and I am sorry I haven't searched thoroughly to see if someone has suggested this already, though I don't believe they have.  Unicode and UTF are supported very well, however, the support is simply limited to the packages starting at Ada.Strings.UTF_Encoding.  There is no connection to Character_Set found in Maps.  Since many lines of code are designed around the traditional Character_Set in Ada.Strings, the categories of UTF should be conveyable as a (Wide_+)Character_Set so that the much existing code does not have to be fundamentally or completely redesigned in order to use the support to Unicode.  Please consider making Unicode categories available as character_sets (obviously omitting any characters from a category that are out of the range of the string, such as String, sans block drawing, vs. Wide_String, with block drawing).
> 
> If the character_set support for Unicode is not included in the pre-built standard libraries, then it will be much elaboration and unnecessary code to try to implement it correctly.

You may find an implementation of Unicode sets, maps, categorization here:

http://www.dmitry-kazakov.de/ada/strings_edit.htm#7.6

> Does anybody agree or disagree with this very simple, but very impactful suggestion?

Sets and maps have very infrequent use. With Unicode they require sparse 
representation and thus less efficient than Latin-1 variants.

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


^ permalink raw reply	[relevance 0%]

* Latest suggestion for 202x
@ 2019-06-15 23:59  1% Micah Waddoups
  2019-06-16  7:17  0% ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: Micah Waddoups @ 2019-06-15 23:59 UTC (permalink / raw)


Following is my comment of appreciation AND my suggestion that is a very basic and important level of support for Unicode.

Frankly, the former rules for directly specifying the contents of an array were perfect, when you can only use parenthesis.  Being able to use square brackets to improve the readability of an array is brilliant because it is familiar to those who use other languages and it does very little to change what is already part of the language definition (square brackets are already use in a way that does not conflict).  Therefore, it is not confusing, just new.

As for the other uses, I can't fully wrap my head around it, because I don't have time to study that part yet.

I have a suggestion, and I am sorry I haven't searched thoroughly to see if someone has suggested this already, though I don't believe they have.  Unicode and UTF are supported very well, however, the support is simply limited to the packages starting at Ada.Strings.UTF_Encoding.  There is no connection to Character_Set found in Maps.  Since many lines of code are designed around the traditional Character_Set in Ada.Strings, the categories of UTF should be conveyable as a (Wide_+)Character_Set so that the much existing code does not have to be fundamentally or completely redesigned in order to use the support to Unicode.  Please consider making Unicode categories available as character_sets (obviously omitting any characters from a category that are out of the range of the string, such as String, sans block drawing, vs. Wide_String, with block drawing).

If the character_set support for Unicode is not included in the pre-built standard libraries, then it will be much elaboration and unnecessary code to try to implement it correctly.

Does anybody agree or disagree with this very simple, but very impactful suggestion?



^ permalink raw reply	[relevance 1%]

* Re: Suggestions needed to split a package
  @ 2019-05-24 21:21  1%     ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2019-05-24 21:21 UTC (permalink / raw)


On Friday, May 24, 2019 at 2:26:04 PM UTC-6, Randy Brukardt wrote:
> "Björn Lundin" wrote in message 
> news:qc9595$ime$1...
> > Den 2019-05-24 kl. 17:49, skrev A. Cervetti:
> >> A package in the program I am writing is getting too long.
> >> So I thought it would be a good idea to split it.
> >>
> >> The package is here: 
> >> https://github.com/andreacervetti/ada-virt-monitor/tree/master/avm/src/monitor 
> >> (files monitor-structures.ad*).
> >>
> >> My problems are:
> >> I'd like to avoid forcing clients of the package to "with" too many 
> >> modules.
> >> I want keep private types private.
> >
> > If it is only file size that is your concern, you
> > can look at moving some functions via 'separate' to other files.
> > It does not change your structure, and clients of
> > the package does not know -> not more withs than current solution
> 
> Yes, although if there are a lot of small subprograms, it's not very 
> effective as you would end up with a *lot* of files (making it hard to find 
> things and slowing compilation). And you can't make overloaded subprograms 
> separate (the names have to be unique).

The way I've gotten around this is by putting these small subprograms in a nested-package within the body, making *that* package separate, and using renames.

Package Public is
  Type T1 is private;
  Procedure P1;
  Procedure P2;
  --...
End Public;

Package Body Public is
  Package Internal is
    Procedure P1;
    Procedure P2;
  End Internal;
  Package Body Internal is Separate;
  
  Procedure P1 renames Internal.P1;
  Procedure P2 renames Internal.P2;
End Public;

-------
As to making overloaded subprograms separate, is there a way to correct this? That, plus [TTBOMK] not being able to overload subprograms in the library hierarchy seem to be fairly related and could arguably make maintenance easier.

e.g. We can't have both
function Ada.Strings.Equal_Case_Insensitive (Left, Right : String) return Boolean;
function Ada.Strings.Equal_Case_Insensitive (Left, Right : Wide_Wide_String) return Boolean;

^ permalink raw reply	[relevance 1%]

* Re: Ada programmers: Stéphane Carrez - interview
  @ 2019-05-07 20:20  1%   ` stephane.carrez
  0 siblings, 0 replies; 200+ results
From: stephane.carrez @ 2019-05-07 20:20 UTC (permalink / raw)


Le mardi 7 mai 2019 16:11:30 UTC+2, Optikos a écrit :
> On Tuesday, May 7, 2019 at 6:26:24 AM UTC-5, Tomek Wałkuski wrote:
> > The new interview is up! Enjoy!
> > 
> > https://tomekw.com/ada-programmers-stephane-carrez/
> > 
> > The list of all interviews to date can be found here: https://tomekw.com/tag/interview/
> 
> Stéphane,
> What would be the generalization of the dot construct/operator for which you yearn?

I'm speaking of method call.
If you have the following variable:

  Item : Ada.Strings.Unbounded.Unbounded_String;

You have to use:

  Append (Item, "something");

But it would be nice to just do:

  Item.Append ("something");

There is an AI about that (can't remember the reference).
If I remember well, it was not accepted due to some problems this would create.

If you want to use the dot method call notation, you are force to use a tagged type.
And then, if you define other operations in another package (of course they are not overridable), then you can't use the dot method call notation.

Stephane


^ permalink raw reply	[relevance 1%]

* Re: Chess game in character over MS Windows
  @ 2019-03-01 13:17  1% ` manueledensenster
  0 siblings, 0 replies; 200+ results
From: manueledensenster @ 2019-03-01 13:17 UTC (permalink / raw)


On Friday, March 1, 2019 at 2:07:21 PM UTC+1, manueled...@gmail.com wrote:
> Hello,
> 
> I have inserted the 12 Wide_Character into a string of length 12 but gnatmake say at the exécution : length check failed.
> 
> Help me please.
> 
> 
> I have tested with UTF-8-auto-dos encoding with Emacs.
> 
> With GPS in UTF-8 is the same problem.
> 
> Thank you.

Sorry bis.
Ok, over MS Windows the problem is same over GPS or simple make with gnatmake and GtkAda.

My program is an chess game in text in a GtkAda project.
Sensibly the cocage of 12 Wide_Character is Ok.

But the Chess character are not printed.

I convert The literal Wide_Character with the line :

[code]

Locale_From_Utf8
		  
		  (Ada.Strings.UTF_Encoding.Conversions.Convert
		     ("" & Images(Piece_Type'Pos(Piece)),
		      UTF_8)
		  )
[/code]

To be inserted in gtk_text_buffer.

Thank you for your help.

^ permalink raw reply	[relevance 1%]

* Re: Ada x <whatever> Datagram Sockets
  2019-02-07  6:41  0%       ` Rego, P.
  2019-02-07  7:23  0%         ` Egil H H
@ 2019-02-07 11:47  0%         ` Jere
  1 sibling, 0 replies; 200+ results
From: Jere @ 2019-02-07 11:47 UTC (permalink / raw)


On Thursday, February 7, 2019 at 1:41:28 AM UTC-5, Rego, P. wrote:
> On Thursday, February 7, 2019 at 4:00:11 AM UTC-2, Egil H H wrote:
> > > > On Wednesday, February 6, 2019 at 6:10:37 PM UTC-5, Rego, P. wrote:
> > > 
> > > Just the string "test". I also confirmed that the MQL container (uchar data[]) has really the size 5.
> > > 
> > 
> > Right, Ada strings are not zero-terminated, and the size of the string needs 
> > to come from somewhere, which is why String'Input will interpret the first x bits (probably 32, but may depend on your platform) as the length. So in this
> > case, "test" becomes a big number and 'Input will most likely try to allocate
> > just under 2GB  on your stack (and probably at least twice, in order to copy
> > the result into your string).
> A C++ uchar in Windows machine is usually 1 byte, so assuming that both use the same signature, both messages (from C++ and from Ada) should be of same size, right? 
> 
The problem is you are telling it to send it one way and receive it
in another way.  In C++ you tell the code to send:
't' 'e' 's' 't' '\0'

In Ada you are telling it to receive:

<length byte 1..4> <data byte 1..length>

if it reads your c++ packet in that format, assuming a little endian 
system:

<0x74736574> <\0 + random junk>

That translates to specifying a length of 1953719668 bytes, which is 
above the 65507 limit.

For giggles try modifying your receive code a bit:

      declare
         subtype Test_String is String(1..5);
         Message : Test_String := Test_String'Input (Channel);
      begin
         Address := SOCKETS.Get_Address (Channel);
         Text_IO.Put_Line (Message & " from " & SOCKETS.Image (Address));
         Test_String'Output (Channel, Message);
      end; 

I don't recall if C actually sends the '\0' at the end or not
for sockets, so if it doesn't, then change the Test_String declaration
to

      subtype Test_String is String(1..4);

However, I think it does send the '\0', so you will also have to
handle that in your Ada code (since strings don't terminate with a
'\0' in Ada).

Changing String to a constrained subtype might change the pattern
to be closer to the C++ pattern sent.  This doesn't solve your problem
because you never know how long the data is for real data, but would
at least (hopefully) get you talking.

> 
> > 
> > Don't use Ada stream attributes to communicate with other languages.
> > 
> > And, as some will tell you, don't use them at all, especially for arrays, as
> > each array element may end up being transferred as a single data packet, destroying performance.
> 
> This is quite controversial, in this case. I'd usually agree with you, however the use of Ada stream is not by choice. The whole GNAT Ada package uses Ada streams, and actually the above code was entirely extracted from the comments from g-sockets.ads with minimum modification. I don't think it would be wise to re-implement Ada Sockets pkg to be more efficient.

I've never used streams with the GNAT socket package for production code,
so I cannot comment on them, but the package definitely offers other
options besides streams.  I generally have a task that periodically
reads up to a specific number of bytes into a buffer and then my other
tasks can handle the data as they see fit.  You can even have the OS
tell you how many bytes are available to read before you do.

^ permalink raw reply	[relevance 0%]

* Re: Ada x <whatever> Datagram Sockets
  2019-02-07  6:41  0%       ` Rego, P.
@ 2019-02-07  7:23  0%         ` Egil H H
  2019-02-07 11:47  0%         ` Jere
  1 sibling, 0 replies; 200+ results
From: Egil H H @ 2019-02-07  7:23 UTC (permalink / raw)


On Thursday, February 7, 2019 at 7:41:28 AM UTC+1, Rego, P. wrote:
> On Thursday, February 7, 2019 at 4:00:11 AM UTC-2, Egil H H wrote:
> > > > On Wednesday, February 6, 2019 at 6:10:37 PM UTC-5, Rego, P. wrote:
> > > 
> > > Just the string "test". I also confirmed that the MQL container (uchar data[]) has really the size 5.
> > > 
> > 
> > Right, Ada strings are not zero-terminated, and the size of the string needs 
> > to come from somewhere, which is why String'Input will interpret the first x bits (probably 32, but may depend on your platform) as the length. So in this
> > case, "test" becomes a big number and 'Input will most likely try to allocate
> > just under 2GB  on your stack (and probably at least twice, in order to copy
> > the result into your string).
> A C++ uchar in Windows machine is usually 1 byte, so assuming that both use the same signature, both messages (from C++ and from Ada) should be of same size, right? 
> 

The *message* may be of the same size, but that doesn't matter, as long as
it's interpreted differently in C++ vs Ada.
C++ apparently puts an extra character in your message (you said "test"
was length 5...)
Ada interprets your string (presumably the first 4 bytes, which is usually
the size of Positive/Integer) as a very big number.

> > 
> > Don't use Ada stream attributes to communicate with other languages.
> > 
> > And, as some will tell you, don't use them at all, especially for arrays, as
> > each array element may end up being transferred as a single data packet, destroying performance.
> 
> This is quite controversial, in this case. I'd usually agree with you, however the use of Ada stream is not by choice. The whole GNAT Ada package uses Ada streams, and actually the above code was entirely extracted from the comments from g-sockets.ads with minimum modification. I don't think it would be wise to re-implement Ada Sockets pkg to be more efficient.


How is it controversial? The example works fine when the server and client
are both written in Ada, as they would then agree on the protocol.
But when dealing with cross-language communication, you're better off using
Send_Socket/Receive_Socket directly. No need to re-implement

-- 
~egilhh


^ permalink raw reply	[relevance 0%]

* Re: Ada x <whatever> Datagram Sockets
  2019-02-07  6:00  1%     ` Egil H H
@ 2019-02-07  6:41  0%       ` Rego, P.
  2019-02-07  7:23  0%         ` Egil H H
  2019-02-07 11:47  0%         ` Jere
  0 siblings, 2 replies; 200+ results
From: Rego, P. @ 2019-02-07  6:41 UTC (permalink / raw)


On Thursday, February 7, 2019 at 4:00:11 AM UTC-2, Egil H H wrote:
> > > On Wednesday, February 6, 2019 at 6:10:37 PM UTC-5, Rego, P. wrote:
> > 
> > Just the string "test". I also confirmed that the MQL container (uchar data[]) has really the size 5.
> > 
> 
> Right, Ada strings are not zero-terminated, and the size of the string needs 
> to come from somewhere, which is why String'Input will interpret the first x bits (probably 32, but may depend on your platform) as the length. So in this
> case, "test" becomes a big number and 'Input will most likely try to allocate
> just under 2GB  on your stack (and probably at least twice, in order to copy
> the result into your string).
A C++ uchar in Windows machine is usually 1 byte, so assuming that both use the same signature, both messages (from C++ and from Ada) should be of same size, right? 

(I checked both send commands used by Ada sockets and MQL sockets, and they both are using standard win32 signatures, I mean for C++ case

int sendto(
  SOCKET         s,
  const char     *buf,
  int            len,
  int            flags,
  const sockaddr *to,
  int            tolen
);

and in Ada case a imported function
   function C_Sendto
     (S     : C.int;
      Msg   : System.Address;
      Len   : C.int;
      Flags : C.int;
      To    : System.Address;
      Tolen : C.int) return C.int;
)

> 
> Don't use Ada stream attributes to communicate with other languages.
> 
> And, as some will tell you, don't use them at all, especially for arrays, as
> each array element may end up being transferred as a single data packet, destroying performance.

This is quite controversial, in this case. I'd usually agree with you, however the use of Ada stream is not by choice. The whole GNAT Ada package uses Ada streams, and actually the above code was entirely extracted from the comments from g-sockets.ads with minimum modification. I don't think it would be wise to re-implement Ada Sockets pkg to be more efficient.


^ permalink raw reply	[relevance 0%]

* Re: Ada x <whatever> Datagram Sockets
  @ 2019-02-07  6:00  1%     ` Egil H H
  2019-02-07  6:41  0%       ` Rego, P.
  0 siblings, 1 reply; 200+ results
From: Egil H H @ 2019-02-07  6:00 UTC (permalink / raw)


> > On Wednesday, February 6, 2019 at 6:10:37 PM UTC-5, Rego, P. wrote:
> 
> Just the string "test". I also confirmed that the MQL container (uchar data[]) has really the size 5.
> 

Right, Ada strings are not zero-terminated, and the size of the string needs 
to come from somewhere, which is why String'Input will interpret the first x bits (probably 32, but may depend on your platform) as the length. So in this
case, "test" becomes a big number and 'Input will most likely try to allocate
just under 2GB  on your stack (and probably at least twice, in order to copy
the result into your string).

Don't use Ada stream attributes to communicate with other languages.

And, as some will tell you, don't use them at all, especially for arrays, as
each array element may end up being transferred as a single data packet, destroying performance.


-- 
~egilhh

^ permalink raw reply	[relevance 1%]

* Re: class wide iterable (and indexable)
  2019-01-07 21:07  0%               ` Randy Brukardt
@ 2019-01-08  9:51  0%                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2019-01-08  9:51 UTC (permalink / raw)


On 2019-01-07 22:07, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:q0pvlp$1vp1$1@gioia.aioe.org...
>> On 2019-01-05 10:21, Randy Brukardt wrote:
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>>> news:q0n6av$1tqs$1@gioia.aioe.org...
>>> ...
>>>> In real programs dispatch is rare, thus there is no overhead.
>>>
>>> This is probably true, but then interfaces are even more useless (they
>>> provide nothing that could possibly be of value other than dispatch!).
>>
>>  From the SW design POV they provide a description of an interface, which
>> is a lot of value as is.
> 
> That's primarily the job of package specifications, how the contents are
> structured isn't very relevant from a description standpoint.

Package specification is only a container for. How do you know that a 
type is numeric? The choice is between structural and named equivalence. 
With interfaces you can declare it numeric by merely stating that it 
belongs to the class. Without them you need to analyze all declarations 
related to the type in order to guess and there no guaranty that the 
guess is right.

>>>> No, interfaces cannot contain common code except for class-wide one. Is
>>>> that what Randy meant about overhead?
>>>
>>> Not really. My main point is that you'll never have more than one concrete
>>> instance of a generic interface in any individual program (certainly not
>>> of an interface like that of a container),
>>
>> I don't understand this. Usually I have dozens of instantiations of the
>> same generics with different actual parameters.
> 
> Right, but all of those are *different* interfaces because they have
> *different* generic parameters. You can't mix those types in any useful way,
> because you almost always have the generic parameter type(s) involved.

Of course I can mix them. Generics are mixed by passing to other generics:

    generic
       with package X is new P (<>);
    package Mixer is ...

The body is valid for all instances of P. And we still have not 
specialization of generics. So the set of instances cannot be 
constrained later.

Though, I don't see how it is important to mix or not to mix instances 
to the question which method of building a class is better. Tagged 
classes are infinitely better than generic classes.

> For instance, for the containers, an interface would have to contain the
> element type. But that substantially limits reuse, because almost every
> container instance would have a different element type. You can't even pass
> just the interface into a generic because you wouldn't be able to call the
> primitives without knowing the element type. To make such a reuse possible
> you'd have to pass so many parameters that you are typing instantiations for
> days. And then the compilation time also would be days. You'd have to be
> slightly mad to even try it. :-)

I don't see your point. You argue that generic-based design of 
containers is bad. Of course it is bad.

>>> Note: I mean one concrete type, there might be many objects of that type.
>>> But it doesn't make sense to use bounded and indefinite containers at the
>>> same time for the same element type.
>>
>> Of course it does. The best example is Ada strings, a container of
>> characters. Practically every program in effect uses both bounded and
>> unbounded strings, the later, maybe, in the form of access String (I tend
>> to avoid Unbounded_String).
> 
> As with many things OOP, there seems to be exactly one example where it
> works. And everything else it doesn't work (or at least help - it "works" in
> the sense that you can write it that way and get it to work -- but you've
> gained nothing, you've just changed the problems).

At least there is one. Generics have none.

>>> Dmitry is of course an all-interface all the time sort of guy. All I see
>>> from that is a vast amount of typing to get nothing in particular in
>>> return.
>>
>> You get type safety. Otherwise you can always go back K&R C! (:-))
> 
> Ada has plenty of type safety without using OOP.

No, Ada is all OOP as we do

    type I is new Natural; -- Interface

instead of

    type I is private; -- Nobody knows what
    function "+" (Left, Right : I) return I;
    function "-" (Left, Right : I) return I;
    function "*" (Left, Right : I) return I;
    function "/" (Left, Right : I) return I;
    function "0" return I;
    function "1" return I;
    function "2" return I;
    ...

>>> [But I'm not much of a fan of OOP, either; the big advantage of OOP is
>>> requiring few recompiles when adding features. That was a big deal in
>>> 1990,
>>> but it hardly matters today. (I can recompile the entirety of Janus/Ada -
>>> 250,000 lines - in 15 minutes or so. Why try to save compiles?) And for
>>> that, you get to type dozens and dozens of declarations to do anything.
>>
>> That is because compilers are no longer large software, not even
>> medium-size (:-)). My current project takes a half of week to recompile
>> from scratch [*].
> 
> Because you greatly overuse generics in the hopes of making interfaces
> useful. [You admitted as much at the bottom of this message.] You understand
> the cost of using interfaces very well, yet don't seem to make the obvious
> connection. ;-)

There is no other way to reuse across a set of types. Either generics 
(AKA static polymorphism) or inheritance (AKA dynamic polymorphism).

>> And recompilation is not the biggest problem. Deployment of the modules
>> is.
> 
> Keeping protocols consistent is definitely a hard problem. (One I'm glad to
> skip.) I don't see any reason that OOP would help there, though. My attempt
> at that in the Claw Builder was mostly unsuccessful.

With interfaces you can detect client side problems at compile time. 
Without them you don't know until you actually use a given operation. 
This is the case with generics especially because Ada generics have weak 
contracts.

> And you talk about this a lot, so I don't know what it is that you think you
> gain with interfaces that you wouldn't have with a normal record type and
> primitive operations.

Give me tagged types to freely inherit from and I promise to never use 
interfaces [*] again! (:-))

>> ----------------------
>> * GNAT is awfully slow when compiling specifically generic instantiations,
>> and I have lots of them. The more I have, the more I hate them.
> 
> This is the point where I'd usually suggest trying a different compiler. :-)

And I usually point out that without Linux/VxWorks support and targets 
like ARM there is no chance.

> A compiler using shared generics could take a lot less time to compile
> instances because there is little code involved.

Without any doubt. Worse that that, yes, instances are slow to compile, 
but I have an impression that merely with-ing compiled instances 
drastically increases the compile time of a package and the memory used 
by the compiler. At the end of the dependency chain it becomes minutes 
to compile a three-liner body. There is something utterly wrong with 
GNAT there.

> OTOH, I don't want you to
> try Janus/Ada (even on the code that don't use actual interfaces), 'cause
> the way you use generics would inevitably break stuff and I'd hate to have
> to debug code like that. :-) :-)

I would gladly use Janus/Ada or ObjectAda if I could. I was a happy user 
of the latter long ago. Unfortunately cross-platformity is a requirement 
in these days.
--------------------
* Here, interface = crippled abstract tagged type.

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

^ permalink raw reply	[relevance 0%]

* Re: class wide iterable (and indexable)
  2019-01-05 10:07  1%             ` Dmitry A. Kazakov
@ 2019-01-07 21:07  0%               ` Randy Brukardt
  2019-01-08  9:51  0%                 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2019-01-07 21:07 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:q0pvlp$1vp1$1@gioia.aioe.org...
> On 2019-01-05 10:21, Randy Brukardt wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:q0n6av$1tqs$1@gioia.aioe.org...
>> ...
>>> In real programs dispatch is rare, thus there is no overhead.
>>
>> This is probably true, but then interfaces are even more useless (they
>> provide nothing that could possibly be of value other than dispatch!).
>
> From the SW design POV they provide a description of an interface, which 
> is a lot of value as is.

That's primarily the job of package specifications, how the contents are 
structured isn't very relevant from a description standpoint.

...
>> ...
>>> No, interfaces cannot contain common code except for class-wide one. Is
>>> that what Randy meant about overhead?
>>
>> Not really. My main point is that you'll never have more than one 
>> concrete
>> instance of a generic interface in any individual program (certainly not 
>> of
>> an interface like that of a container),
>
> I don't understand this. Usually I have dozens of instantiations of the 
> same generics with different actual parameters.

Right, but all of those are *different* interfaces because they have 
*different* generic parameters. You can't mix those types in any useful way, 
because you almost always have the generic parameter type(s) involved.

For instance, for the containers, an interface would have to contain the 
element type. But that substantially limits reuse, because almost every 
container instance would have a different element type. You can't even pass 
just the interface into a generic because you wouldn't be able to call the 
primitives without knowing the element type. To make such a reuse possible 
you'd have to pass so many parameters that you are typing instantiations for 
days. And then the compilation time also would be days. You'd have to be 
slightly mad to even try it. :-)

>> Note: I mean one concrete type, there might be many objects of that type.
>> But it doesn't make sense to use bounded and indefinite containers at the
>> same time for the same element type.
>
> Of course it does. The best example is Ada strings, a container of 
> characters. Practically every program in effect uses both bounded and 
> unbounded strings, the later, maybe, in the form of access String (I tend 
> to avoid Unbounded_String).

As with many things OOP, there seems to be exactly one example where it 
works. And everything else it doesn't work (or at least help - it "works" in 
the sense that you can write it that way and get it to work -- but you've 
gained nothing, you've just changed the problems).

>> Dmitry is of course an all-interface all the time sort of guy. All I see
>> from that is a vast amount of typing to get nothing in particular in 
>> return.
>
> You get type safety. Otherwise you can always go back K&R C! (:-))

Ada has plenty of type safety without using OOP.

>> [But I'm not much of a fan of OOP, either; the big advantage of OOP is
>> requiring few recompiles when adding features. That was a big deal in 
>> 1990,
>> but it hardly matters today. (I can recompile the entirety of Janus/Ada -
>> 250,000 lines - in 15 minutes or so. Why try to save compiles?) And for
>> that, you get to type dozens and dozens of declarations to do anything.
>
> That is because compilers are no longer large software, not even 
> medium-size (:-)). My current project takes a half of week to recompile 
> from scratch [*].

Because you greatly overuse generics in the hopes of making interfaces 
useful. [You admitted as much at the bottom of this message.] You understand 
the cost of using interfaces very well, yet don't seem to make the obvious 
connection. ;-)

> And recompilation is not the biggest problem. Deployment of the modules 
> is.

Keeping protocols consistent is definitely a hard problem. (One I'm glad to 
skip.) I don't see any reason that OOP would help there, though. My attempt 
at that in the Claw Builder was mostly unsuccessful.

 >> While the supposedly terrible case statement solution gives you case
>> completeness checks, variant checks, and essentially has no more chance 
>> of
>> failure (and costs a lot less, and keeps all of the similar code together
>> rather that scattering it about to every different kind of object).
>
> The main problem is that the "similar" code logically has nothing in 
> common, except the shared interface. It must be written by different 
> teams, at different locations and time. Independently tested, used, 
> deployed, versioned, maintained. The case-statement solution crushes not 
> only the architecture but all software process.

Understood, but I'm a "smaller is better" guy. If the team for the project 
doesn't fit in a room, you are guaranteed to have to mess. You can only get 
by then with very strong specifications -- but interfaces themselves don't 
buy anything there (the reverse, in fact, since they're hard to serialize). 
The specifications have to include not just declarations and semantics but 
data layout and protocols and all of that mess that never really works.

And you talk about this a lot, so I don't know what it is that you think you 
gain with interfaces that you wouldn't have with a normal record type and 
primitive operations.

> ----------------------
> * GNAT is awfully slow when compiling specifically generic instantiations, 
> and I have lots of them. The more I have, the more I hate them.

This is the point where I'd usually suggest trying a different compiler. :-) 
A compiler using shared generics could take a lot less time to compile 
instances because there is little code involved. OTOH, I don't want you to 
try Janus/Ada (even on the code that don't use actual interfaces), 'cause 
the way you use generics would inevitably break stuff and I'd hate to have 
to debug code like that. :-) :-)

                              Randy.


^ permalink raw reply	[relevance 0%]

* Re: class wide iterable (and indexable)
  @ 2019-01-05 10:07  1%             ` Dmitry A. Kazakov
  2019-01-07 21:07  0%               ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2019-01-05 10:07 UTC (permalink / raw)


On 2019-01-05 10:21, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:q0n6av$1tqs$1@gioia.aioe.org...
> ...
>> In real programs dispatch is rare, thus there is no overhead.
> 
> This is probably true, but then interfaces are even more useless (they
> provide nothing that could possibly be of value other than dispatch!).

 From the SW design POV they provide a description of an interface, 
which is a lot of value as is.

>> I don't know which overhead Randy meant, though. Maybe, space overhead?
>> That is not nearly close to what generics produce in GNAT...
> 
> Dispatching is very expensive for interfaces, in that some form of search is
> needed. (Note: I have no idea how GNAT implements them exactly.) It might be
> possible to do some sort of link-time assignment of interface identifiers
> and link-time tag construction to avoid some of that cost (at the cost of a
> lot of space), but that would be such a complex and unusual project
> (conventional linkers don't support anything like that) that I've always
> considered it impraactical.

Bounded time dispatch must be a requirement of course. However I doubt 
that what we have now, a myriad of helper tagged types and objects 
created and destroyed all the time is more effective in any thinkable way.

> ...
>> No, interfaces cannot contain common code except for class-wide one. Is
>> that what Randy meant about overhead?
> 
> Not really. My main point is that you'll never have more than one concrete
> instance of a generic interface in any individual program (certainly not of
> an interface like that of a container),

I don't understand this. Usually I have dozens of instantiations of the 
same generics with different actual parameters.

> Note: I mean one concrete type, there might be many objects of that type.
> But it doesn't make sense to use bounded and indefinite containers at the
> same time for the same element type.

Of course it does. The best example is Ada strings, a container of 
characters. Practically every program in effect uses both bounded and 
unbounded strings, the later, maybe, in the form of access String (I 
tend to avoid Unbounded_String).

> Dmitry is of course an all-interface all the time sort of guy. All I see
> from that is a vast amount of typing to get nothing in particular in return.

You get type safety. Otherwise you can always go back K&R C! (:-))

> [But I'm not much of a fan of OOP, either; the big advantage of OOP is
> requiring few recompiles when adding features. That was a big deal in 1990,
> but it hardly matters today. (I can recompile the entirety of Janus/Ada -
> 250,000 lines - in 15 minutes or so. Why try to save compiles?) And for
> that, you get to type dozens and dozens of declarations to do anything.

That is because compilers are no longer large software, not even 
medium-size (:-)). My current project takes a half of week to recompile 
from scratch [*].

And recompilation is not the biggest problem. Deployment of the modules is.

> While the supposedly terrible case statement solution gives you case
> completeness checks, variant checks, and essentially has no more chance of
> failure (and costs a lot less, and keeps all of the similar code together
> rather that scattering it about to every different kind of object).

The main problem is that the "similar" code logically has nothing in 
common, except the shared interface. It must be written by different 
teams, at different locations and time. Independently tested, used, 
deployed, versioned, maintained. The case-statement solution crushes not 
only the architecture but all software process.

----------------------
* GNAT is awfully slow when compiling specifically generic 
instantiations, and I have lots of them. The more I have, the more I 
hate them.

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


^ permalink raw reply	[relevance 1%]

* Re: class wide iterable (and indexable)
  2019-01-04  4:32  0%       ` Shark8
@ 2019-01-05  9:03  0%         ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2019-01-05  9:03 UTC (permalink / raw)


"Shark8" <onewingedshark@gmail.com> wrote in message 
news:95f6a9b0-adc6-4044-8ff8-f0820612aeea@googlegroups.com...
> On Thursday, January 3, 2019 at 1:52:50 AM UTC-7, Simon Wright wrote:
>>
>>
>> The Ada 95 Booch Components[4] follow this model. One reason they
>> weren't taken as a model for Ada.Containers was that the model requires
>> multiple levels of generic instantiation of child packages: for example,
>> to make an unbounded map from Unbounded_String to Unbounded_String
>> requires
>>
>>    with Ada.Strings.Unbounded;
>>    with BC.Containers.Maps.Unbounded;
>>    with BC.Support.Standard_Storage;
>>
>>    package Configuration_Demo_Support is
>>
>>       package Abstract_String_Containers is new BC.Containers
>>         (Item => Ada.Strings.Unbounded.Unbounded_String,
>>          "=" => Ada.Strings.Unbounded."=");
>>
>>       package Abstract_String_Maps
>>       is new Abstract_String_Containers.Maps
>>         (Key => Ada.Strings.Unbounded.Unbounded_String,
>>          "=" => Ada.Strings.Unbounded."=");
> True; but the Automatic Instantiation AI would relieve a lot of the hassle 
> here --  
> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0268-1.txt?rev=1.2

The AI you refer to is only about formal packages, while the above doesn't 
have any formal packages so I fail to see how it would help.

A more general automatic instantiation mechanism was also proposed in 
AI12-0215-1. But that one is a dead-body issue for me (at least as 
proposed). Ada gives specific places where every declaration occurs 
(statically) and is elaborated (dynamically). AI12-0215-1 throws that 
property completely away, harming analyzability, readability, and 
understandability -- it would be much like saying that there's no neeed to 
declare objects before using them because the compiler can figure out what 
was intended. Bah humbug. :-)

                            Randy.


^ permalink raw reply	[relevance 0%]

* Re: class wide iterable (and indexable)
  2019-01-03  8:52  2%     ` Simon Wright
@ 2019-01-04  4:32  0%       ` Shark8
  2019-01-05  9:03  0%         ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Shark8 @ 2019-01-04  4:32 UTC (permalink / raw)


On Thursday, January 3, 2019 at 1:52:50 AM UTC-7, Simon Wright wrote:
> 
> 
> The Ada 95 Booch Components[4] follow this model. One reason they
> weren't taken as a model for Ada.Containers was that the model requires
> multiple levels of generic instantiation of child packages: for example,
> to make an unbounded map from Unbounded_String to Unbounded_String
> requires
> 
>    with Ada.Strings.Unbounded;
>    with BC.Containers.Maps.Unbounded;
>    with BC.Support.Standard_Storage;
> 
>    package Configuration_Demo_Support is
> 
>       package Abstract_String_Containers is new BC.Containers
>         (Item => Ada.Strings.Unbounded.Unbounded_String,
>          "=" => Ada.Strings.Unbounded."=");
> 
>       package Abstract_String_Maps
>       is new Abstract_String_Containers.Maps
>         (Key => Ada.Strings.Unbounded.Unbounded_String,
>          "=" => Ada.Strings.Unbounded."=");
True; but the Automatic Instantiation AI would relieve a lot of the hassle here -- http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0268-1.txt?rev=1.2  

^ permalink raw reply	[relevance 0%]

* Re: class wide iterable (and indexable)
  @ 2019-01-03  8:52  2%     ` Simon Wright
  2019-01-04  4:32  0%       ` Shark8
    1 sibling, 1 reply; 200+ results
From: Simon Wright @ 2019-01-03  8:52 UTC (permalink / raw)


George Shapovalov <gshapovalov@gmail.com> writes:

> Thanks!
> I'll try adding this and see if I can get around that invalid
> interface conversion.
>
> I did see in the Ada.Containers.Vectors code two versions defined,
> however I was not clear on why, especially since both the Ada Gem 10x
> (I forgot now exact number) and Ada Rationale for 2012 seem to only
> provide one, with a Cursor.

ARM A.18.2(34.3)ff[1] has both forms.

> However, from your response (also my general impression while digging
> through the iterables workings) is that this is not a common way to
> provide such code unification. How then one is supposed to go about
> such feature?

You might be interested in Emmanuel's 'traits'-based containers, see
[2], [3].

> On a related note, I was rather surprised that the related types in
> Ada.Containers do not form such a hierarchy. Say both
> Ada.Containers.Vectors and Indefinite_Vectors (and especially now with
> addition of Bounded_Vectors too) all could derive from a common
> ancestor that could be used to implement common functionality and let
> end user chose the desired data storage model..

The Ada 95 Booch Components[4] follow this model. One reason they
weren't taken as a model for Ada.Containers was that the model requires
multiple levels of generic instantiation of child packages: for example,
to make an unbounded map from Unbounded_String to Unbounded_String
requires

   with Ada.Strings.Unbounded;
   with BC.Containers.Maps.Unbounded;
   with BC.Support.Standard_Storage;

   package Configuration_Demo_Support is

      package Abstract_String_Containers is new BC.Containers
        (Item => Ada.Strings.Unbounded.Unbounded_String,
         "=" => Ada.Strings.Unbounded."=");

      package Abstract_String_Maps
      is new Abstract_String_Containers.Maps
        (Key => Ada.Strings.Unbounded.Unbounded_String,
         "=" => Ada.Strings.Unbounded."=");

      function Hash (S : Ada.Strings.Unbounded.Unbounded_String)
        return Natural;

      package String_Maps
      is new Abstract_String_Maps.Unbounded
        (Hash => Hash,
         Buckets => 43,
         Storage => BC.Support.Standard_Storage.Pool);

   end Configuration_Demo_Support;

[1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-18-2.html#p34.3
[2] https://blog.adacore.com/traits-based-containers
[3] https://github.com/AdaCore/ada-traits-containers
[4] https://sourceforge.net/projects/booch95/


^ permalink raw reply	[relevance 2%]

* Re: Gtk Ada Message box example
  @ 2018-12-31  7:31  2%   ` ldries46
  0 siblings, 0 replies; 200+ results
From: ldries46 @ 2018-12-31  7:31 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

Thanks for the information.
I just have remembered how it has to be done in Gtk and put in some standard 
package that wil position a message box with only one button which can do 
what I wanrted, just preenting a message

L. Dries

"Dmitry A. Kazakov"  schreef in bericht news:q08683$ol5$1@gioia.aioe.org...

On 2018-12-29 16:34, ldries46 wrote:
> I am searching for an example of showing a message box in Gtk.
> I have been programming in VC++ earlier and there it was simple tocreate a 
> message box because you only have to show it.
> I just want a message box with a title, a message and one button "OK". If 
> possble an Icon "Warning"
> both text items can be either in string format or in.
> I do not want to use glade anymore since it cannot present ada programming 
> language anymore.
> I just am glad with a link ho an example in Ada

    http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm

Package Gtk.Missed, procedure Message_Dialog.

Note it cannot be called from any Ada task other than the one running
the GTK messages loop.

For a procedure callable from any task see the package Gtk.Main.Router,
procedure Say.

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

[-- Attachment #2: message_box.adb --]
[-- Type: text/plain, Size: 1344 bytes --]

pragma License(Unrestricted);
--with Gtk;                         use Gtk;
with Gtk.Window;                  use Gtk.Window;
with Gtk.Dialog;                  use Gtk.Dialog;
with Gtk.Message_Dialog;          use Gtk.Message_Dialog;
with Ada.Strings.Unbounded;       use Ada.Strings.Unbounded;

package body Message_Box is

   procedure M_Box(Title : String;
                   Text : String) is
      MessageBox : Gtk_Message_Dialog;
   begin
      MessageBox := Gtk_Message_Dialog_New(null,
                                           1,
                                           Message_Warning,
                                           Buttons_Close,
                                           Text);
      MessageBox.Set_Title(Title);
      if MessageBox.Run <= 0 then
         MessageBox.Destroy;
      end if;
   end M_Box;

   procedure M_Box(Title : UnBounded_String;
                   Text : UnBounded_String) is
   begin
      M_Box(To_String(Title), To_String(Text));
   end M_Box;

   procedure M_Box(Title : UnBounded_String;
                   Text : String) is
   begin
      M_Box(To_String(Title), Text);
   end M_Box;

   procedure M_Box(Title : String;
                   Text : UnBounded_String) is
   begin
      M_Box(Title, To_String(Text));
   end M_Box;

end Message_Box;

[-- Attachment #3: message_box.ads --]
[-- Type: text/plain, Size: 625 bytes --]

pragma License(Unrestricted);
--with Gtk;                         use Gtk;
with Gtk.Window;                  use Gtk.Window;
with Gtk.Message_Dialog;          use Gtk.Message_Dialog;
with Ada.Strings.Unbounded;       use Ada.Strings.Unbounded;

package Message_Box is

   procedure M_Box(Title : String;
                   Text : String);
   procedure M_Box(Title : UnBounded_String;
                   Text : UnBounded_String);
   procedure M_Box(Title : UnBounded_String;
                   Text : String);
   procedure M_Box(Title : String;
                   Text : UnBounded_String);

end Message_Box;

^ permalink raw reply	[relevance 2%]

* Re: GNATCOLL JSON Parsing
  @ 2018-12-03 18:10  1%   ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2018-12-03 18:10 UTC (permalink / raw)


eduardsapotski@gmail.com writes:

> Again problem ...
> I'm trying parse such result: https://api.exmo.com/v1/pair_settings/
>
>    function Get_Pair_Settings return Pair_Settings_Vector_Package.Vector is
>       JSON    : Unbounded_String := Null_Unbounded_String;
>       URL_Str : Unbounded_String := To_Unbounded_String("https://api.exmo.com/v1/pair_settings/");
>
>       Current_JSON_Item, JSON_Main_Node : JSON_Value := Create;
>       JSON_Result_Array : JSON_Array := Empty_Array;
>
>       Result  : Pair_Settings_Vector_Package.Vector;
>    begin
>       JSON := To_Unbounded_String(Message_Body(Get(URL => To_String(URL_Str))));
>       JSON_Main_Node := Read(JSON);
>       JSON_Result_Array := Get(JSON_Main_Node);
>
>       if Length(JSON_Result_Array) > 0 then
>          for i in 1 .. Length(JSON_Result_Array) loop
>             Put_Line("123");
>          end loop;
>       end if;
>
>       return Result;
>
>    end;
>
> ...
>
> raised CONSTRAINT_ERROR : gnatcoll-json.adb:1328 discriminant check failed

I finally managed to make this work.

It turns out that the JSON returned from that query (actually, the http:
version) is a single JSON object, where the contents are fields, not
array elements (I may have the nomenclature wrong there).

This code

with Aws;
with Aws.Client;
with Aws.Response;
with Ada.Text_IO; use Ada.Text_IO;
with GNATCOLL.JSON; use GNATCOLL.JSON;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure Test_JSON is
   Aws_Reply         : Aws.Response.Data;
   JSON_Main_Node    : JSON_Value := Create;

   procedure Report_Outer_Field_Name (Name : Utf8_String; Value : JSON_Value);
   procedure Report_Inner_Field_Name (Name : Utf8_String; Value : JSON_Value);

   procedure Report_Outer_Field_Name (Name : Utf8_String; Value : JSON_Value)
   is
   begin
      Put_Line ("field: " & Name);
      Map_JSON_Object (Value, Report_Inner_Field_Name'Access);
   end Report_Outer_Field_Name;

   procedure Report_Inner_Field_Name (Name : Utf8_String; Value : JSON_Value)
   is
   begin
      Put_Line ("    field: " & Name & ", kind: " & Kind (Value)'Image);
   end Report_Inner_Field_Name;

begin
   Aws_Reply := Aws.Client.Get
     (Url          => "http://api.exmo.com/v1/pair_settings");

   JSON_Main_Node := Read
     (Strm     => Unbounded_String'(Aws.Response.Message_Body(Aws_Reply)),
      Filename => "");

   Map_JSON_Object (JSON_Main_Node, Report_Outer_Field_Name'Access);

end Test_JSON;

results in

$ ./test_json 
field: BTC_USD
    field: min_quantity, kind: JSON_STRING_TYPE
    field: max_quantity, kind: JSON_STRING_TYPE
    field: min_price, kind: JSON_STRING_TYPE
    field: max_price, kind: JSON_STRING_TYPE
    field: max_amount, kind: JSON_STRING_TYPE
    field: min_amount, kind: JSON_STRING_TYPE
field: BTC_EUR
    field: min_quantity, kind: JSON_STRING_TYPE
    field: max_quantity, kind: JSON_STRING_TYPE
    field: min_price, kind: JSON_STRING_TYPE
    field: max_price, kind: JSON_STRING_TYPE
    field: max_amount, kind: JSON_STRING_TYPE
    field: min_amount, kind: JSON_STRING_TYPE
...
field: BTG_ETH
    field: min_quantity, kind: JSON_STRING_TYPE
    field: max_quantity, kind: JSON_STRING_TYPE
    field: min_price, kind: JSON_STRING_TYPE
    field: max_price, kind: JSON_STRING_TYPE
    field: max_amount, kind: JSON_STRING_TYPE
    field: min_amount, kind: JSON_STRING_TYPE

Struggles:

As noted several times, this was all a bit mystifying

The default build of GNATCOLL has no debug symbols (both static & shared
libraries)

^ permalink raw reply	[relevance 1%]

* Re: windows-1251 to utf-8
  2018-10-31 15:28  2% ` eduardsapotski
  2018-10-31 17:01  0%   ` Dmitry A. Kazakov
@ 2018-11-01 12:49  0%   ` Björn Lundin
  1 sibling, 0 replies; 200+ results
From: Björn Lundin @ 2018-11-01 12:49 UTC (permalink / raw)


On 2018-10-31 16:28, eduardsapotski@gmail.com wrote:
> Let's make it easier. For example:
> 
> ------------------------------------------------------------------
> 
> with Ada.Strings.Unbounded;     use Ada.Strings.Unbounded;
> with Ada.Text_IO.Unbounded_IO;  use Ada.Text_IO.Unbounded_IO;
> 
> with AWS.Client;            use AWS.Client;
> with AWS.Messages;          use AWS.Messages;
> with AWS.Response;          use AWS.Response;
> 
> procedure Main is
> 
>    HTML_Result   : Unbounded_String;
>    Request_Header_List : Header_List;
> 
> begin
> 
>    Request_Header_List.Add(Name => "User-Agent", Value => "Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0");
> 
>    HTML_Result := Message_Body(Get(URL => "http://www.sql.ru/", Headers => Request_Header_List));
> 
>    Put_Line(HTML_Result);
> 
> end Main;
> 
> ------------------------------------------------------------------
> 
> My linux terminal (default UTF-8) show: https://photos.app.goo.gl/EPgwKoiFSuwkJvgSA
> 
> If set encoding in terminal Windows-1251 - all is well: https://photos.app.goo.gl/goN5g7uofD8rYLP79
> 
> Are there standard ways to solve this problem?
> 


In xml/ada there are unicode packages.

something like (with changes for 1251 instead of Latin_1 to be done)

with Unicode.Ces.Utf8, Unicode.Ces.Utf32, Unicode.Ces.Basic_8bit,
Unicode.Ccs.ISO_8859_1;
use Unicode, Unicode.Ccs, Unicode.Ces, Unicode.Ces.Utf8, Unicode.Ces.Utf32;

--some with are likely not needed, code copied from bigger function


 function To_Utf_8_From_Latin_1_Little_Endian
     (A_Latin_1_Encoded_String : in String)
      return String is

    --  32-bit Latin-1 string (normal Ada string with 32-bit characters)
    S_32 : Unicode.Ces.Utf32.Utf32_Le_String :=
       Unicode.Ces.Basic_8bit.To_Utf32 (A_Latin_1_Encoded_String);

    --  UTF-32 string (convert Latin-1 to Unicode characters)
    U_32 : Unicode.Ces.Utf32.Utf32_Le_String :=
       Unicode.Ces.Utf32.To_Unicode_Le
          (S_32,
           Cs => Unicode.Ccs.ISO_8859_1.ISO_8859_1_Character_Set);
    -- change UTF-32 to UTF-8
    An_Utf_8_Encoded_String_Le : Unicode.Ces.Utf8.Utf8_String :=
Unicode.Ces.Utf8.From_Utf32 (U_32);

  begin
    return An_Utf_8_Encoded_String_Le;
  end To_Utf_8_From_Latin_1_Little_Endian;

---------------------------------------------------------------------------------


It's a starting point

-- 
--
Björn

^ permalink raw reply	[relevance 0%]

* Re: windows-1251 to utf-8
  2018-10-31 17:01  0%   ` Dmitry A. Kazakov
@ 2018-10-31 20:58  2%     ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2018-10-31 20:58 UTC (permalink / raw)


>Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
>news:prcn4v$d30$1@gioia.aioe.org...
> On 2018-10-31 16:28, eduardsapotski@gmail.com wrote:
>> Let's make it easier. For example:
>>
>> ------------------------------------------------------------------
>>
>> with Ada.Strings.Unbounded;     use Ada.Strings.Unbounded;
>> with Ada.Text_IO.Unbounded_IO;  use Ada.Text_IO.Unbounded_IO;
>>
>> with AWS.Client;            use AWS.Client;
>> with AWS.Messages;          use AWS.Messages;
>> with AWS.Response;          use AWS.Response;
>>
>> procedure Main is
>>
>>     HTML_Result   : Unbounded_String;
>>     Request_Header_List : Header_List;
>>
>> begin
>>
>>     Request_Header_List.Add(Name => "User-Agent", Value => "Mozilla/5.0 
>> (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0");
>>
>>     HTML_Result := Message_Body(Get(URL => "http://www.sql.ru/", Headers 
>> => Request_Header_List));
>>
>>     Put_Line(HTML_Result);
>>
>> end Main;
>>
>> ------------------------------------------------------------------
>>
>> My linux terminal (default UTF-8) show: 
>> https://photos.app.goo.gl/EPgwKoiFSuwkJvgSA
>>
>> If set encoding in terminal Windows-1251 - all is well: 
>> https://photos.app.goo.gl/goN5g7uofD8rYLP79
>>
>> Are there standard ways to solve this problem?
>
> What problem? The page uses the content charset=windows-1251. It is legal.
>
> Your program is illegal as it prints the body using Put_Line. Ada standard 
> requires Character be Latin-1. The only case when your program would be 
> correct is when charset=ISO-8859-1.
>
> You must convert the page body according to the encoding specified by the 
> charset key into a string containing UTF-8 octets and use 
> Streams.Stream_IO to write these octets as-is. The conversion for the case 
> of windows-1251 I described earlier. Create a table Character'Pos 
> 0..255 -> Code_Point and use it for each "character" of HTML_Result.
>
> P.S. GNAT Text_IO ignores Latin-1, but that is between GNAT and the 
> underlying OS.
>
> P.P.S. Technically AWS also ignores Ada standard. But that is an 
> established practice. Since there is no better way.

Right. Probably the easiest way to do this (using just Ada functions) would 
be to:

 (A)  Use Ada.Characters to convert the To_String of the unbounded string to 
a Wide_String, and then store that in a Wide_Unbounded_String (or is that a 
Unbounded_Wide_String?)
 (B) Use Ada.Strings.Wide_Maps to create a character conversion map (the 
conversions were described by another reply);
 (C) Use Ada.Strings.Wide_Unbounded.Translate to apply the mapping from (B) 
to your Wide_Unbounded_String.
(D) Use Ada.Strings.UTF_Encoding.Wide_Strings.Encode to convert 
To_Wide_String to your translated Wide_Unbounded_String, presumably storing 
the result into a Unbounded_String.

You potentially could skip (D) if Wide_Text_IO works when sent to 
Standard_Output (I'd expect that on Windows, no idea on Linux). In that 
case, use Wide_Text_IO.Put to send your result.

In any case, this shows why Unicode exists, and why anything these days that 
uses non-standard encodings is evil. There's really no short-cut to recoding 
such things, and that makes them maddening.

                                  Randy.





^ permalink raw reply	[relevance 2%]

* Re: windows-1251 to utf-8
  2018-10-31 15:28  2% ` eduardsapotski
@ 2018-10-31 17:01  0%   ` Dmitry A. Kazakov
  2018-10-31 20:58  2%     ` Randy Brukardt
  2018-11-01 12:49  0%   ` Björn Lundin
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-10-31 17:01 UTC (permalink / raw)


On 2018-10-31 16:28, eduardsapotski@gmail.com wrote:
> Let's make it easier. For example:
> 
> ------------------------------------------------------------------
> 
> with Ada.Strings.Unbounded;     use Ada.Strings.Unbounded;
> with Ada.Text_IO.Unbounded_IO;  use Ada.Text_IO.Unbounded_IO;
> 
> with AWS.Client;            use AWS.Client;
> with AWS.Messages;          use AWS.Messages;
> with AWS.Response;          use AWS.Response;
> 
> procedure Main is
> 
>     HTML_Result   : Unbounded_String;
>     Request_Header_List : Header_List;
> 
> begin
> 
>     Request_Header_List.Add(Name => "User-Agent", Value => "Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0");
> 
>     HTML_Result := Message_Body(Get(URL => "http://www.sql.ru/", Headers => Request_Header_List));
> 
>     Put_Line(HTML_Result);
> 
> end Main;
> 
> ------------------------------------------------------------------
> 
> My linux terminal (default UTF-8) show: https://photos.app.goo.gl/EPgwKoiFSuwkJvgSA
> 
> If set encoding in terminal Windows-1251 - all is well: https://photos.app.goo.gl/goN5g7uofD8rYLP79
> 
> Are there standard ways to solve this problem?

What problem? The page uses the content charset=windows-1251. It is legal.

Your program is illegal as it prints the body using Put_Line. Ada 
standard requires Character be Latin-1. The only case when your program 
would be correct is when charset=ISO-8859-1.

You must convert the page body according to the encoding specified by 
the charset key into a string containing UTF-8 octets and use 
Streams.Stream_IO to write these octets as-is. The conversion for the 
case of windows-1251 I described earlier. Create a table Character'Pos 
0..255 -> Code_Point and use it for each "character" of HTML_Result.

P.S. GNAT Text_IO ignores Latin-1, but that is between GNAT and the 
underlying OS.

P.P.S. Technically AWS also ignores Ada standard. But that is an 
established practice. Since there is no better way.

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

^ permalink raw reply	[relevance 0%]

* Re: windows-1251 to utf-8
  @ 2018-10-31 15:28  2% ` eduardsapotski
  2018-10-31 17:01  0%   ` Dmitry A. Kazakov
  2018-11-01 12:49  0%   ` Björn Lundin
  0 siblings, 2 replies; 200+ results
From: eduardsapotski @ 2018-10-31 15:28 UTC (permalink / raw)


Let's make it easier. For example:

------------------------------------------------------------------

with Ada.Strings.Unbounded;     use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;  use Ada.Text_IO.Unbounded_IO;

with AWS.Client;            use AWS.Client;
with AWS.Messages;          use AWS.Messages;
with AWS.Response;          use AWS.Response;

procedure Main is

   HTML_Result   : Unbounded_String;
   Request_Header_List : Header_List;

begin

   Request_Header_List.Add(Name => "User-Agent", Value => "Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0");

   HTML_Result := Message_Body(Get(URL => "http://www.sql.ru/", Headers => Request_Header_List));

   Put_Line(HTML_Result);

end Main;

------------------------------------------------------------------

My linux terminal (default UTF-8) show: https://photos.app.goo.gl/EPgwKoiFSuwkJvgSA

If set encoding in terminal Windows-1251 - all is well: https://photos.app.goo.gl/goN5g7uofD8rYLP79

Are there standard ways to solve this problem?

^ permalink raw reply	[relevance 2%]

* Re: Simple hash or pseudo-random function
  2018-07-18 13:38  0%       ` gautier_niouzes
@ 2018-08-01  9:08  2%         ` gautier_niouzes
  0 siblings, 0 replies; 200+ results
From: gautier_niouzes @ 2018-08-01  9:08 UTC (permalink / raw)


Just a followup on the last remark: as expected, GNAT's Hash function gives consecutive values for consecutive characters at the end of the string. People may want to append some constant string to get randomness in the hash code.

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Hash;

procedure Hash_test is
begin
  Put_Line (Ada.Strings.Hash ("Abcd")'Image);
  Put_Line (Ada.Strings.Hash ("Bbcd")'Image);
  Put_Line (Ada.Strings.Hash ("Cbcd")'Image);
  Put_Line ("--");
  Put_Line (Ada.Strings.Hash ("abCd")'Image);
  Put_Line (Ada.Strings.Hash ("abDd")'Image);
  Put_Line (Ada.Strings.Hash ("abEd")'Image);
  Put_Line ("--");
  Put_Line (Ada.Strings.Hash ("abcD")'Image);
  Put_Line (Ada.Strings.Hash ("abcE")'Image);
  Put_Line (Ada.Strings.Hash ("abcF")'Image);
end Hash_test;

 14682274
 795269473
 1575856672
--
 3516536994
 3516602593
 3516668192
--
 3518636130
 3518636131
 3518636132

NB: same behavior for ObjectAda (reverting here to pure Ada 2005 syntax):

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

procedure Hash_test is
begin
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("Abcd")));
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("Bbcd")));
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("Cbcd")));
  Put_Line ("--");                                    
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("abCd")));
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("abDd")));
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("abEd")));
  Put_Line ("--");                                    
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("abcD")));
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("abcE")));
  Put_Line (Hash_Type'Image (Ada.Strings.Hash ("abcF")));
end Hash_test;

 803596578
 1584183777
 2364770976
--
 10484002
 10549601
 10615200
--
 12583138
 12583139
 12583140

^ permalink raw reply	[relevance 2%]

* Re: Simple hash or pseudo-random function
  2018-07-17  6:09  1%     ` Jeffrey R. Carter
@ 2018-07-18 13:38  0%       ` gautier_niouzes
  2018-08-01  9:08  2%         ` gautier_niouzes
  0 siblings, 1 reply; 200+ results
From: gautier_niouzes @ 2018-07-18 13:38 UTC (permalink / raw)


Am Dienstag, 17. Juli 2018 08:09:10 UTC+2 schrieb Jeffrey R. Carter:

> Another possibility would be to try (calling your 64-bit type U64)
> 
> subtype S8 is String (1 .. 8);
> 
> function To_S8 is new Ada.Unchecked_Conversion (Source => U64, Target => S8);
> 
> Ada.Strings.Hash (To_S8 (N) );
> 
> If Hash is a decent hash function ("It should be unlikely for similar strings to 
> return the same value.") then it might be sufficiently random.

Brillant, works as expected (after a few adjustments on the final range to be really uniform).

Looking at GNAT's s-strhas.adb :

      H := 0;
      for J in Key'Range loop
         H := Char_Type'Pos (Key (J))
                + Shift_Left (H, 6) + Shift_Left (H, 16) - H;
      end loop;

I guess it is "random" enough on small changes of Key (Key'First .. Key'Last - 1) or on small changes (+1 or -1) of N if U64's are stored as little-endian.


^ permalink raw reply	[relevance 0%]

* Re: Simple hash or pseudo-random function
  @ 2018-07-17  6:09  1%     ` Jeffrey R. Carter
  2018-07-18 13:38  0%       ` gautier_niouzes
  0 siblings, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2018-07-17  6:09 UTC (permalink / raw)


On 07/16/2018 11:14 PM, gautier_niouzes@hotmail.com wrote:
> 
> The 64-bit value is the *input* and the output is a function of that input only.
> e.g.
> 10562032 gives always 211
> 31375393 gives always 31
> 85232830 gives always 172
> NB: the input codes can appear in a different order, so a pseudo-random *sequence* cannot be used.
> 
> I've tested different RNG's by initializing them with the input code and using only the first pseudo-random value using that seed. The good news is that they seem uniformly distributed even with successive seed values, but they are not random enough when seeds are similar. I'll check Marius' solution, or a hash function like CRC.

That makes things clearer. I would have suggested what you tried. Perhaps you 
could modify it a bit so that, for a value N, you discard the 1st N rem M values 
from the RNG before generating the output for N, and see if that improves the 
randomness of the results. M should be small enough that this is fast enough for 
your requirements but large enough to be significantly different from what 
you've already tried.

Another possibility would be to try (calling your 64-bit type U64)

subtype S8 is String (1 .. 8);

function To_S8 is new Ada.Unchecked_Conversion (Source => U64, Target => S8);

Ada.Strings.Hash (To_S8 (N) );

If Hash is a decent hash function ("It should be unlikely for similar strings to 
return the same value.") then it might be sufficiently random.

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


^ permalink raw reply	[relevance 1%]

* Re: Unknown constraints and type composition
  @ 2018-07-08 13:53  2%     ` Jacob Sparre Andersen
  0 siblings, 0 replies; 200+ results
From: Jacob Sparre Andersen @ 2018-07-08 13:53 UTC (permalink / raw)


J-P. Rosen wrote:

> Even better, the default can be a raise expression (or a function that
> raises an exception for pre-2012), so no uninitialized object can be
> created. This is a run-time check, but a decent compiler would warn
> you at compile time.

This does not give a warning at compile time with FSF GNAT 8
(Debian/sid), nor with GNAT CE 2018, but you get the correct run-time
error with both compilers:

   private with Ada.Strings.Unbounded;
   
   package Initialisation_Required is
   
      type Instance is private;
   
      function Create (Name : in String) return Instance;
   
   private
   
      type Instance is
         record
            Name : Ada.Strings.Unbounded.Unbounded_String := raise Constraint_Error with "Uninitialised object.";
         end record;
   
   end Initialisation_Required;

   package body Initialisation_Required is
   
      function Create (Name : in String) return Instance is
      begin
         return R : Instance do
            R.Name := Ada.Strings.Unbounded.To_Unbounded_String (Name);
         end return;
      end Create;
   
   end Initialisation_Required;

   with Initialisation_Required;
   
   procedure Demo is
      O : Initialisation_Required.Instance := Initialisation_Required.Create (Name => "Hello");
   begin
      O := Initialisation_Required.Create (Name => "Hello");
   end Demo;

Another problem with this is that you can't wait until you leave your
internal constructor function, before the initialisation has to happen.

With the example above, you get your exception already at "return R :
Instance do", which isn't what we want.  (Easy to work around, but
something you should be aware of.)

Greetings,

Jacob
-- 
"Sleep is just a cheap substitute for coffee"

^ permalink raw reply	[relevance 2%]

* Re: Strange crash on custom iterator
  2018-07-05 17:19  1%                                                                       ` Dan'l Miller
@ 2018-07-05 19:14  0%                                                                         ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2018-07-05 19:14 UTC (permalink / raw)


On Thursday, July 5, 2018 at 11:20:00 AM UTC-6, Dan'l Miller wrote:
> 
> But, Shark8, you seem to criticizing something a little different than that.  In some alternate universe where Unicode or ISO10646 transpired entirely differently, what would Unicode-done-right* look like, especially w.r.t. Ada strings.  It seems that you are alluding to some sort of multiple-strand string or something like that (not merely allocating the billion nonBMP codepoints better so that we would have a one-letter-one-codepoint axiom). 

Well, Ada does like 'disassembling' things [concepts, etc] into usable component pieces, traditionally-speaking. So, I'd expect the multilingual problem-space would likely be decomposed into some usable/useful sets of types/subprograms.

To borrow from other ISO stuff, perhaps something like:

-- ISO 639-1
PACKAGE LANGUAGES IS
  Type Code is ( ab, aa, [...], za, zu );
  -- other stuff.
END LANGUAGES;

PACKAGE LANGUAGES.CONSTRUCTS IS
   -- A Text is a full sequence of linguistically meaningful data, a sequence of contexts.
   Type Text is private;
   -- subprograms...
   
   -- Essentailly a "string" w/ a language context.
   Type Context( Language : Code; Length : Natural ) is private;
   -- subprograms
PRIVATE
  --...
END LANGUAGES.CONSTRUCTS;

Or something; the point is the preservation of the structure/context of the sequence-of-symbols\words\graphemes\whatever to provide a solid multilingual foundation rather than throwing away all context, shoving everything in the Unicode-blender and having to deal with string-of-hexadecimal-sludge (codepoints) which, in-turn, forces reconstruction of the lost structures and contexts... maybe involving the [ab]use of RegEx, that always seems to be an answer when dealing with textually-represented data, hence why so many of our peers seem to think that RegEx is suitable for parsing/processing HTML....

Yes, it bucks the "everything is a string" mentality of C/unix influenced OS-APIs; where the analog of a path would be an actual vector of names [eg ("root", "projects", "source", "file.adb")] rather than a plain text-string [eg "root\projects\source\file.adb"] if applied to the OS as well.

The whole purpose is, as stated up-thread, "to aid the creative craftsman, not enforce mediocrity".


^ permalink raw reply	[relevance 0%]

* Re: Strange crash on custom iterator
  @ 2018-07-05 17:19  1%                                                                       ` Dan'l Miller
  2018-07-05 19:14  0%                                                                         ` Shark8
  0 siblings, 1 reply; 200+ results
From: Dan'l Miller @ 2018-07-05 17:19 UTC (permalink / raw)


On Thursday, July 5, 2018 at 11:47:33 AM UTC-5, Shark8 wrote:
> On Wednesday, July 4, 2018 at 8:07:56 PM UTC-6, Luke A. Guest wrote:
> > Shark8 wrote:
> > 
> > >> Shark8, what would be the better solution for character-encoding itself?
> > >>  (not whole words)
> > > 
> > > Whole-word isn't a terrible idea, per se. But the thrust I was getting at
> > > is the delination between languages: with Unicode it's a sequence of
> > > codepoints, independent of the actual item (word, sentence, etc) other
> > > than [perhaps] graphic-presented. That the example is (Eng,Eng,Eng...Eng,
> > > Heb,Heb,Heb,Heb, Eng,Eng,Eng...) codepoints is not the problem, though
> > > related, because it discards all information in favor of (num, num, num,
> > > num, ...) rather than actually considering alternate languages: IMO,
> > > ("The Hebrew word for man" (quote ADAM) (quote "Adam") ".") is much
> > > better as 'text' because we're preserving structure: [ENGLISH [THIS
> > > SECTION HEBREW] ENGLISH].
> > > 
> > 
> > I don’t understand why you think Unicode should carry linguistic
> > information when all it has ever been designed to do is encode symbols
> > across all languages and their direction.
> 
> I'm not saying that "Unicode should" do *anything* -- I'm saying Unicode solves *the wrong problem*.
> 
> "Encoding symbols" ties everything to a stupidly primitive level, forcing everything to such lowest
> common denominator so as to apply "the unix way" processing to text: discard all structural information,
> all semantic information, and have "some tool" regenerate it later... just like "the unix way" discards
> type-information in favor of forcing ad-hoc parsing on unstructured-text at every step between it's
> "small tools" connected together with 'pipes'.

At some level I could conceivably agree with you in principle that a strictly-linear sequence of unadorned symbols is too low-level is some designs to be useful.  For example, there was a time in the 1970s through early 1980s when Texas Instruments microprocessors excessively modeled a Turing machine's tapes (dual-tape model).  No one nowadays would think that a processor should be strictly & intentionally designed to overtly model a Turing machine directly right down to the linear streams/tapes of symbols.

Unicode/ISO10646 is asinine in its insistence on a sequence of •multiple• codepoints being the ••shortest possible•• representation of some individual letter in some natural language.  Programmers want one-letter-one-codepoint representation in all languages—not some Turing-machine tape to process sequentially statefully, as Unicode demands even in its 32-bit UCS4 or UTF-32 representations.  Programmers don't want any “well, yeah but …” situations at all when they just finished executing the fully-normalize-all-the-codepoints-in-this-string subprogram (but that “well yeah but …” is the world we suffer in with Unicode/ISO10646 as currently defined).

But, Shark8, you seem to criticizing something a little different than that.  In some alternate universe where Unicode or ISO10646 transpired entirely differently, what would Unicode-done-right* look like, especially w.r.t. Ada strings.  It seems that you are alluding to some sort of multiple-strand string or something like that (not merely allocating the billion nonBMP codepoints better so that we would have a one-letter-one-codepoint axiom). 

* Yeah, I know, in Unicode done right, there wouldn't be any Unicode or ISO10646 at all, but what would there be instead and what would the strawman look like at all in Ada?

^ permalink raw reply	[relevance 1%]

* Re: Strange crash on custom iterator
  2018-07-03 14:17  1%                       ` J-P. Rosen
@ 2018-07-03 15:06  0%                         ` Lucretia
    0 siblings, 1 reply; 200+ results
From: Lucretia @ 2018-07-03 15:06 UTC (permalink / raw)


On Tuesday, 3 July 2018 15:17:14 UTC+1, J-P. Rosen  wrote:
> Le 03/07/2018 à 16:08, Lucretia a écrit :
> >    type Unicode_String is array (Positive range <>) of Integer;
> Array of Integer???? For a Unicode_String...

Firstly read the rest of this thread, secondly, i should've renamed that in that simple test, because IT'S A TEST to show an error in the compiler. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86391

> Btw, do you know the package Ada.Strings.UTF_Encoding ?

Yes, I'm well aware of this completely useless type.

1) It's a subtype of String, which is incorrect as UTF-8 is not a superset of Latin 1, this should never have been allowed.

2) Ada needs a decent Unicode library not this half-arsed crap we have now.

^ permalink raw reply	[relevance 0%]

* Re: Strange crash on custom iterator
  @ 2018-07-03 14:17  1%                       ` J-P. Rosen
  2018-07-03 15:06  0%                         ` Lucretia
  0 siblings, 1 reply; 200+ results
From: J-P. Rosen @ 2018-07-03 14:17 UTC (permalink / raw)


Le 03/07/2018 à 16:08, Lucretia a écrit :
>    type Unicode_String is array (Positive range <>) of Integer;
Array of Integer???? For a Unicode_String...

Btw, do you know the package Ada.Strings.UTF_Encoding ?

-- 
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: Strange crash on custom iterator
  @ 2018-07-02 19:42  1%                   ` Simon Wright
    0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2018-07-02 19:42 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 450 bytes --]

Luke A. Guest <laguest@archeia.com> writes:

> Simon Wright <> wrote:
>
>>> You don't need to make it tagged, to pass it by reference.  It is enough
>>> to make the formal parameter aliased.
>> 
>> Yes, that works (except you have to make the container you're iterating
>> over aliased too).
>
> I had to make the iterate for nation take “aliased in out” and make the
> array aliased, but it still does in the same place.

This worked for me ..


[-- Attachment #2: gnatchop-me --]
[-- Type: text/plain, Size: 9880 bytes --]

--  Copyright 2018, Luke A. Guest
--  License TBD.

with Ada.Characters.Latin_1;
with Ada.Text_IO; use Ada.Text_IO;
with UCA.Encoding;
with UCA.Iterators;

procedure Test is
   package L1 renames Ada.Characters.Latin_1;

   package Octet_IO is new Ada.Text_IO.Modular_IO (UCA.Octets);
   use Octet_IO;

   --  D  : UCA.Octets         := Character'Pos ('Q');
   --  A  : UCA.Unicode_String := UCA.To_Array (D);
   --  A2 : UCA.Unicode_String := UCA.Unicode_String'(1, 0, 0, 0, 0, 0, 1, 0);
   --  D2 : UCA.Octets         := UCA.To_Octet (A2);

   --  package OA_IO is new Ada.Text_IO.Integer_IO (Num => UCA.Bits);

   use UCA.Encoding;
   A : aliased UCA.Unicode_String :=
     +("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ" & L1.LF &
         "Hello, world" & L1.LF &
         "Sîne klâwen durh die wolken sint geslagen," & L1.LF &
         "Τη γλώσσα μου έδωσαν ελληνική" & L1.LF &
         "मैं काँच खा सकता हूँ और मुझे उससे कोई चोट नहीं पहुंचती." & L1.LF &
         "میں کانچ کھا سکتا ہوں اور مجھے تکلیف نہیں ہوتی");
   B : aliased UCA.Unicode_String :=
     (225, 154, 160, 225, 155, 135, 225, 154, 187, 225, 155, 171, 225, 155, 146, 225, 155, 166, 225,
      154, 166, 225, 155, 171, 225, 154, 160, 225, 154, 177, 225, 154, 169, 225, 154, 160, 225, 154,
      162, 225, 154, 177, 225, 155, 171, 225, 154, 160, 225, 155, 129, 225, 154, 177, 225, 154, 170,
      225, 155, 171, 225, 154, 183, 225, 155, 150, 225, 154, 187, 225, 154, 185, 225, 155, 166, 225,
      155, 154, 225, 154, 179, 225, 154, 162, 225, 155, 151,
      10,
      72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100,
      10,
      83, 195, 174, 110, 101, 32, 107, 108, 195, 162, 119, 101, 110, 32, 100, 117, 114, 104, 32, 100,
      105, 101, 32, 119, 111, 108, 107, 101, 110, 32, 115, 105, 110, 116, 32, 103, 101, 115, 108, 97,
      103, 101, 110, 44,
      10,
      206, 164, 206, 183, 32, 206, 179, 206, 187, 207, 142, 207, 131, 207, 131, 206, 177, 32, 206, 188,
      206, 191, 207, 133, 32, 206, 173, 206, 180, 207, 137, 207, 131, 206, 177, 206, 189, 32, 206, 181,
      206, 187, 206, 187, 206, 183, 206, 189, 206, 185, 206, 186, 206, 174,
      10,
      224, 164, 174, 224, 165, 136, 224, 164, 130, 32, 224, 164, 149, 224, 164, 190, 224, 164, 129, 224,
      164, 154, 32, 224, 164, 150, 224, 164, 190, 32, 224, 164, 184, 224, 164, 149, 224, 164, 164, 224,
      164, 190, 32, 224, 164, 185, 224, 165, 130, 224, 164, 129, 32, 224, 164, 148, 224, 164, 176, 32,
      224, 164, 174, 224, 165, 129, 224, 164, 157, 224, 165, 135, 32, 224, 164, 137, 224, 164, 184, 224,
      164, 184, 224, 165, 135, 32, 224, 164, 149, 224, 165, 139, 224, 164, 136, 32, 224, 164, 154, 224,
      165, 139, 224, 164, 159, 32, 224, 164, 168, 224, 164, 185, 224, 165, 128, 224, 164, 130, 32, 224,
      164, 170, 224, 164, 185, 224, 165, 129, 224, 164, 130, 224, 164, 154, 224, 164, 164, 224, 165, 128, 46,
      10,
      217, 133, 219, 140, 218, 186, 32, 218, 169, 216, 167, 217, 134, 218, 134, 32, 218, 169, 218, 190,
      216, 167, 32, 216, 179, 218, 169, 216, 170, 216, 167, 32, 219, 129, 217, 136, 218, 186, 32, 216,
      167, 217, 136, 216, 177, 32, 217, 133, 216, 172, 218, 190, 219, 146, 32, 216, 170, 218, 169, 217,
      132, 219, 140, 217, 129, 32, 217, 134, 219, 129, 219, 140, 218, 186, 32, 219, 129, 217, 136, 216,
      170, 219, 140);
begin
--   Put_Line ("A => " & To_UTF_8_String (A));
   Put_Line ("A => " & L1.LF & String (+A));

   Put_Line ("A => ");
   Put ('(');

   for E of A loop
      Put (Item => E, Base => 2);
      Put (", ");
   end loop;

   Put (')');
   New_Line;

   Put_Line ("B => " & L1.LF & String (+B));

   Put_Line ("A (Iterated) => ");

   for I in UCA.Iterators.Iterate (A) loop
      Put (UCA.Iterators.Element (I));       --  ERROR! Dies in Element, Data has nothing gdb => p position - $1 = (data => (), index => 1)
   end loop;

   New_Line;
end Test;

with Ada.Strings.UTF_Encoding;
with Ada.Unchecked_Conversion;

package UCA is
   use Ada.Strings.UTF_Encoding;

   type Octets is mod 2 ** 8 with
     Size => 8;

   type Unicode_String is array (Positive range <>) of Octets with
     Pack => True;

   type Unicode_String_Access is access all Unicode_String;

   --  This should match Wide_Wide_Character in size.
   type Code_Points is mod 2 ** 32 with
     Static_Predicate => Code_Points in 0 .. 16#0000_D7FF# or Code_Points in 16#0000_E000# .. 16#0010_FFFF#,
     Size             => 32;

private
   type Bits is range 0 .. 1 with
     Size => 1;

   type Bit_Range is range 0 .. Octets'Size - 1;
end UCA;

with Ada.Finalization;
with Ada.Iterator_Interfaces;
private with System.Address_To_Access_Conversions;

package UCA.Iterators is
   ---------------------------------------------------------------------------------------------------------------------
   --  Iteration over code points.
   ---------------------------------------------------------------------------------------------------------------------
   type Cursor is private;
   pragma Preelaborable_Initialization (Cursor);

   function Has_Element (Position : in Cursor) return Boolean;

   function Element (Position : in Cursor) return Octets;

   package Code_Point_Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element);

   function Iterate (Container : aliased in Unicode_String) return Code_Point_Iterators.Forward_Iterator'Class;
   function Iterate (Container : aliased in Unicode_String; Start : in Cursor) return
     Code_Point_Iterators.Forward_Iterator'Class;

   ---------------------------------------------------------------------------------------------------------------------
   --  Iteration over grapheme clusters.
   ---------------------------------------------------------------------------------------------------------------------
private
   use Ada.Finalization;

   package Convert is new System.Address_To_Access_Conversions (Unicode_String);

   type Cursor is
      record
         Data  : Convert.Object_Pointer := null;
         Index : Positive               := Positive'Last;
      end record;

   type Code_Point_Iterator is new Limited_Controlled and Code_Point_Iterators.Forward_Iterator with
      record
         Data  : Convert.Object_Pointer := null;
      end record;

   overriding
   function First (Object : in Code_Point_Iterator) return Cursor;

   overriding
   function Next  (Object : in Code_Point_Iterator; Position : Cursor) return Cursor;

end UCA.Iterators;

with Ada.Text_IO; use Ada.Text_IO;

package body UCA.Iterators is
   package Octet_IO is new Ada.Text_IO.Modular_IO (UCA.Octets);
   use Octet_IO;

   use type Convert.Object_Pointer;

   function Has_Element (Position : in Cursor) return Boolean is
   begin
      return Position.Index in Position.Data'Range;
   end Has_Element;

   function Element (Position : in Cursor) return Octets is
   begin
      if Position.Data = null then
         raise Constraint_Error with "Fuck!";
      end if;
      Put ("<< Element - " & Positive'Image (Position.Index) & " - ");
      Put (Position.Data (Position.Index));
      Put_Line (" >>");

      return Position.Data (Position.Index);
   end Element;

   function Iterate (Container : aliased in Unicode_String) return Code_Point_Iterators.Forward_Iterator'Class is
   begin
      Put_Line ("<< iterate >>");
      return I : Code_Point_Iterator := (Limited_Controlled with
        Data => Convert.To_Pointer (Container'Address)) do
         if I.Data = null then
            Put_Line ("Data => null");
         else
            Put_Line ("Data => not null - Length: " & Positive'Image (I.Data'Length));
         end if;
         null;
      end return;
   end Iterate;

   function Iterate (Container : aliased in Unicode_String; Start : in Cursor) return
     Code_Point_Iterators.Forward_Iterator'Class is
   begin
      Put_Line ("<< iterate >>");
      return I : Code_Point_Iterator := (Limited_Controlled with
        Data => Convert.To_Pointer (Container'Address)) do
         if I.Data = null then
            Put_Line ("Data => null");
         else
            Put_Line ("Data => not null");
         end if;
         null;
      end return;
   end Iterate;

   ---------------------------------------------------------------------------------------------------------------------
   --  Iteration over grapheme clusters.
   ---------------------------------------------------------------------------------------------------------------------
   overriding
   function First (Object : in Code_Point_Iterator) return Cursor is
   begin
      return (Data => Object.Data, Index => Positive'First);
   end First;

   overriding
   function Next  (Object : in Code_Point_Iterator; Position : Cursor) return Cursor is
   begin
      return (Data => Object.Data, Index => Position.Index + 1);
   end Next;
end UCA.Iterators;

--  Copyright © 2018, Luke A. Guest
with Ada.Unchecked_Conversion;

package body UCA.Encoding is
   function To_Unicode_String (Str : in String) return Unicode_String is
      Result : Unicode_String (1 .. Str'Length) with
        Address => Str'Address;
   begin
      return Result;
   end To_Unicode_String;

   function To_String (Str : in Unicode_String) return String is
      Result : String (1 .. Str'Length) with
        Address => Str'Address;
   begin
      return Result;
   end To_String;
end UCA.Encoding;

package UCA.Encoding is
   use Ada.Strings.UTF_Encoding;

   function To_Unicode_String (Str : in String) return Unicode_String;
   function To_String (Str : in Unicode_String) return String;

   function "+" (Str : in String) return Unicode_String renames To_Unicode_String;
   function "+" (Str : in Unicode_String) return String renames To_String;
end UCA.Encoding;

^ permalink raw reply	[relevance 1%]

* Strings with discriminated records
@ 2018-05-26 21:43  2% NiGHTS
  0 siblings, 0 replies; 200+ results
From: NiGHTS @ 2018-05-26 21:43 UTC (permalink / raw)


I know that Ada Strings are an unconstrained type, and so you can't use them in records. But if a discriminated record is being passed a String parameter which is then being assigned to a String object in a record, the string is being constrained at the instantiation of the record. So shouldn't the compiler allow this configuration since it has enough information to allocate the memory required for the record?

Either way, considering this unfortunate Ada limitation, is there a workaround that can assign a string's default value on a record using a discriminant? Is there a way to do this with Fixed or bounded strings?

Thank you for your help!

^ permalink raw reply	[relevance 2%]

* Re: How to get Ada to “cross the chasm”?
  @ 2018-05-06 16:58  2%                     ` Jacob Sparre Andersen
  0 siblings, 0 replies; 200+ results
From: Jacob Sparre Andersen @ 2018-05-06 16:58 UTC (permalink / raw)


Paul Rubin wrote:
> Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

>> One reason is that when a function evaluates an expression that
>> creates an object of a large, dynamic size (eg. an array expression)
>> on the secondary stack, this object can be returned /in situ/ as the
>> function's return value, without being copied.
>
> Ok, but that pattern is so common that allocating the space in the
> primary stack before calling the function is a standard optimization
> that every serious C++ compiler knows how to do.  Then the function
> writes the result into the primary stack and the caller can still use
> it after the function returns.  Could Ada not do it the same way?

How would you do it with this example?

   with Ada.Numerics.Discrete_Random;
   with Ada.Strings.Fixed;
   with Ada.Text_IO;
   
   procedure Random_String is
   
      subtype Lengths is Integer range 10 .. 20;
   
      package Random_Lengths is
        new Ada.Numerics.Discrete_Random (Result_Subtype => Lengths);
   
      Generator : Random_Lengths.Generator;
   
      function Example (C : in Character) return String is
         use Ada.Strings.Fixed;
      begin
         return Random_Lengths.Random (Generator) * C;
      end Example;
   
   begin
      Random_Lengths.Reset (Generator);
   
      Ada.Text_IO.Put_Line (Example ('H'));
      Ada.Text_IO.Put_Line (Example ('e'));
      Ada.Text_IO.Put_Line (Example ('l'));
      Ada.Text_IO.Put_Line (Example ('l'));
      Ada.Text_IO.Put_Line (Example ('o'));
   end Random_String;

Greetings,

Jacob
-- 
»But you have to be a bit wary of a ship that collects
 snowflakes.«                                  -- Diziet Sma

^ permalink raw reply	[relevance 2%]

* Re: How to get Ada to “cross the chasm”?
  2018-04-30 11:28  1% ` Mehdi Saada
@ 2018-04-30 12:39  0%   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-04-30 12:39 UTC (permalink / raw)


On 2018-04-30 13:28, Mehdi Saada wrote:
> For dictionnaries, you can instantiate ada.strings.bounded ou unbounded, to get a variable-length string, then instantiate Ada.containers.bounded_hashed_maps like this:

Or, I suppose, Containers.Indefinite_Ordered_Maps.

However, from a string map I would expect bit more functionality than 
either map or "dictionary" offers. It also depends on whether the target 
objects in the map must be mutable, have an identity etc.

> Sure, there are no containers aggregates which would make the syntax more natural as in Python,

I don't find Python syntax of aggregates natural. It is rather 
incredibly cumbersome, counter-intuitive, lacks regularity and clarity 
Ada syntax has.

> but it's being studied for the next Ada. It doesn't hinder the use so much, though.

Well, I cautiously doubt it. As the history with iterators and implicit 
derefence shows we unlikely get the syntax and functionality we wanted.

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


^ permalink raw reply	[relevance 0%]

* Re: How to get Ada to “cross the chasm”?
    @ 2018-04-30 11:28  1% ` Mehdi Saada
  2018-04-30 12:39  0%   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: Mehdi Saada @ 2018-04-30 11:28 UTC (permalink / raw)


For dictionnaries, you can instantiate ada.strings.bounded ou unbounded, to get a variable-length string, then instantiate Ada.containers.bounded_hashed_maps like this:

first you have to overload the hash function a bit since it takes only the type String.
function Hash(A: your_string_type) is
(ada.string.Hash(To_String(A)));

then you create your hashed map package:
package hashed_maps is new ada.containers.bounded_hashed_maps
(Key_Type => your_string_type, Element_Type => another_string_type, Hash => Ada.string.Hash, Equivalent_Keys => "=");

and there you have your dictionary.
DIct: Map (Nombre_de_mots_max, Default_modulus(Nombre_de_mots_max));

I let you understand the subprograms, but most of them are self-evident, and repeat themselves all over the containers libraries.

Sure, there are no containers aggregates which would make the syntax more natural as in Python, but it's being studied for the next Ada. It doesn't hinder the use so much, though.


^ permalink raw reply	[relevance 1%]

* Re: CONSTRAINT ERROR? access check failed
  2018-03-01 12:44  2%   ` Mehdi Saada
@ 2018-03-01 13:45  2%     ` Björn Lundin
  0 siblings, 0 replies; 200+ results
From: Björn Lundin @ 2018-03-01 13:45 UTC (permalink / raw)


On 2018-03-01 13:44, Mehdi Saada wrote:
> Those are the two last things I would like you people to review. First, I can't get out of that loop, even with the exit INNER; after "Rentrez vos commandes". It starts it again.
> 

seems strange, since you do exit INNNER.
Are you sure that not something else is happening,
like all this is in a procedure that you call again?


> INNER : loop
...
> 	Put_Line ("Rentrer maintenant vos commandes"); exit INNER;
>     exception when others => Put_Line ("ERREUR");
>     end;
> end loop INNER;
> 
> Then, could you tell what you think of that subprogram that is meant to purge a STRING from non graphic characters (those that make the program crash) ?


 I'm likely gettting bashed for using unbounded string like this,
 but I'd do like this

function Let_Only_Graphic_Characters (Input_String : in String) return
String is
  use Ada.Strings.Unbounded;
  use Ada.Characters.Handling;
  Tmp : Unbounded_String;
begin
  for i in Input_String'range loop
    if Is_Graphic(Input_String(i)) then
      Append(Tmp, Input_String(i));
    end if;
  end loop;
  return To_String(Tmp);
end Let_Only_Graphic_Characters;

or with 'for of' loop

function Let_Only_Graphic_Characters (Input_String : in String) return
String is
  use Ada.Strings.Unbounded;
  use Ada.Characters.Handling;
  Tmp : Unbounded_String;
begin
  for C of Input_String loop
    if Is_Graphic(C) then
      Append(Tmp, C);
    end if;
  end loop;
  return To_String(Tmp);
end Let_Only_Graphic_Characters;



-- 
--
Björn

^ permalink raw reply	[relevance 2%]

* Re: CONSTRAINT ERROR? access check failed
  @ 2018-03-01 12:44  2%   ` Mehdi Saada
  2018-03-01 13:45  2%     ` Björn Lundin
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-03-01 12:44 UTC (permalink / raw)


Those are the two last things I would like you people to review. First, I can't get out of that loop, even with the exit INNER; after "Rentrez vos commandes". It starts it again.

INNER : loop
declare
   NOM_FICHIER : String := Get_Line;
   INDICE      : NATURAL := 0;
   begin
	if Index_Non_Blank (NOM_FICHIER) /= 0
	then
	    if not Exists (NOM_FICHIER) then Put_Line ("N'existe pas. Recommencez."); end if;
	    OPEN (FILE_ENTREE, In_File, NOM_FICHIER);
	    Set_Input (FILE_ENTREE);
	    while not End_Of_File loop
		INDICE := INDICE + 10;
		INSERT_OR_REPLACE (INDICE, LET_ONLY_GRAPHIC_CHARACTERS(GET_LINE));
	    end loop;
        end if;
	Put_Line ("Rentrer maintenant vos commandes"); exit INNER;
    exception when others => Put_Line ("ERREUR");
    end;
end loop INNER;

Then, could you tell what you think of that subprogram that is meant to purge a STRING from non graphic characters (those that make the program crash) ?

 function LET_ONLY_GRAPHIC_CHARACTERS
     (INPUT_STRING : in STRING) return STRING is
      use Ada.Strings.Maps.Constants,
	  Ada.Strings.Maps, Ada.Strings.Fixed, Ada.Strings;
      FIRST, I, COUNT, LAST : NATURal := INPUT_STRING'FIRST;
      OUTPUT_STRING         : STRING (INPUT_STRING'Range);

   begin
      loop
	 FIND_TOKEN (Source => INPUT_STRING (I .. INPUT_STRING'LAST),
	      Set    => Graphic_Set,
	      Test   => Inside ,
	      First  => First,
	      Last   => Last);
	 if Last in INPUT_STRING'Range and LAST /= 0 then
	    OUTPUT_STRING (I .. I + LAST - FIRST) := INPUT_STRING (FIRST .. LAST);
	    I := I + LAST - FIRST + 1;
	 else
	    exit; end if;
      end loop;
      PRAGMA Assert (Index (OUTPUT_STRING(OUTPUT_STRING'First .. 
			    (if I > OUTPUT_STRING'Length then OUTPUT_STRING'Last else I))
			      , GRAPHIC_SET, TEST => Outside) = 0, "CHARACTÈRES NON GRAPHIQUE ONT ECHAPPÉS !");
      return OUTPUT_STRING (OUTPUT_STRING'First .. (if I > OUTPUT_STRING'Length then OUTPUT_STRING'Last else I));
   end;


^ permalink raw reply	[relevance 2%]

* Re: open a file non-blocking ?
  @ 2018-02-26 16:41  2%   ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2018-02-26 16:41 UTC (permalink / raw)


> On Saturday, February 24, 2018 at 2:42:30 PM UTC-5, pat...@spellingbeewinnars.org wrote:
>   
> There does not seem to be an option to open a file non-blocking. Is there a way?

I guess it depends on what you mean by non-blocking. Some of the responses on 
here seem to think it means you can issue a write to the file and it returns 
immediately, without waiting for the write to file to complete.

If that's the case, the normal way to deal with this within Ada is something like

package Write_Queue_Interfaces is new
    Ada.Containers.Synchronized_Queue_Interfaces
       (Element_Type => Ada.Strings.Unbounded.Unbounded_String);

package Write_Queues is new Ada.Containers.Unbounded_Synchornized_Queues
    (Queue_Interfaces => Write_Queue_Interfaces);

Write_Queue : Write_Queues.Queue;

task Writer;

task body Writer is
    File : Ada.Text_IO.File_Type;
    Item : Ada.Strings.Unbounded.Unbounded_String;
begin -- Writer
    Ada.Text_IO.Create (File => File, Name => ...);

    Forever : loop
       Write_Queue.Dequeue (Element => Item);
       Ada.Text_IO.Put_Line
          (File => File, Item => Ada.Strings.Unbounded.To_String (Item) );
    end loop Forever;
end Writer;

Probably in reality you'd want a way to exit the loop and close the file. A task 
wishing to write Msg to the file does

Write_Queue.Enqueue
    (New_Item => Ada.Strings.Unbounded.To_Unbounded_String (Msg) );

-- 
Jeff Carter
"He nevere yet no vileynye ne sayde
In al his lyf unto no maner wight."
Canterbury Tales
156


^ permalink raw reply	[relevance 2%]

* Re: alternative elsif branch not tested
  2018-02-22 23:09  1% ` Mehdi Saada
  2018-02-22 23:29  0%   ` Anh Vo
@ 2018-02-22 23:54  1%   ` Randy Brukardt
  1 sibling, 0 replies; 200+ results
From: Randy Brukardt @ 2018-02-22 23:54 UTC (permalink / raw)


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

I'd suggest looking again at DeMorgan's Law of boolean expressions. I've 
made this mistake dozens of times over the years.

                                 Randy.

"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:fd7c28a6-5605-4521-b9e9-f88b47b9714d@googlegroups.com...
This piece shall verify the program's arguments. I don't understand why 
whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.

      if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre 
d'arguments."); raise Exc_Commande;
      elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' 
| 'C' then
        PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) 
charactère entre n, c, N et C."); raise Exc_Commande;
      elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, 
Outside) /= 0 then
  PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de 
chiffres !"); raise Exc_Commande;
      end if; 


^ permalink raw reply	[relevance 1%]

* Re: alternative elsif branch not tested
  2018-02-22 23:09  1% ` Mehdi Saada
@ 2018-02-22 23:29  0%   ` Anh Vo
  2018-02-22 23:54  1%   ` Randy Brukardt
  1 sibling, 0 replies; 200+ results
From: Anh Vo @ 2018-02-22 23:29 UTC (permalink / raw)


On Thursday, February 22, 2018 at 3:09:17 PM UTC-8, Mehdi Saada wrote:
> This piece shall verify the program's arguments. I don't understand why whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
> It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.
>  
>       if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre d'arguments."); raise Exc_Commande;
>       elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' | 'C' then
>         PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) charactère entre n, c, N et C."); raise Exc_Commande;
>       elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, Outside) /= 0 then
>  	PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de chiffres !"); raise Exc_Commande;
>       end if;

It falls outside of your if check. That means it must be in the else part.

Anh Vo


^ permalink raw reply	[relevance 0%]

* Re: alternative elsif branch not tested
  2018-02-22 22:54  1% alternative elsif branch not tested Mehdi Saada
@ 2018-02-22 23:09  1% ` Mehdi Saada
  2018-02-22 23:29  0%   ` Anh Vo
  2018-02-22 23:54  1%   ` Randy Brukardt
  0 siblings, 2 replies; 200+ results
From: Mehdi Saada @ 2018-02-22 23:09 UTC (permalink / raw)


This piece shall verify the program's arguments. I don't understand why whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.
 
      if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre d'arguments."); raise Exc_Commande;
      elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' | 'C' then
        PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) charactère entre n, c, N et C."); raise Exc_Commande;
      elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, Outside) /= 0 then
 	PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de chiffres !"); raise Exc_Commande;
      end if;

^ permalink raw reply	[relevance 1%]

* alternative elsif branch not tested
@ 2018-02-22 22:54  1% Mehdi Saada
  2018-02-22 23:09  1% ` Mehdi Saada
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-02-22 22:54 UTC (permalink / raw)


This piece shall verify the program's arguments. I don't understand why whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.
Except that, everything worked just fine. Almost at the first attempt !

      if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre d'arguments."); raise Exc_Commande;
      elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' | 'C' then
	 PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) charactère entre n, c, N et C."); raise Exc_Commande;
      elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, Outside) /= 0 then
	 PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de chiffres !"); raise Exc_Commande;
      end if;


^ permalink raw reply	[relevance 1%]

* article on acces types and dynamic serialization in Ada (2003)
@ 2018-02-21 23:57  1% Mehdi Saada
  0 siblings, 0 replies; 200+ results
From: Mehdi Saada @ 2018-02-21 23:57 UTC (permalink / raw)


Hello everyone.
I already mailed you Simon Wright about it, but I've more info and questions, so it put it here. First the context:
I played with streams yesterday to learn more, and stumbled on something not really intuitive, at least. what means exactly Some_access_type'Write(Stream1, Some_Pointer) ?
I could figure out it's implementation defined, so you can't guess.
So that
Some_access_type'Write(stream(Stream_File), Pointer1);
...
Reset(Stream_File, IN_FILE);
Some_access_type'Read(stream(Stream_file), Pointer2);
doesn't work: reaching Pointer2.all raises "erroneous memory access", though Pointer2 isn't null.
Strange, since in my exemple, all happen in the same, hum, "scope of declaration" (apropriate term ?). Any address or whatever information the pointer is made of, should still be valid. Any pool pointed at still exists.
Doesn't feel like a "sane" legal behavior. I also saw a "normal" record object with a pool-specific pointer like this one
type FOO is record
  ...
  BAR: access INTEGER := new INTEGER'(15);
end record;
serializes well, I can read Bar.all. Funny, but where the difference since (according to Ada wikibook) a priori the default 'Write is called for each record component ?

Then I found today that https://infoscience.epfl.ch/record/54724/files/IC_TECH_REPORT_200363.pdf : Automatic Serialization of Dynamic Structures in Ada Technical Report

I was surprised I could read and understand it all with some concentration. And a bit proud, to be honnest ! I would have thought it to be like Chinese at my level.
It was 13 years ago, but I couldn't find a more recent papier on the subject of dynamic serialization, nor has new Dynamic_Stream aspects/attributes been added since then. I didn't read anything either in the stream or access types related sections.

I tried more, but can't write well yet that more complicated exemple:
with Ada.Streams.Stream_IO, Ada.Strings.Unbounded.Text_IO, Ada.Text_IO;
use Ada.Streams.Stream_IO, Ada.Streams, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO;
procedure Main is
   subtype TSF is File_Type;
   FILE : TSF;
   type CHAMPS;
   type ACCESS_CHAMPS is access ALL CHAMPS;
   type CHAMPS (A: ACCESS_CHAMPS) is record
      NOTE : NATURAL range 0 .. 20 := 0;
   end record;
   
   C2, C1 , C3  :  aliased CHAMPS := (A => null, note => 5); 
begin
        
   C1 := (C2'Access, 14);
   C2 := (A => C1'Access, Note => 5 ); 
   Create (FILE, Append_File, Name => "tentative.stream");
   CHAMPS'Write (Stream (FILE), C2);
   Reset (File => FILE,
	  Mode => In_File );
   CHAMPS'Read(Stream(FILE), C3);
   ada.Text_IO.Put_line (INTEGER'Image (C3.A.all.Note));
   CLOSE(FILE);
end;

raises CONSTRAINT_ERROR : main.adb:15 discriminant check failed
I read as I could about access discrimant aliasing and autoreferencing types, but visibly lack practice ;-)  
Could you help me finish that exemple ? I would be delighted to see what happens by myself, since the former exemple (Some_Access'Write and 'Read) proves interesting.

Gosh, the pleasure these things give me...

^ permalink raw reply	[relevance 1%]

* Re: Array of records with default values not propagating to array
  @ 2018-02-04 11:38  1%     ` Bojan Bozovic
  0 siblings, 0 replies; 200+ results
From: Bojan Bozovic @ 2018-02-04 11:38 UTC (permalink / raw)


On Sunday, February 4, 2018 at 11:07:10 AM UTC+1, Niklas Holsti wrote:
> On 18-02-04 06:59 , Bojan Bozovic wrote:
> > On Saturday, February 3, 2018 at 12:06:52 PM UTC+1, Bojan Bozovic wrote:
> >> When I defined a record, and set a default value for some of its
> >> components, these don't propagate when I make array of these
> >> records. Here is code that can be compiled, but I wonder do I
> >> need to explicitly assign value for 'others' in 'Initialize'
> >> procedure.
> 
> This is just a rule in Ada: in a record aggregate, one has to specify 
> values for all the "needed components", whether or not the record type 
> declaration supplies default values for some components.
> 
> This is different from a subprogram call, in which one can omit the 
> parameter associations for parameters that have a default value.
> 
> The default values of record components are used in two cases: when one 
> creates an object of the type, without giving an initial value, such as 
> (in your code):
> 
>        Temporary_Data : Card_Info;
> 
> Here, the default values in the Card_Info declaration come into play, 
> and define the initial values of those components of Temporary_Data.
> 
> Here it means that Temporary_Data.Trump is False, and Name and 
> Divinatory_Meaning are null unbounded strings. The component 
> Temporary_Data.Trump_Value has an undefined value, as it is not given 
> any default value in the declaration of Card_Info.
> 
> However, in your code, defining explicit default values of 
> Null_Unbounded_String for the components Name and Divinatory_Meaning is 
> unnecessary, because every object of type Unbounded_String is 
> initialised, by default, to Null_Unbounded_String.
> 
> The second case where default values of record components are used is in 
> a record aggreggate where a component association says " ... => <>". 
> Here, the "<>" means "use the default value, if there is one".
> 
> So, in your code, if a record aggregate for a Card_Info record says "... 
> => <>" for the components Name and Divinatory_Meaning, it means that 
> these components will be given the value Null_Unbounded_String.
> 
> >> When I omit "others =>" in Initialize, I get compilation errors
> >> at these lines both on FSF compiler and AdaCore GPL compiler on
> >> Windows. Is this intended behavior or I am missing something?
> 
> It is intended behaviour. The relevant Reference Manual rule is 
> http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-3-1.html#p16 .
> 
> > The compiler does compile assignment of others => <> to uninitialized
> > record components as Mr. Simon Wright noticed above,
> 
> Why do you believe that the components (Name and Divinatory_Meaning) are 
> uninitialised? In my tests of the code, they are initialised, as 
> expected, to Null_Unbounded_String.
> 
> > I have reproduced the bug both with GNAT 2017 GPL and FSF GNAT on
> > Cygwin (6.4.0).
> 
> So far, I don't think there is any bug.
> 
> -- 
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
>        .      @       .

When in record declaration making components uninitialized like:

Name : Ada.Strings.Unbounded.Unbounded_String;

I had made a mistake to believe these had no proper initialization and shouldn't have been assigned by others => <> in assignment during Initialize, but explicitly, as Simon Wright originally said. I don't know enough about the language itself to discern if something isn't implemented correctly by the compiler, but it is, as Simon Wright rectified his stance on this, so I just sent some spam to AdaCore about that, but I don't think it matters. ;)


^ permalink raw reply	[relevance 1%]

* Re: Array of records with default values not propagating to array
  2018-02-04  9:21  0%     ` Niklas Holsti
@ 2018-02-04  9:32  0%       ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2018-02-04  9:32 UTC (permalink / raw)


Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> On 18-02-03 17:26 , Simon Wright wrote:
>
>> I find that
>>
>>    type Card_Info (Trump : Boolean := False) is record
>>       Name : Ada.Strings.Unbounded.Unbounded_String;
>>       Divinatory_Meaning : Ada.Strings.Unbounded.Unbounded_String;
>>       ...
>>
>>          TDeck (Index) :=
>>            (Trump       => True,
>>             Trump_Value => Index_1,
>>             others      => <>);
>>          ...
>>
>>             TDeck (Index) :=
>>               (Trump      => False,
>>                Card_Value => Card_Index,
>>                Suit_Value => Suit_Index,
>>                others     => <>);
>>
>> compiles OK and seems to run perfectly well. Presumably this is OK
>> because the initial value for an otherwise-uninitialized unbounded
>> string is the empty string. Or maybe it's GNAT being over-helpful, since
>> it seems not to obey ARM 4.3.1(17.1)[1].
>>
>> [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-3-1.html#p17.1
>
> I don't think that ARM paragraph applies to the "others" in this
> code. The paragraph says:
>
> "A record_component_association for a discriminant without a
> default_expression shall have an expression rather than <>"
>
> but the components covered by the "others" in this code are not
> discriminants. The discriminant is the Trump component, and the
> associations for Trump have an expression (True or False), not <>.

Oh, yes.

I should have looked a bit further down: (19.1) says

   "... For a record_component_association with <>, if the
   component_declaration has a default_expression, that
   default_expression defines the value for the associated component(s);
   otherwise, the associated component(s) are initialized by default as
   for a stand-alone object of the component subtype (see 3.3.1)."

which is exactly what OP needs.


^ permalink raw reply	[relevance 0%]

* Re: Array of records with default values not propagating to array
  2018-02-03 15:26  2%   ` Simon Wright
@ 2018-02-04  9:21  0%     ` Niklas Holsti
  2018-02-04  9:32  0%       ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Niklas Holsti @ 2018-02-04  9:21 UTC (permalink / raw)


On 18-02-03 17:26 , Simon Wright wrote:

> I find that
>
>    type Card_Info (Trump : Boolean := False) is record
>       Name : Ada.Strings.Unbounded.Unbounded_String;
>       Divinatory_Meaning : Ada.Strings.Unbounded.Unbounded_String;
>       ...
>
>          TDeck (Index) :=
>            (Trump       => True,
>             Trump_Value => Index_1,
>             others      => <>);
>          ...
>
>             TDeck (Index) :=
>               (Trump      => False,
>                Card_Value => Card_Index,
>                Suit_Value => Suit_Index,
>                others     => <>);
>
> compiles OK and seems to run perfectly well. Presumably this is OK
> because the initial value for an otherwise-uninitialized unbounded
> string is the empty string. Or maybe it's GNAT being over-helpful, since
> it seems not to obey ARM 4.3.1(17.1)[1].
>
> [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-3-1.html#p17.1

I don't think that ARM paragraph applies to the "others" in this code. 
The paragraph says:

"A record_component_association for a discriminant without a 
default_expression shall have an expression rather than <>"

but the components covered by the "others" in this code are not 
discriminants. The discriminant is the Trump component, and the 
associations for Trump have an expression (True or False), not <>.

(Moreover, the Trump component has a default expression (False), which 
makes ARM 4.3.1(17.1) inapplicable even to "Trump => <>".)

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


^ permalink raw reply	[relevance 0%]

* Re: Array of records with default values not propagating to array
  2018-02-03 11:06  2% Array of records with default values not propagating to array Bojan Bozovic
  2018-02-03 14:16  2% ` Jere
@ 2018-02-04  4:59  0% ` Bojan Bozovic
    1 sibling, 1 reply; 200+ results
From: Bojan Bozovic @ 2018-02-04  4:59 UTC (permalink / raw)


On Saturday, February 3, 2018 at 12:06:52 PM UTC+1, Bojan Bozovic wrote:
> When I defined a record, and set a default value for some of its components, these don't propagate when I make array of these records. Here is code that can be compiled, but I wonder do I need to explicitly assign value for 'others' in 'Initialize' procedure. This has nothing to do with Ada random number generation, I might have as well used Ada.Numerics.Float_Random, or the reusable code that was posted in another thread, with the same result, so I will post in this separate thread. When I omit "others =>" in Initialize, I get compilation errors at these lines both on FSF compiler and AdaCore GPL compiler on Windows. Is this intended behavior or I am missing something?
> 
> with Ada.Numerics.Discrete_Random;
> with Ada.Text_IO;
> with Ada.Text_IO.Unbounded_IO;
> with Ada.Strings;
> with Ada.Strings.Unbounded;
> 
> procedure Tarot1 is
> 
> Maximum_Deck_Length: constant integer := 78;
> subtype Card_Position is Positive range 1..Maximum_Deck_Length;
> type Card_Suits is (Cups,Pentacles,Swords,Wands);
> type Trump_Values is new Natural range 0..21;
> type Card_Values is (Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Page,Knight,Queen,King,Ace);
> type Card_Info (Trump: Boolean := False) is record
> -- we will skip giving name and divinatory meaning to cards - its just ordinary assignment but for each card separately;
> -- PROBLEM: Assignment here does nothing, so I have to assign these values in Initialize procedure below as well
> 
> Name : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;
> Divinatory_Meaning: Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;
> 
> case Trump is 
> 	when True => Trump_Value:Trump_Values;
> 	when False =>  Card_Value:Card_Values;
> 					Suit_Value:Card_Suits;
> end case;
> end record;
> type Deck is array (Card_Position) of Card_Info;
> package Card_Position_Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Card_Position);
> 
> procedure Initialize ( TDeck : in out Deck) is
> 	Index: Card_Position := 1;
> 	begin
> 		-- first lay 22 trump cards in a deck
> 			for Index_1 in Trump_Values loop
> 			TDeck (Index) := (Trump => True, Trump_Value => Index_1, others => Ada.Strings.Unbounded.Null_Unbounded_String);
> 			Index := Index + 1;
> 			end loop;
> 		-- now lay 4 suits of 14 cards each;
> 		for Suit_Index in Card_Suits loop
> 			for Card_Index in Card_Values loop
> 			TDeck (Index) := (Trump => False, Card_Value => Card_Index, Suit_Value => Suit_Index, others => Ada.Strings.Unbounded.Null_Unbounded_String);
> 			exit when Index=Maximum_Deck_Length; -- preventing CONSTRAINT_ERROR;
> 			Index:=Index+1;
> 			end loop;
> 			end loop;
> end Initialize;
> 
>    procedure Shuffle (TDeck : in out Deck) is
>       Position_Gen   : Card_Position_Random.Generator;
>       Temporary_Data : Card_Info;
>       Index_Random   : Card_Position;
>    begin
>       Card_Position_Random.Reset (Gen => Position_Gen);
>       for Index in Card_Position loop
>          Index_Random         := Card_Position_Random.Random (Gen => Position_Gen);
>          Temporary_Data       := TDeck (Index);
>          TDeck (Index)        := TDeck (Index_Random);
>          TDeck (Index_Random) := Temporary_Data;
>       end loop;
>    end Shuffle;
>    Tarot_Deck : Deck;
>    begin
>    Initialize(Tarot_Deck);
>    Shuffle(Tarot_Deck);
>    for Index in Card_Position loop -- just print the deck as shuffled
>    if Tarot_Deck(Index).Trump then
> 	Ada.Text_IO.Put_Line("Major Arcana/Trump: "&Trump_Values'Image(Tarot_Deck(Index).Trump_Value));
> else
> 	Ada.Text_IO.Put_Line("Minor Arcana: "&Card_Values'Image(Tarot_Deck(Index).Card_Value)&" of "&Card_Suits'Image(Tarot_Deck(Index).Suit_Value));
> 	end if;
> 	end loop;
>    end Tarot1;
> 
> Thanks for help.

The compiler does compile assignment of others => <> to uninitialized record components as Mr. Simon Wright noticed above, I have reproduced the bug both with GNAT 2017 GPL and FSF GNAT on Cygwin (6.4.0), problem is I don't have GNAT Pro subscription for access to AdaCore GNAT tracker, and I can't open an account on GCC Bugzilla either, as my mail to administration is rejected and direct account creation is disabled. We can only hope that powers that be take notice of this. Thanks for the suggestions by the way.


^ permalink raw reply	[relevance 0%]

* Re: Array of records with default values not propagating to array
  2018-02-03 14:16  2% ` Jere
@ 2018-02-03 15:26  2%   ` Simon Wright
  2018-02-04  9:21  0%     ` Niklas Holsti
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2018-02-03 15:26 UTC (permalink / raw)


Jere <jhb.chat@gmail.com> writes:

> The big issue I see is not incrementing Index in the first loop.  As
> it stands, you simply keep reassigning trumps to the same card over
> and over again.

When I copied OP's code it _did_ increment Index in the first loop. ??

I find that

   type Card_Info (Trump : Boolean := False) is record
      Name : Ada.Strings.Unbounded.Unbounded_String;
      Divinatory_Meaning : Ada.Strings.Unbounded.Unbounded_String;
      ...

         TDeck (Index) :=
           (Trump       => True,
            Trump_Value => Index_1,
            others      => <>);
         ...

            TDeck (Index) :=
              (Trump      => False,
               Card_Value => Card_Index,
               Suit_Value => Suit_Index,
               others     => <>);

compiles OK and seems to run perfectly well. Presumably this is OK
because the initial value for an otherwise-uninitialized unbounded
string is the empty string. Or maybe it's GNAT being over-helpful, since
it seems not to obey ARM 4.3.1(17.1)[1].

[1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-3-1.html#p17.1


^ permalink raw reply	[relevance 2%]

* Re: Array of records with default values not propagating to array
  2018-02-03 11:06  2% Array of records with default values not propagating to array Bojan Bozovic
@ 2018-02-03 14:16  2% ` Jere
  2018-02-03 15:26  2%   ` Simon Wright
  2018-02-04  4:59  0% ` Bojan Bozovic
  1 sibling, 1 reply; 200+ results
From: Jere @ 2018-02-03 14:16 UTC (permalink / raw)


On Saturday, February 3, 2018 at 6:06:52 AM UTC-5, Bojan Bozovic wrote:
> When I defined a record, and set a default value for some of its components, these don't propagate when I make array of these records. Here is code that can be compiled, but I wonder do I need to explicitly assign value for 'others' in 'Initialize' procedure. This has nothing to do with Ada random number generation, I might have as well used Ada.Numerics.Float_Random, or the reusable code that was posted in another thread, with the same result, so I will post in this separate thread. When I omit "others =>" in Initialize, I get compilation errors at these lines both on FSF compiler and AdaCore GPL compiler on Windows. Is this intended behavior or I am missing something?
> 
> with Ada.Numerics.Discrete_Random;
> with Ada.Text_IO;
> with Ada.Text_IO.Unbounded_IO;
> with Ada.Strings;
> with Ada.Strings.Unbounded;
> 
> procedure Tarot1 is
> 
> Maximum_Deck_Length: constant integer := 78;
> subtype Card_Position is Positive range 1..Maximum_Deck_Length;
> type Card_Suits is (Cups,Pentacles,Swords,Wands);
> type Trump_Values is new Natural range 0..21;
> type Card_Values is (Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Page,Knight,Queen,King,Ace);
> type Card_Info (Trump: Boolean := False) is record
> -- we will skip giving name and divinatory meaning to cards - its just ordinary assignment but for each card separately;
> -- PROBLEM: Assignment here does nothing, so I have to assign these values in Initialize procedure below as well
> 
> Name : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;
> Divinatory_Meaning: Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;
> 
> case Trump is 
> 	when True => Trump_Value:Trump_Values;
> 	when False =>  Card_Value:Card_Values;
> 					Suit_Value:Card_Suits;
> end case;
> end record;
> type Deck is array (Card_Position) of Card_Info;
> package Card_Position_Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Card_Position);
> 
> procedure Initialize ( TDeck : in out Deck) is
> 	Index: Card_Position := 1;
> 	begin
> 		-- first lay 22 trump cards in a deck
> 			for Index_1 in Trump_Values loop
> 			TDeck (Index) := (Trump => True, Trump_Value => Index_1, others => Ada.Strings.Unbounded.Null_Unbounded_String);
> 			Index := Index + 1;
> 			end loop;
> 		-- now lay 4 suits of 14 cards each;
> 		for Suit_Index in Card_Suits loop
> 			for Card_Index in Card_Values loop
> 			TDeck (Index) := (Trump => False, Card_Value => Card_Index, Suit_Value => Suit_Index, others => Ada.Strings.Unbounded.Null_Unbounded_String);
> 			exit when Index=Maximum_Deck_Length; -- preventing CONSTRAINT_ERROR;
> 			Index:=Index+1;
> 			end loop;
> 			end loop;
> end Initialize;
> 
>    procedure Shuffle (TDeck : in out Deck) is
>       Position_Gen   : Card_Position_Random.Generator;
>       Temporary_Data : Card_Info;
>       Index_Random   : Card_Position;
>    begin
>       Card_Position_Random.Reset (Gen => Position_Gen);
>       for Index in Card_Position loop
>          Index_Random         := Card_Position_Random.Random (Gen => Position_Gen);
>          Temporary_Data       := TDeck (Index);
>          TDeck (Index)        := TDeck (Index_Random);
>          TDeck (Index_Random) := Temporary_Data;
>       end loop;
>    end Shuffle;
>    Tarot_Deck : Deck;
>    begin
>    Initialize(Tarot_Deck);
>    Shuffle(Tarot_Deck);
>    for Index in Card_Position loop -- just print the deck as shuffled
>    if Tarot_Deck(Index).Trump then
> 	Ada.Text_IO.Put_Line("Major Arcana/Trump: "&Trump_Values'Image(Tarot_Deck(Index).Trump_Value));
> else
> 	Ada.Text_IO.Put_Line("Minor Arcana: "&Card_Values'Image(Tarot_Deck(Index).Card_Value)&" of "&Card_Suits'Image(Tarot_Deck(Index).Suit_Value));
> 	end if;
> 	end loop;
>    end Tarot1;
> 
> Thanks for help.

The big issue I see is not incrementing Index in the first loop.  As it
stands, you simply keep reassigning trumps to the same card over and over
again.  Since the type is uninitialized and the next for loop cannot fill
the deck, you get a constraint error later on in the print statement when
trying to print a minor arcana.  As a note, defaulting the variant portion
of the record definition did prevent the constraint error, though obviously
the results were wrong because Initialize did not initialize the whole deck.

Try:

with Ada.Numerics.Discrete_Random;
with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings;
with Ada.Strings.Unbounded; 

procedure Tarot1 is
   
   Maximum_Deck_Length: constant integer := 78;
   subtype Card_Position is Positive range 1..Maximum_Deck_Length;
   type Card_Suits is (Cups,Pentacles,Swords,Wands);
   type Trump_Values is new Natural range 0..21;
   type Card_Values is (Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Page,Knight,Queen,King,Ace);
   type Card_Info (Trump: Boolean := False) is record
      -- we will skip giving name and divinatory meaning to cards - its just ordinary assignment but for each card separately;
      -- PROBLEM: Assignment here does nothing, so I have to assign these values in Initialize procedure below as well

      Name : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;
      Divinatory_Meaning: Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;

      case Trump is
         when True =>
            Trump_Value:Trump_Values;
         when False =>
            Card_Value:Card_Values;
            Suit_Value:Card_Suits;
      end case;
   end record;
   type Deck is array (Card_Position) of Card_Info;
   package Card_Position_Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Card_Position);

   procedure Initialize ( TDeck : in out Deck) is
      Index: Card_Position := 1;
   begin
      -- first lay 22 trump cards in a deck
      for Index_1 in Trump_Values loop
         TDeck (Index) := (Trump => True, Trump_Value => Index_1, others => <>);
         Index := Index + 1;  -- Jere:  I added this
      end loop;
      
      -- now lay 4 suits of 14 cards each;
      for Suit_Index in Card_Suits loop
         for Card_Index in Card_Values loop
            TDeck (Index) := (Trump => False, Card_Value => Card_Index, Suit_Value => Suit_Index, others => <>);
            exit when Index=Maximum_Deck_Length; -- preventing CONSTRAINT_ERROR;
            Index:=Index+1;
         end loop;
      end loop;
   end Initialize;

   procedure Shuffle (TDeck : in out Deck) is
      Position_Gen   : Card_Position_Random.Generator;
      Temporary_Data : Card_Info;
      Index_Random   : Card_Position;
   begin
      Card_Position_Random.Reset (Gen => Position_Gen);
      for Index in Card_Position loop
         Index_Random         := Card_Position_Random.Random (Gen => Position_Gen);
         Temporary_Data       := TDeck (Index);
         TDeck (Index)        := TDeck (Index_Random);
         TDeck (Index_Random) := Temporary_Data;
      end loop;
   end Shuffle;
   Tarot_Deck : Deck; 
   
begin
   
   Initialize(Tarot_Deck);
   Shuffle(Tarot_Deck);
   for Index in Card_Position loop -- just print the deck as shuffled
      Ada.Text_IO.put("Index = " & Card_Position'Image(Index) & " => ");
      if Tarot_Deck(Index).Trump then
         Ada.Text_IO.Put_Line("Major Arcana/Trump: "&Trump_Values'Image(Tarot_Deck(Index).Trump_Value));
      else
         Ada.Text_IO.Put_Line("Minor Arcana: "&Card_Values'Image(Tarot_Deck(Index).Card_Value)&" of "&Card_Suits'Image(Tarot_Deck(Index).Suit_Value));
      end if;
   end loop;
   
end Tarot1;

^ permalink raw reply	[relevance 2%]

* Array of records with default values not propagating to array
@ 2018-02-03 11:06  2% Bojan Bozovic
  2018-02-03 14:16  2% ` Jere
  2018-02-04  4:59  0% ` Bojan Bozovic
  0 siblings, 2 replies; 200+ results
From: Bojan Bozovic @ 2018-02-03 11:06 UTC (permalink / raw)


When I defined a record, and set a default value for some of its components, these don't propagate when I make array of these records. Here is code that can be compiled, but I wonder do I need to explicitly assign value for 'others' in 'Initialize' procedure. This has nothing to do with Ada random number generation, I might have as well used Ada.Numerics.Float_Random, or the reusable code that was posted in another thread, with the same result, so I will post in this separate thread. When I omit "others =>" in Initialize, I get compilation errors at these lines both on FSF compiler and AdaCore GPL compiler on Windows. Is this intended behavior or I am missing something?

with Ada.Numerics.Discrete_Random;
with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings;
with Ada.Strings.Unbounded;

procedure Tarot1 is

Maximum_Deck_Length: constant integer := 78;
subtype Card_Position is Positive range 1..Maximum_Deck_Length;
type Card_Suits is (Cups,Pentacles,Swords,Wands);
type Trump_Values is new Natural range 0..21;
type Card_Values is (Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Page,Knight,Queen,King,Ace);
type Card_Info (Trump: Boolean := False) is record
-- we will skip giving name and divinatory meaning to cards - its just ordinary assignment but for each card separately;
-- PROBLEM: Assignment here does nothing, so I have to assign these values in Initialize procedure below as well

Name : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;
Divinatory_Meaning: Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;

case Trump is 
	when True => Trump_Value:Trump_Values;
	when False =>  Card_Value:Card_Values;
					Suit_Value:Card_Suits;
end case;
end record;
type Deck is array (Card_Position) of Card_Info;
package Card_Position_Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Card_Position);

procedure Initialize ( TDeck : in out Deck) is
	Index: Card_Position := 1;
	begin
		-- first lay 22 trump cards in a deck
			for Index_1 in Trump_Values loop
			TDeck (Index) := (Trump => True, Trump_Value => Index_1, others => Ada.Strings.Unbounded.Null_Unbounded_String);
			Index := Index + 1;
			end loop;
		-- now lay 4 suits of 14 cards each;
		for Suit_Index in Card_Suits loop
			for Card_Index in Card_Values loop
			TDeck (Index) := (Trump => False, Card_Value => Card_Index, Suit_Value => Suit_Index, others => Ada.Strings.Unbounded.Null_Unbounded_String);
			exit when Index=Maximum_Deck_Length; -- preventing CONSTRAINT_ERROR;
			Index:=Index+1;
			end loop;
			end loop;
end Initialize;

   procedure Shuffle (TDeck : in out Deck) is
      Position_Gen   : Card_Position_Random.Generator;
      Temporary_Data : Card_Info;
      Index_Random   : Card_Position;
   begin
      Card_Position_Random.Reset (Gen => Position_Gen);
      for Index in Card_Position loop
         Index_Random         := Card_Position_Random.Random (Gen => Position_Gen);
         Temporary_Data       := TDeck (Index);
         TDeck (Index)        := TDeck (Index_Random);
         TDeck (Index_Random) := Temporary_Data;
      end loop;
   end Shuffle;
   Tarot_Deck : Deck;
   begin
   Initialize(Tarot_Deck);
   Shuffle(Tarot_Deck);
   for Index in Card_Position loop -- just print the deck as shuffled
   if Tarot_Deck(Index).Trump then
	Ada.Text_IO.Put_Line("Major Arcana/Trump: "&Trump_Values'Image(Tarot_Deck(Index).Trump_Value));
else
	Ada.Text_IO.Put_Line("Minor Arcana: "&Card_Values'Image(Tarot_Deck(Index).Card_Value)&" of "&Card_Suits'Image(Tarot_Deck(Index).Suit_Value));
	end if;
	end loop;
   end Tarot1;

Thanks for help.



^ permalink raw reply	[relevance 2%]

* Re: Reference counter in smart pointers are not updated properly when used by multiple tasks
  @ 2018-02-01 19:04  2% ` Robert A Duff
  0 siblings, 0 replies; 200+ results
From: Robert A Duff @ 2018-02-01 19:04 UTC (permalink / raw)


onox <denkpadje@gmail.com> writes:

>... so I am using atomics (GCC's
> __sync_sub_and_fetch_4) ...

There is a version of Ada.Strings.Unbounded that
uses atomics for reference counting.  You could look
at that as an example.  Look at a-strunb.ads.
If it has this comment near the top:

--  This package provides an implementation of Ada.Strings.Unbounded that uses
--  reference counts to implement copy on modification (rather than copy on
--  assignment). This is significantly more efficient on many targets.

--  This version is supported on:
--    - all Alpha platforms
--    - all ia64 platforms
--    - all PowerPC platforms
--    - all SPARC V9 platforms
--    - all x86 platforms
--    - all x86_64 platforms

then that's the right version to look at.

- Bob


^ permalink raw reply	[relevance 2%]

* Re: Iterable container as generic parameter
  @ 2018-01-28 18:08  2%         ` Lionel Draghi
  0 siblings, 0 replies; 200+ results
From: Lionel Draghi @ 2018-01-28 18:08 UTC (permalink / raw)


Le 26/01/2018 à 10:09, emmanuel... a écrit :
>> But I probably would just use your original spec and add the container type
>> and iterator function, something like:
>>
>> generic
>>     type Cursor is (<>);
>>     with function Image (C : Cursor) return String;
>>     type Container (<>) is private;
>>     with package Iterator_Interfaces is
>>       new Ada.Iterator_Interfaces (Cursor, others => <>);
>>     with function Iterator (C : Container) return
>> Iterator_Interfaces.Forward_Iterator'Class;
>> function List_Image return String;
>>
> 
> I think that's a good starting point.

Ok, I have something that works (https://github.com/LionelDraghi/List_Image).

Instantiating this is not as simple as I hoped, but not that much a nightmare :

   with List_Image;

   with Ada.Containers.Indefinite_Hashed_Sets;
   with Ada.Strings.Hash_Case_Insensitive;
   ...
      -- Example here with a set of identifier
      package Id_Sets is new Ada.Containers.Indefinite_Hashed_Sets
        (String, Ada.Strings.Hash_Case_Insensitive, "=");
      Id_Set : Id_Sets.Set;

      use Id_Sets;
      function Id_Set_Image is new List_Image.Image
           (Cursor      => Cursor,
            Image       => Element,
            Iterator_If => Set_Iterator_Interfaces,
            Container   => Set,
            Iterator    => Iterate,
            Style       => List_Image.Bracketed_List_Style);
      ...
      Id_Set.Insert ("Salt");
      Id_Set.Insert ("Pepper");
      Put_Line (Id_Set_Image (Id_Set));


It becomes slightly more complex for Containers that don't directly export an Iterate function returning Forward_Iterator'class (but Reversible_Iterator'class).
You need then to provide a simple function :

   function Iterate (L : List) return
     List_Iterator_Interfaces.Forward_Iterator'Class is 
       (Iterate (L));

The signature Style package is generally simple, and may be application wide, shared among all List_Image instantiation.

Any idea to simplify is welcome.

-- 
-- Lionel


^ permalink raw reply	[relevance 2%]

* Re: Iterable container as generic parameter
  @ 2018-01-25 14:58  2%   ` Lionel Draghi
    0 siblings, 1 reply; 200+ results
From: Lionel Draghi @ 2018-01-25 14:58 UTC (permalink / raw)


> As to the question you didn't ask, you clearly need the container type 
> somewhere in your interface, so you can pass container objects. (Or, I 
> suppose, you could reference the type used in the instance of the 
> Iterator_Interfaces.) Otherwise, you just have methods but no data. And 
> there isn't anything interesting that you can do with just methods!
> 
>                                     Randy.

Thanks Randy for the answer, this is actually my question.
And what you put into parenthesis was what I was trying to do.

Here is my point : 
If I limit the procedure scope to a specific container, the generic is simple : 

with Ada.Containers.Doubly_Linked_Lists;
generic
   type Element_Type is (<>);
   with function Image (Element : Element_Type) return String is <>;
   with package Lists is new Ada.Containers.Doubly_Linked_Lists (Element_Type);
function List_Image_1 (List : Lists.List) return string;

But if want something that could be used with both Lists and Maps, I have to provide much more parameters : 

with Ada.Containers;
generic
   type Element_Type (<>) is Private;
   with function Image (Element : Element_Type) return String is <>;

   type Cursor is private; 
   with function First return Cursor is <>;
   with function Next (Position : Cursor) return Cursor is <>;
   with function Length return Ada.Containers.Count_Type is <>;

   with function Element (Position : Cursor) return Element_Type is <>;

function List_Image_2 return String;

And that sounds a bit to complex to me, because what I am doing is just creating my own iterator. 
This is why I was trying to simplify the generic formal part by using the Iterator_Interfaces.

I have the feeling that I’m missing something.

Lionel

PS : here is my test code.

with Ada.Containers.Doubly_Linked_Lists;

generic
   type Element_Type is (<>);
   with function Image (Element : Element_Type) return String is <>;
   with package Lists is new Ada.Containers.Doubly_Linked_Lists (Element_Type);

function List_Image_1 (List : Lists.List) return string;

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; 

function List_Image_1 (List : Lists.List) return String is
   Tmp : Unbounded_String;
begin
   for E of List loop
      Tmp := Tmp & " " & Image (E);
   end loop;
   return To_String (Tmp);
end List_Image_1;

with Ada.Containers;

generic
   type Element_Type (<>) is Private;
   with function Image (Element : Element_Type) return String is <>;

   type Cursor is private; 
   with function First return Cursor is <>;
   with function Next (Position : Cursor) return Cursor is <>;
   with function Length return Ada.Containers.Count_Type is <>;
   
   with function Element (Position : Cursor) return Element_Type is <>;
   
function List_Image_2 return String;

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

function List_Image_2 return String is
   Tmp : Unbounded_String;
   C   : Cursor;
begin
   -- a bit more sophisticated format
   case Length is 
      when 0 => return "";
      when 1 => return "[" & Image (Element (First)) & "]";
      when others => 
         C := First;
         Tmp := To_Unbounded_String ("[") & Image (Element (C));
         for I in 2 .. Length loop
            C := Next (C);
            Tmp := Tmp  & ", " & Image (Element (C));
         end loop;
         Tmp := Tmp & "]";
   end case;
   return To_String (Tmp);
end List_Image_2;

with List_Image_1;
with List_Image_2;

with Ada.Containers.Doubly_Linked_Lists;
with Ada.Containers.Indefinite_Hashed_Sets;
with Ada.Strings.Hash_Case_Insensitive;

with Ada.Text_Io;

procedure Test_List_Image is
   
   -- container for test purposes
   package Integer_Lists is new Ada.Containers.Doubly_Linked_Lists (Integer);
   List : Integer_Lists.List;

   Function Integer_List_Image_1 is new List_Image_1 
     (Integer, 
      Integer'Image, 
      Integer_Lists);

   function Integer_List_Image_2 is new List_Image_2 
     (Integer, 
      Integer'Image, 
      Integer_Lists.Cursor,
      List.First,
      Integer_Lists.Next,
      List.Length,
      Integer_Lists.Element);

   -- another container 
   function Image (S : String) return String is (String (S));
   
   package Id_Sets is new Ada.Containers.Indefinite_Hashed_Sets 
     (String, Ada.Strings.Hash_Case_Insensitive, "=");
   Set : Id_Sets.Set;
   use Id_Sets; 
   
   function Id_Set_Image_2 is new List_Image_2 
     (String, 
      Image, 
      Cursor  => Id_Sets.Cursor,
      First   => Set.First,
      Next    => Id_Sets.Next,
      Length  => Set.Length,
      Element => Id_Sets.Element);

begin
   -- ----------------------------------------------------------------------
   Ada.Text_Io.Put_Line ("Test generic 1 on a list :");
   Ada.Text_Io.Put_Line (Integer_List_Image_1 (List));

   List.Append (1);
   Ada.Text_Io.Put_Line (Integer_List_Image_1 (List));

   List.Append (2);
   Ada.Text_Io.Put_Line (Integer_List_Image_1 (List));

   List.Append (3);
   Ada.Text_Io.Put_Line (Integer_List_Image_1 (List));
   Ada.Text_Io.New_Line;
   
   -- ----------------------------------------------------------------------
   Ada.Text_Io.Put_Line ("Test generic 2 on a list :");

   List.Clear;
   Ada.Text_Io.Put_Line (Integer_List_Image_2);

   List.Append (1);
   Ada.Text_Io.Put_Line (Integer_List_Image_2);

   List.Append (2);
   Ada.Text_Io.Put_Line (Integer_List_Image_2);

   List.Append (3);
   Ada.Text_Io.Put_Line (Integer_List_Image_2);
   Ada.Text_Io.New_Line;

   -- ----------------------------------------------------------------------
   Ada.Text_Io.Put_Line ("Test generic 2 on a set :");
   
   Ada.Text_Io.Put_Line (Id_Set_Image_2);
   Set.Insert ("Hyperion");
   
   Ada.Text_Io.Put_Line (Id_Set_Image_2);
   Set.Insert ("Endymion");
   
   Ada.Text_Io.Put_Line (Id_Set_Image_2);
   Set.Insert ("TechnoCore");

   Ada.Text_Io.Put_Line (Id_Set_Image_2);

end Test_List_Image;


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-20  9:47  1%                         ` Dmitry A. Kazakov
@ 2018-01-23  0:44  1%                           ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2018-01-23  0:44 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:p3v378$1mqo$1@gioia.aioe.org...
> On 2018-01-20 01:42, Randy Brukardt wrote:
...
>> A type parameter clearly would have to pass the subtype information as 
>> well,
>
> Yes, like it does with array bounds, *if* it were a subprogram proper. 
> This is irrelevant because it is not a subprogram, it only has a syntax of 
> a subprogram call. But for the compiler it is a special case exactly like 
> it is when the attribute syntax is used, or any other syntax. The 
> detection does not require special syntax, that is the point. Once the 
> compiler detects the case, the magic starts to work.

Actually, a "special case" that uses typical syntax is not special at all, 
as a compiler has to start with recognizing and interpreting the normal 
syntax. In order to do that for Ada, one would have to have meta-types in 
order that the techniques would work with the resolution rules. It could be 
similar to the rules for universal_integer (needed to allow compile-time 
type-less expressions), but there would have to be something.

Yes, of course such special cases are not a problem for code 
generation/execution -- indeed, a "subprogram call" is just a mess of 
special cases to the point that there hardly is a "normal" case. (Remember 
that operators are "subprogram calls" in Ada, so many programs have more 
special cases than they do usual calls.)

...
>> (And I
>> don't see why you don't think it is related, either. One has to have some
>> mechanism for getting this information, and if you eliminate the special
>> mechanism for that, some replacement is needed. In the proposed language,
>> only a subprogram call is available, unless some other special syntax is
>> invented, which is just kicking the can.)
>
> It is the same mechanism used to pass/eliminate array bounds.

??? For Janus/Ada, at least, the array bounds ARE the object; the compiler 
only pays attention to the array data when it is directly accessed. (There 
is a pointer to the data stored with the bounds.) There is no separate 
"array bounds" mechanism; it is all tied to the subtype conversion 
mechanism.

One would need a separate mechanism to pass bounds by themselves -- not 
particular hard to do, but it would need a data type to represent "array 
bounds without any data".

> It could be generalized for all types including non-tagged classes. The 
> type tag of a non-tagged type is a [sub]type constraint to be passed or 
> not. The same case is represented by dimensioned values. The dimension is 
> a constraint, again passed or not down to the subprogram, kept or not in 
> an instance.
>
> I think it is possible to design common rules for all this and make the 
> language quite simple.

As before, I don't doubt this. I do doubt that it could be done with an 
acceptable level of compatibility. The additional overloading of subtypes 
needed would certainly cause ambiguities and care would have to be taken to 
avoid beaujolias effects.

If one was abandoning compatibility here altogether, then of course you are 
right -- and objects/exceptions should be overloadable to greatly reduce the 
visibility issues that come from use clauses -- and probably a dozen other 
minor fixes (like redoing renames so that static matching is required rather 
than ignoring the subtypes) should be done too. But that's not very likely 
to happen.

                                 Randy.





^ permalink raw reply	[relevance 1%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 14:17  2%           ` Mehdi Saada
  2018-01-18 14:56  2%             ` J-P. Rosen
  2018-01-18 16:48  2%             ` AdaMagica
@ 2018-01-21 23:27  1%             ` G.B.
  2 siblings, 0 replies; 200+ results
From: G.B. @ 2018-01-21 23:27 UTC (permalink / raw)


On 18.01.18 15:17, Mehdi Saada wrote:
> Since universal_integer is meant to be compatible with everything, and since Ada83 is long gone,
> could "function Length return Integer renames Object_Array'Length" be accepted now ? I don't think it could break any existing code to accept something that wasn't.
> 

There is more to 'Image, which is a type attribute like 'Size.
Handling types is the realm of compilers.

Consider 'Value, which is paired with 'Image. Suppose there is
an enumeration subtype like that of

    type T is ('$', '¥', '£');

We now have

    X = T'Value (T'Image (X))

and, usually,

    S = T'Image (T'Value (S))


However, given the history of String design in programming
languages, things have become tricky.

Not because of a lack of symmetry between 'Image and 'Value
as written above.
Rather, I think, because of that tendency in language design
which bows before elementary school training. Hence,
Ada has removed symmetry: for example, in place of making
"+" a required part of numeric literals such as are input
to 'Image, it can be omitted. So, these values are now all
equal in Ada:

  Positive'Value ("42")
  Positive'Value (" 42")
  Positive'Value ("+42")
  Positive'Value ("   42  ")
  Positive'Value ("+42        ")

Very flexible and convenient, at first sight, I think. And done
for good reasons, at the time, perhaps: because, for output,
everyone would use an instance of a package from Text_IO,
and not 'Image. Right? No problem could have been anticipated.

This design decision has led to an endless discussion about
leading spaces in the result of 'Image for non-negatives.
At the root, elementary school habits in engineering make
programmers proudly dismiss the idea of writing numbers
symmetrically, with signs for both negatives and positives,
and maybe some technical prefix like " " attached to (non-FPT) 0.

OTOH, if programmers are smart enough to handle the compiler's
job of defining 'Image and 'Value, they are able to perform
well as substitutes: by providing the compiler with all correct
implementations for parsing and printing all user-defined literals
of any user-defined type.

^ permalink raw reply	[relevance 1%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-20  0:42  1%                       ` Randy Brukardt
@ 2018-01-20  9:47  1%                         ` Dmitry A. Kazakov
  2018-01-23  0:44  1%                           ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-01-20  9:47 UTC (permalink / raw)


On 2018-01-20 01:42, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:p3sbkb$1msl$1@gioia.aioe.org...
>> On 19/01/2018 02:10, Randy Brukardt wrote:
> ...
>>> The benefit is that these things can express ideas that aren't possible
>>> for
>>> ordinary subprogram calls.
>>
>> That does not justify special syntax. E.g. initialization cannot be
>> expressed as a subprogram call either, nevertheless there is no special
>> syntax for declaration of objects with non-null initialization.
> 
> ??? ":=" is the special syntax of initialization (it's not the syntax of a
> subprogram call!). Your example seems to prove my point. :-)

I meant rather this:

    type T is new Ada.Finalization.Controlled with ...

    X : T;
    Y : Integer;

>>> To express Subtype'First as a function, one would
>>> have to have some sort of meta-type (a subtype parameter).
>>
>> I don't think this is related.
>>
>> (However I am glad that you begin to see subtypes as proper types. (:-))
> 
> A type parameter clearly would have to pass the subtype information as well,

Yes, like it does with array bounds, *if* it were a subprogram proper. 
This is irrelevant because it is not a subprogram, it only has a syntax 
of a subprogram call. But for the compiler it is a special case exactly 
like it is when the attribute syntax is used, or any other syntax. The 
detection does not require special syntax, that is the point. Once the 
compiler detects the case, the magic starts to work.

> since Ada does not allow naming of types. In this case, it is the subtype
> information that is most relevant. So I don't see your point or joke.

It was frequently argued that subtypes are not types but something, 
well, something...

> (And I
> don't see why you don't think it is related, either. One has to have some
> mechanism for getting this information, and if you eliminate the special
> mechanism for that, some replacement is needed. In the proposed language,
> only a subprogram call is available, unless some other special syntax is
> invented, which is just kicking the can.)

It is the same mechanism used to pass/eliminate array bounds. It could 
be generalized for all types including non-tagged classes. The type tag 
of a non-tagged type is a [sub]type constraint to be passed or not. The 
same case is represented by dimensioned values. The dimension is a 
constraint, again passed or not down to the subprogram, kept or not in 
an instance.

I think it is possible to design common rules for all this and make the 
language quite simple.

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

^ permalink raw reply	[relevance 1%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-19  8:52  2%                     ` Dmitry A. Kazakov
@ 2018-01-20  0:42  1%                       ` Randy Brukardt
  2018-01-20  9:47  1%                         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2018-01-20  0:42 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:p3sbkb$1msl$1@gioia.aioe.org...
> On 19/01/2018 02:10, Randy Brukardt wrote:
...
>> The benefit is that these things can express ideas that aren't possible 
>> for
>> ordinary subprogram calls.
>
> That does not justify special syntax. E.g. initialization cannot be 
> expressed as a subprogram call either, nevertheless there is no special 
> syntax for declaration of objects with non-null initialization.

??? ":=" is the special syntax of initialization (it's not the syntax of a 
subprogram call!). Your example seems to prove my point. :-)

>> To express Subtype'First as a function, one would
>> have to have some sort of meta-type (a subtype parameter).
>
> I don't think this is related.
>
> (However I am glad that you begin to see subtypes as proper types. (:-))

A type parameter clearly would have to pass the subtype information as well, 
since Ada does not allow naming of types. In this case, it is the subtype 
information that is most relevant. So I don't see your point or joke. (And I 
don't see why you don't think it is related, either. One has to have some 
mechanism for getting this information, and if you eliminate the special 
mechanism for that, some replacement is needed. In the proposed language, 
only a subprogram call is available, unless some other special syntax is 
invented, which is just kicking the can.)

>> You'd also have
>> to allow "univeral_integer" and the like as expressible data types 
>> (meaning
>> that you'd have to decide what they mean at runtime). All things that 
>> could
>> be done -- in a new language -- but it would be extremely difficult to
>> define such things and keep compatibility with existing Ada.
>
> You know that I disagree with this. In my view it is possible to allow
>
> 1. interfaces and class-wides for scalar types
>
> 2. cloning of type hierarchies by Ada 83 style
>
>    type Y is new X;
>
> Universal_Integer would be a parent of any integer type in its hierarchy.

We actually agree on this: I didn't say it wasn't possible, only that it 
would be "extremely difficult" to define it and both keep compatibility as 
well as convincing all of the stakeholders that it kept compatibility. If 
you win the Powerball Jackpot, please hire me to try. ;-)

                                          Randy.



^ permalink raw reply	[relevance 1%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-19 16:15  2%                 ` AdaMagica
@ 2018-01-19 16:58  2%                   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-01-19 16:58 UTC (permalink / raw)


On 2018-01-19 17:15, AdaMagica wrote:

> Making universal_integer type proper would ruin the whole basis.

I don't see why. In any case if not type then it must be strictly 
static. It cannot be both ways.

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

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 16:59  2%               ` Dmitry A. Kazakov
  2018-01-18 19:36  2%                 ` Mehdi Saada
@ 2018-01-19 16:15  2%                 ` AdaMagica
  2018-01-19 16:58  2%                   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: AdaMagica @ 2018-01-19 16:15 UTC (permalink / raw)


Am Donnerstag, 18. Januar 2018 17:59:57 UTC+1 schrieb Dmitry A. Kazakov:
> It could not be abolished, not without proper classes and interfaces of 
> integer types.
> 
> What one can do is to resolve the issues with universal integers during 
> run-time. Either it must be strictly static compile-time or else a 
> proper type with named run-time instances and user-defined operations.

Ah, I do not think so. See how Ada 83 had still Beaujolais effects (albeit very difficult to obtain) and see how Ada 95 with its well balanced universal_integer (no operators) and root_integer (with operator) types avoids these problems.

Making universal_integer type proper would ruin the whole basis.


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-19  1:10  2%                   ` Randy Brukardt
@ 2018-01-19  8:52  2%                     ` Dmitry A. Kazakov
  2018-01-20  0:42  1%                       ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-01-19  8:52 UTC (permalink / raw)


On 19/01/2018 02:10, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:p3qe4m$t5n$1@gioia.aioe.org...
>> On 18/01/2018 14:08, J-P. Rosen wrote:
>>
>>> If the user were allowed to define identifiers with a quote, these would
>>> not be true any more, and there would be no benefit in using a
>>> distinctive syntax.
>>
>> As if there were any benefit of.
> 
> The benefit is that these things can express ideas that aren't possible for
> ordinary subprogram calls.

That does not justify special syntax. E.g. initialization cannot be 
expressed as a subprogram call either, nevertheless there is no special 
syntax for declaration of objects with non-null initialization.

> To express Subtype'First as a function, one would
> have to have some sort of meta-type (a subtype parameter).

I don't think this is related.

(However I am glad that you begin to see subtypes as proper types. (:-))

> You'd also have
> to allow "univeral_integer" and the like as expressible data types (meaning
> that you'd have to decide what they mean at runtime). All things that could
> be done -- in a new language -- but it would be extremely difficult to
> define such things and keep compatibility with existing Ada.

You know that I disagree with this. In my view it is possible to allow

1. interfaces and class-wides for scalar types

2. cloning of type hierarchies by Ada 83 style

    type Y is new X;

Universal_Integer would be a parent of any integer type in its hierarchy.

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

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 19:36  2%                 ` Mehdi Saada
@ 2018-01-19  1:21  2%                   ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2018-01-19  1:21 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:b899a060-6c72-4771-b204-8470ebe6205c@googlegroups.com...
...
>I wonder what already existing code PRECISELY would be broken, if the NEW
>norm (202x) would allow that construct. Since it was NOT present in older
>programs, how it being used in NEW ONES, could be a prolem ? Or gives
>a real world exemple, so I can get your point, AdaMagica.

It wouldn't break any code, it just doesn't make sense to rename a value or 
object as a function. These are different kinds of entities! You can't say:

     function Foobar return Integer renames Some_Object;

either. It makes sense to rename it as an object, or to just use it to 
initialize a constant object.

                    Randy.



^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 15:38  2%               ` Mehdi Saada
@ 2018-01-19  1:13  2%                 ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2018-01-19  1:13 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:8e553cd1-0822-4572-a41b-a7aaaa424b46@googlegroups.com...
>I wanted to rename an attribute as an object at first... Length : Integer 
>renames Object_Array'Length

We're considering this (specifically, making everything an object so it can 
be renamed). But I tried it and couldn't figure out how to do it without 
writing a definition for the meaning of object for each and every 
non-subprogram attribute (which is most of them), so I've (personally) given 
up. Others are planning to try (we'll see if they succeed).

                                                Randy.





^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 15:23  2%                 ` Dmitry A. Kazakov
@ 2018-01-19  1:10  2%                   ` Randy Brukardt
  2018-01-19  8:52  2%                     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2018-01-19  1:10 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:p3qe4m$t5n$1@gioia.aioe.org...
> On 18/01/2018 14:08, J-P. Rosen wrote:
>
>> If the user were allowed to define identifiers with a quote, these would
>> not be true any more, and there would be no benefit in using a
>> distinctive syntax.
>
> As if there were any benefit of.

The benefit is that these things can express ideas that aren't possible for 
ordinary subprogram calls. To express Subtype'First as a function, one would 
have to have some sort of meta-type (a subtype parameter). You'd also have 
to allow "univeral_integer" and the like as expressible data types (meaning 
that you'd have to decide what they mean at runtime). All things that could 
be done -- in a new language -- but it would be extremely difficult to 
define such things and keep compatibility with existing Ada.

                          Randy.



^ permalink raw reply	[relevance 2%]

* Re: implementation of Bounded_String
  @ 2018-01-18 22:24  1% ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2018-01-18 22:24 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> Where can I read GNAT'S implementation of those package ? What's their
> filename ? I suppose it's the same in mac, linux and windows version.

(where your compiler is installed is referred to as $prefix:
e.g. /usr/local/gnat2017 perhaps)

The source is in $prefix/lib/gcc/*/*/adainclude/

e.g. for me

   /opt/gnat-gpl-2017/lib/gcc/x86_64-apple-darwin14.5.0/6.3.1/adainclude/

The file names are compressed: you can find out which contains which
package using gnatkr:

   $ gnatkr ada.strings.unbounded.ads
   a-strunb.ads

If you want to explore the library using GPS (a good idea, it's large &
complex), you could write a GPR (don't try building with it!) like

   project Ada_Library is
      Loc := "/opt/gnat-gpl-2017/lib/gcc/x86_64-apple-darwin14.5.0/6.3.1/";
      for Source_Dirs use (Loc & "adainclude");
      for Object_Dir use Loc & "adalib";
   end Ada_Library;

And yes, aside from a few low-level packages, it's the same on all OSs.


^ permalink raw reply	[relevance 1%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 16:59  2%               ` Dmitry A. Kazakov
@ 2018-01-18 19:36  2%                 ` Mehdi Saada
  2018-01-19  1:21  2%                   ` Randy Brukardt
  2018-01-19 16:15  2%                 ` AdaMagica
  1 sibling, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-18 19:36 UTC (permalink / raw)


>> Since universal_integer is meant to be compatible with everything, and since Ada83 is long gone, 
>> could "function Length return Integer renames Object_Array'Length" be accepted now ? I don't think it could break any existing code to accept something that wasn't. 

>There's still lots of Ada 83 code around in the embedded world. 
>And Ada 95 didn't abolish universal_integer. 

I know that. "abolish" meant "the internal logic and constraints of Ada83 not being the same anymore", no more (sorry, wrong word).
I wonder what already existing code PRECISELY would be broken, if the NEW norm (202x) would allow that construct. Since it was NOT present in older programs, how it being used in NEW ONES, could be a prolem ? Or gives a real world exemple, so I can get your point, AdaMagica.


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 16:48  2%             ` AdaMagica
@ 2018-01-18 16:59  2%               ` Dmitry A. Kazakov
  2018-01-18 19:36  2%                 ` Mehdi Saada
  2018-01-19 16:15  2%                 ` AdaMagica
  0 siblings, 2 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-01-18 16:59 UTC (permalink / raw)


On 2018-01-18 17:48, AdaMagica wrote:
> Am Donnerstag, 18. Januar 2018 15:17:05 UTC+1 schrieb Mehdi Saada:
>> Since universal_integer is meant to be compatible with everything, and since Ada83 is long gone,
>> could "function Length return Integer renames Object_Array'Length" be accepted now ? I don't think it could break any existing code to accept something that wasn't.
> 
> There's still lots of Ada 83 code around in the embedded world.
> And Ada 95 didn't abolish universal_integer.

It could not be abolished, not without proper classes and interfaces of 
integer types.

What one can do is to resolve the issues with universal integers during 
run-time. Either it must be strictly static compile-time or else a 
proper type with named run-time instances and user-defined operations.

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

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 14:17  2%           ` Mehdi Saada
  2018-01-18 14:56  2%             ` J-P. Rosen
@ 2018-01-18 16:48  2%             ` AdaMagica
  2018-01-18 16:59  2%               ` Dmitry A. Kazakov
  2018-01-21 23:27  1%             ` G.B.
  2 siblings, 1 reply; 200+ results
From: AdaMagica @ 2018-01-18 16:48 UTC (permalink / raw)


Am Donnerstag, 18. Januar 2018 15:17:05 UTC+1 schrieb Mehdi Saada:
> Since universal_integer is meant to be compatible with everything, and since Ada83 is long gone,
> could "function Length return Integer renames Object_Array'Length" be accepted now ? I don't think it could break any existing code to accept something that wasn't.

There's still lots of Ada 83 code around in the embedded world.
And Ada 95 didn't abolish universal_integer.

Please dive into the very heart of the definition of numeric types in Ada before you claim such nonsense.


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 14:56  2%             ` J-P. Rosen
@ 2018-01-18 15:38  2%               ` Mehdi Saada
  2018-01-19  1:13  2%                 ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-18 15:38 UTC (permalink / raw)


I wanted to rename an attribute as an object at first... Length : Integer renames Object_Array'Length
Just because I'm obstinate and love renaming :-PP
Fine, I can live without :-P


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 13:08  1%               ` J-P. Rosen
@ 2018-01-18 15:23  2%                 ` Dmitry A. Kazakov
  2018-01-19  1:10  2%                   ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-01-18 15:23 UTC (permalink / raw)


On 18/01/2018 14:08, J-P. Rosen wrote:

> If the user were allowed to define identifiers with a quote, these would
> not be true any more, and there would be no benefit in using a
> distinctive syntax.

As if there were any benefit of.

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

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 14:17  2%           ` Mehdi Saada
@ 2018-01-18 14:56  2%             ` J-P. Rosen
  2018-01-18 15:38  2%               ` Mehdi Saada
  2018-01-18 16:48  2%             ` AdaMagica
  2018-01-21 23:27  1%             ` G.B.
  2 siblings, 1 reply; 200+ results
From: J-P. Rosen @ 2018-01-18 14:56 UTC (permalink / raw)


Le 18/01/2018 à 15:17, Mehdi Saada a écrit :
> Since universal_integer is meant to be compatible with everything,
> and since Ada83 is long gone, could "function Length return Integer
> renames Object_Array'Length" be accepted now ? I don't think it could
> break any existing code to accept something that wasn't.
> 

Why do you insist on renaming a /value/ as a /function/? The following
will do exactly the same thing:

Length : constant Integer := Object_Array'Length;

-- 
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.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 14:05  2%         ` AdaMagica
@ 2018-01-18 14:17  2%           ` Mehdi Saada
  2018-01-18 14:56  2%             ` J-P. Rosen
                               ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: Mehdi Saada @ 2018-01-18 14:17 UTC (permalink / raw)


Since universal_integer is meant to be compatible with everything, and since Ada83 is long gone,
could "function Length return Integer renames Object_Array'Length" be accepted now ? I don't think it could break any existing code to accept something that wasn't.

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18  8:34  2%       ` Dmitry A. Kazakov
  2018-01-18 11:14  2%         ` Simon Wright
@ 2018-01-18 14:05  2%         ` AdaMagica
  2018-01-18 14:17  2%           ` Mehdi Saada
  1 sibling, 1 reply; 200+ results
From: AdaMagica @ 2018-01-18 14:05 UTC (permalink / raw)


Am Donnerstag, 18. Januar 2018 09:34:51 UTC+1 schrieb Dmitry A. Kazakov:
> You can rename result of a function too. (It does make much sense in the 
> case of scalar values returned by value).
> 
> However you cannot rename a non-object. A subtle distinction, but it is 
> there. That would prevent renaming of an attribute Object'Length which 
> is not an object for whatever strange reason.

Simple. Attribute Length is universam_integer.

> Attributes have a long 
> history of being queer. E.g. "abc"'Length is still illegal, AFAIK. In 
> Ada attributes are not considered operations as they should.

Back to Ada 80/83:

A requirement on all predefinied operations on scalar types was that they could not be hidden - so they had to be operators. Ada 80 had Abs as a function name, which was accordingly changed to "abs".
So everything else had to use some other syntax - this was chosen to be attributes.

And since Length has no relation to the index type, but had to be usable for any integer type, the solution was universal_integer, as was also chosen for some others.

And of course are attributes operations (see RM, for instance 3.5.5) - they are not operators!

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 12:21  2%             ` Mehdi Saada
@ 2018-01-18 13:08  1%               ` J-P. Rosen
  2018-01-18 15:23  2%                 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: J-P. Rosen @ 2018-01-18 13:08 UTC (permalink / raw)


Le 18/01/2018 à 13:21, Mehdi Saada a écrit :
>> function "'Image" (X : Integer) return String; X'Image <=> "'Image"
>> (X)
> 
> I read that idea several times here and elsewhere. It seems logical
> indeed. Has it been directly refused ? If so what was their rational?
> 
It would defeat the whole benefit of attributes.

Attributes are constants or subprograms that are provided automatically
by the compiler. In a sense, their names are just like identifiers with
a ''' in the middle (OK lawyers, it's not really true, but it is close
enough for the casual user). This way, 1) it is clear that it is
provided by the compiler, and 2) it cannot clash with any user-defined
identifier.

If the user were allowed to define identifiers with a quote, these would
not be true any more, and there would be no benefit in using a
distinctive syntax.

-- 
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.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 11:55  2%           ` Dmitry A. Kazakov
@ 2018-01-18 12:21  2%             ` Mehdi Saada
  2018-01-18 13:08  1%               ` J-P. Rosen
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-18 12:21 UTC (permalink / raw)


>     function "'Image" (X : Integer) return String; 
>     X'Image <=> "'Image" (X)

I read that idea several times here and elsewhere. It seems logical indeed. Has it been directly refused ? If so what was their rational ?


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18 11:14  2%         ` Simon Wright
@ 2018-01-18 11:55  2%           ` Dmitry A. Kazakov
  2018-01-18 12:21  2%             ` Mehdi Saada
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-01-18 11:55 UTC (permalink / raw)


On 18/01/2018 12:14, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> In Ada attributes are not considered operations as they should.
> 
> In spite of the way some attributes can be overridden by operations
> (e.g. 'Read).

Yes. It should rather have been an operator-syntax with a 
straightforward sugar:

    function "'Image" (X : Integer) return String;

    X'Image <=> "'Image" (X)

And of course primitive for tagged types.

P.S. Falls into the categories "not ugly enough" and "too simple" to 
adopt... (:-))

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


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-18  8:34  2%       ` Dmitry A. Kazakov
@ 2018-01-18 11:14  2%         ` Simon Wright
  2018-01-18 11:55  2%           ` Dmitry A. Kazakov
  2018-01-18 14:05  2%         ` AdaMagica
  1 sibling, 1 reply; 200+ results
From: Simon Wright @ 2018-01-18 11:14 UTC (permalink / raw)


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

> In Ada attributes are not considered operations as they should.

In spite of the way some attributes can be overridden by operations
(e.g. 'Read).

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-17 22:50  2%     ` Mehdi Saada
@ 2018-01-18  8:34  2%       ` Dmitry A. Kazakov
  2018-01-18 11:14  2%         ` Simon Wright
  2018-01-18 14:05  2%         ` AdaMagica
  0 siblings, 2 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-01-18  8:34 UTC (permalink / raw)


On 17/01/2018 23:50, Mehdi Saada wrote:
>> Remember position vs. index:
>>      Length : constant Integer := Object'Length;
>>      First  : constant Index_Type := Object'First;
>>      Last   : constant Index_Type := Object'Last;
> 
> Yeah, an Integer subtype. Ah, always something I forget to precise explicitely.
> I saw it goes along well with a constant declaration, but I wanted a renaming declaration...

You can rename result of a function too. (It does make much sense in the 
case of scalar values returned by value).

However you cannot rename a non-object. A subtle distinction, but it is 
there. That would prevent renaming of an attribute Object'Length which 
is not an object for whatever strange reason. Attributes have a long 
history of being queer. E.g. "abc"'Length is still illegal, AFAIK. In 
Ada attributes are not considered operations as they should.

A discriminant of some object can be renamed, no problem. So

    type Object_Type (Length : Natural) is ...;
    Object : Object_Type (10);
    Length : Integer renames Object.Length; -- This is OK, 10

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


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-17 16:30  2%   ` Dmitry A. Kazakov
@ 2018-01-17 22:50  2%     ` Mehdi Saada
  2018-01-18  8:34  2%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-17 22:50 UTC (permalink / raw)


> Remember position vs. index:
>     Length : constant Integer := Object'Length;
>     First  : constant Index_Type := Object'First;
>     Last   : constant Index_Type := Object'Last;

Yeah, an Integer subtype. Ah, always something I forget to precise explicitely.
I saw it goes along well with a constant declaration, but I wanted a renaming declaration...

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-15 16:06  2% ` Mehdi Saada
@ 2018-01-17 19:23  2%   ` Niklas Holsti
  0 siblings, 0 replies; 200+ results
From: Niklas Holsti @ 2018-01-17 19:23 UTC (permalink / raw)


On 18-01-15 18:06 , Mehdi Saada wrote:
> I succeeded: in the end, I wrote that:
> for Ind in reverse 1..Length(LIGNE) loop
>          C1 := TO_BASIC( TO_LOWER( ELEMENT( LIGNE,IND )));
>          if IS_LETTER(C1) then
>             EMPILER(LA_PILE,C1);
>             APPEND(CHAINE,C1);
>          end if;
> end loop;

Note that this loop will stack up (EMPILER) the elements of LIGNE in 
*reverse order* compared to your first loop, "for Ind in 1 .. 
Length(LIGNE)".

This reverse order may or may not be correct for your problem. But 
usually the order of the elements in a stack *is* important.

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


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-17 15:45  2% ` Mehdi Saada
@ 2018-01-17 16:30  2%   ` Dmitry A. Kazakov
  2018-01-17 22:50  2%     ` Mehdi Saada
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-01-17 16:30 UTC (permalink / raw)


On 17/01/2018 16:45, Mehdi Saada wrote:
> Can I write
>        SO_size : constant Length_Range := String_Object'Length;
> using a renaming statement without significantly more characters ?

What is Length_Range, an integer subtype?

Remember position vs. index:

    Length : constant Integer := Object'Length;

    First  : constant Index_Type := Object'First;
    Last   : constant Index_Type := Object'Last;

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


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
                     ` (2 preceding siblings ...)
  2018-01-16 16:24  2% ` Mehdi Saada
@ 2018-01-17 15:45  2% ` Mehdi Saada
  2018-01-17 16:30  2%   ` Dmitry A. Kazakov
  3 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-17 15:45 UTC (permalink / raw)


Can I write
      SO_size : constant Length_Range := String_Object'Length;
using a renaming statement without significantly more characters ?
I don't think so, but I try to use to use renaming as much possible, it's so elegant...


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-16 18:20  2%   ` Jacob Sparre Andersen
@ 2018-01-16 20:00  2%     ` Mehdi Saada
  0 siblings, 0 replies; 200+ results
From: Mehdi Saada @ 2018-01-16 20:00 UTC (permalink / raw)


idiotic me... forgot that. Feels good to live outside real world ;-)
I haven't really understood the thing about me conflating index and position. Where exactly in the piece of code I shared, did I mixed the two ?
I may err elsewhere, if I don't get it now. 

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-16 16:24  2% ` Mehdi Saada
@ 2018-01-16 18:20  2%   ` Jacob Sparre Andersen
  2018-01-16 20:00  2%     ` Mehdi Saada
  0 siblings, 1 reply; 200+ results
From: Jacob Sparre Andersen @ 2018-01-16 18:20 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> But what might people need to use the FSF version instead of Adacore's
> anyway?

Some people may not want to release their executables under the Gnu GPL.

Greetings,

Jacob
-- 
"There's a lot of information that was in the programmer's head
 when they wrote the code that isn't reflected in that code"

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-16 16:06  1%     ` Brian Drummond
@ 2018-01-16 17:21  2%       ` Anh Vo
  0 siblings, 0 replies; 200+ results
From: Anh Vo @ 2018-01-16 17:21 UTC (permalink / raw)


On Tuesday, January 16, 2018 at 8:06:33 AM UTC-8, Brian Drummond wrote:
> On Mon, 15 Jan 2018 09:22:34 -0800, Anh Vo wrote:
> 
> > On Monday, January 15, 2018 at 12:29:41 AM UTC-8, Dmitry A. Kazakov
> >> 
> >>     addr2line --exe=<program-name> <funny-numbers>
> >> 
> >> That will give you the stack trace.
> >  
> > It is even better to use GNAT addition to print out full stack trace as
> > shown in the snippet.
> > 
> > -- ...
> > 
> > exception
> > 
> > when Err : others =>
> > 
> >   Text_Io.Put_Line ("Houston we have a problem: " &
> >                                     Exceptions.Exception_Information
> >                                     (Err));
> >   Text_Io.Put_Line ("Traceback => " &
> >   GNAT.Traceback.Symbolic.Symbolic_Traceback(Err));
> > end [Ada Unit Name];
> 
> This has some issues with (FSF) Gnat 6.3 (at least on Debian Stretch).
> I asked about this on the Gnoga list, still working through the issues.
> 
> (1) It just prints out the same funny numbers, with capital letters in 
> the hex part.
> 
> (2) Feeding the funny numbers to addr2line just gives a bunch of question 
> marks.
> 
> The culprit appears to be something to do with Position Independent 
> Executables, and Address Space Randomization, which appear to have broken 
> a few things. 
> 
> Adding "-no-pie" (NOT "-Wl,-no_pie") to the Linker switches changes the 
> funny numbers, such that addr2line can now parse them, fixing (2).
> 
> However neither this nor explicitly linking libreadline (adding 
> "-lreadline" to teh linker options fixes (1). I have a feeling that when 
> (2) broke, a quick fix was added to GNAT.Traceback.Symbolic to "fix" (1).
> 
> (checking the RTS source I see a comment...
> --  This is the default implementation for platforms where the full 
> capability
> --  is not supported. It returns tracebacks as lists of hexadecimal 
> addresses
> --  of the form "0x...".
> 
> So, apparently not provided in recent-ish FSF Gnat compilers ... if it 
> ever was.

I trusted that switch -g passed during compilation, -E passed during binding and -g passed during linking.

Anh Vo

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
      2018-01-15 16:06  2% ` Mehdi Saada
@ 2018-01-16 16:24  2% ` Mehdi Saada
  2018-01-16 18:20  2%   ` Jacob Sparre Andersen
  2018-01-17 15:45  2% ` Mehdi Saada
  3 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-16 16:24 UTC (permalink / raw)


But what might people need to use the FSF version instead of Adacore's anyway ?

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-15 17:22  2%   ` Anh Vo
  2018-01-15 17:48  2%     ` Dmitry A. Kazakov
@ 2018-01-16 16:06  1%     ` Brian Drummond
  2018-01-16 17:21  2%       ` Anh Vo
  1 sibling, 1 reply; 200+ results
From: Brian Drummond @ 2018-01-16 16:06 UTC (permalink / raw)


On Mon, 15 Jan 2018 09:22:34 -0800, Anh Vo wrote:

> On Monday, January 15, 2018 at 12:29:41 AM UTC-8, Dmitry A. Kazakov
>> 
>>     addr2line --exe=<program-name> <funny-numbers>
>> 
>> That will give you the stack trace.
>  
> It is even better to use GNAT addition to print out full stack trace as
> shown in the snippet.
> 
> -- ...
> 
> exception
> 
> when Err : others =>
> 
>   Text_Io.Put_Line ("Houston we have a problem: " &
>                                     Exceptions.Exception_Information
>                                     (Err));
>   Text_Io.Put_Line ("Traceback => " &
>   GNAT.Traceback.Symbolic.Symbolic_Traceback(Err));
> end [Ada Unit Name];

This has some issues with (FSF) Gnat 6.3 (at least on Debian Stretch).
I asked about this on the Gnoga list, still working through the issues.

(1) It just prints out the same funny numbers, with capital letters in 
the hex part.

(2) Feeding the funny numbers to addr2line just gives a bunch of question 
marks.

The culprit appears to be something to do with Position Independent 
Executables, and Address Space Randomization, which appear to have broken 
a few things. 

Adding "-no-pie" (NOT "-Wl,-no_pie") to the Linker switches changes the 
funny numbers, such that addr2line can now parse them, fixing (2).

However neither this nor explicitly linking libreadline (adding 
"-lreadline" to teh linker options fixes (1). I have a feeling that when 
(2) broke, a quick fix was added to GNAT.Traceback.Symbolic to "fix" (1).

(checking the RTS source I see a comment...
--  This is the default implementation for platforms where the full 
capability
--  is not supported. It returns tracebacks as lists of hexadecimal 
addresses
--  of the form "0x...".

So, apparently not provided in recent-ish FSF Gnat compilers ... if it 
ever was.

-- Brian


^ permalink raw reply	[relevance 1%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-15 17:48  2%     ` Dmitry A. Kazakov
@ 2018-01-15 19:56  2%       ` Anh Vo
  0 siblings, 0 replies; 200+ results
From: Anh Vo @ 2018-01-15 19:56 UTC (permalink / raw)


On Monday, January 15, 2018 at 9:48:12 AM UTC-8, Dmitry A. Kazakov wrote:
> On 2018-01-15 18:22, Anh Vo wrote:
> > On Monday, January 15, 2018 at 12:29:41 AM UTC-8, Dmitry A. Kazakov wrote:
> >> On 15/01/2018 02:18, Mehdi Saada wrote:
> >>> This if statement exactly, seems to raise
> >>> "ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782"(No indication of line, so I can't know more).
> >>
> >> There is a list of funny numbers following the exception message. Pass
> >> that list to
> >>
> >>      addr2line --exe=<program-name> <funny-numbers>
> >>
> >> That will give you the stack trace.
> >   
> > It is even better to use GNAT addition to print out full stack trace as shown in the snippet.
> > 
> > -- ...
> > 
> > exception
> > 
> > when Err : others =>
> > 
> >    Text_Io.Put_Line ("Houston we have a problem: " &
> >                                      Exceptions.Exception_Information (Err));
> >    Text_Io.Put_Line ("Traceback => " & GNAT.Traceback.Symbolic.Symbolic_Traceback(Err));
> > end [Ada Unit Name];
> 
> Even better to make AdaCore make this the default behavior when dealing 
> with unhandled exception. >>

At least for me, a debugger is never needed. I consider it a tremendous improvement.

> with unhandled exception. However considering that it took 20 years or 
> so to stop disabling integer overflow checks by default...

It was that long. It is late still better than never :-).  If it was me, I would do it in a day.

Anh Vo

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  @ 2018-01-15 18:55  2%         ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2018-01-15 18:55 UTC (permalink / raw)


On Monday, January 15, 2018 at 5:00:21 AM UTC-7, Mehdi Saada wrote:
> That's an awful lot of things at once x_x, but thanks. So in linux I have to go past the "./doinstall" script, right... Never used specific compilation option for anything until now.
> 
> > When deleting elements of a list by position the loop must run positions 
> >in reverse: 
> >[...]
> >That will keep the positions straight. Position /= index, BTW. 
> >However, deleting characters from a string almost never has sense. You 
> >probably should reconsider the algorithm.
> 
> Ah ? Why so ? And how come position =/ index ? "IND" is the same, isn't ? Performance consideration ? But fine, I'll do without.

The reason position isn't index can be simply illustrated with the following array:
  Example : Array( 11..15 ) of Boolean := (True, False, False, True);

In the above, position #1 is True, #2 & #3 are False, and #4 is True.
HOWEVER, position #1 is index 11, #2 is index 12, etc.
(There's also Offset, which is actually why C programmers seem to be enamored with 0-based indexing; but it only shows they conflate index, position, and offset.)


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-15 15:50  2%             ` Mehdi Saada
@ 2018-01-15 17:53  2%               ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2018-01-15 17:53 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> I know (and saw) others mistakes, but that's for later. What's wrong
> with this "if" line ?

Your original problem was with

   for Ind in 1..Length(CHAINE) loop
           begin
               if IS_BASIC(ELEMENT(CHAINE,IND)) then
                       EMPILER(LA_PILE,ELEMENT(CHAINE,IND));
               else DELETE(CHAINE, IND,IND);
               end if;
            end;
   end loop;

So suppose Length(CHAINE) started at 10; we're looping from 1 .. 10.

Now suppose you execute the DELETE. That means that now Length(CHAINE)
is 9, *but* you are still looping from 1 .. 10; so that when IND gets to
10 (the loop range doesn't alter), ELEMENT(CHAINE,IND) is trying to
access an element which doesn't exist.


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  2018-01-15 17:22  2%   ` Anh Vo
@ 2018-01-15 17:48  2%     ` Dmitry A. Kazakov
  2018-01-15 19:56  2%       ` Anh Vo
  2018-01-16 16:06  1%     ` Brian Drummond
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-01-15 17:48 UTC (permalink / raw)


On 2018-01-15 18:22, Anh Vo wrote:
> On Monday, January 15, 2018 at 12:29:41 AM UTC-8, Dmitry A. Kazakov wrote:
>> On 15/01/2018 02:18, Mehdi Saada wrote:
>>> This if statement exactly, seems to raise
>>> "ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782"(No indication of line, so I can't know more).
>>
>> There is a list of funny numbers following the exception message. Pass
>> that list to
>>
>>      addr2line --exe=<program-name> <funny-numbers>
>>
>> That will give you the stack trace.
>   
> It is even better to use GNAT addition to print out full stack trace as shown in the snippet.
> 
> -- ...
> 
> exception
> 
> when Err : others =>
> 
>    Text_Io.Put_Line ("Houston we have a problem: " &
>                                      Exceptions.Exception_Information (Err));
>    Text_Io.Put_Line ("Traceback => " & GNAT.Traceback.Symbolic.Symbolic_Traceback(Err));
> end [Ada Unit Name];

Even better to make AdaCore make this the default behavior when dealing 
with unhandled exception. However considering that it took 20 years or 
so to stop disabling integer overflow checks by default...

P.S. When GPS is running with the switch --server=<port> one can make it 
open the window with the source code at the error line! (:-))

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

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
    @ 2018-01-15 17:22  2%   ` Anh Vo
  2018-01-15 17:48  2%     ` Dmitry A. Kazakov
  2018-01-16 16:06  1%     ` Brian Drummond
  1 sibling, 2 replies; 200+ results
From: Anh Vo @ 2018-01-15 17:22 UTC (permalink / raw)


On Monday, January 15, 2018 at 12:29:41 AM UTC-8, Dmitry A. Kazakov wrote:
> On 15/01/2018 02:18, Mehdi Saada wrote:
> > This if statement exactly, seems to raise
> > "ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782"(No indication of line, so I can't know more).
> 
> There is a list of funny numbers following the exception message. Pass 
> that list to
> 
>     addr2line --exe=<program-name> <funny-numbers>
> 
> That will give you the stack trace.
 
It is even better to use GNAT addition to print out full stack trace as shown in the snippet.

-- ...

exception

when Err : others =>

  Text_Io.Put_Line ("Houston we have a problem: " &
                                    Exceptions.Exception_Information (Err));
  Text_Io.Put_Line ("Traceback => " & GNAT.Traceback.Symbolic.Symbolic_Traceback(Err));
end [Ada Unit Name];

Anh Vo


^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
    @ 2018-01-15 16:06  2% ` Mehdi Saada
  2018-01-17 19:23  2%   ` Niklas Holsti
  2018-01-16 16:24  2% ` Mehdi Saada
  2018-01-17 15:45  2% ` Mehdi Saada
  3 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-15 16:06 UTC (permalink / raw)


I succeeded: in the end, I wrote that:
for Ind in reverse 1..Length(LIGNE) loop
         C1 := TO_BASIC( TO_LOWER( ELEMENT( LIGNE,IND )));
         if IS_LETTER(C1) then
            EMPILER(LA_PILE,C1);
            APPEND(CHAINE,C1);
         end if;
end loop;

It's way cleaner. Ah, the joy of succeeding when you know it means a progress in your self-imposed personal objectives. But I would like to know what was intimately wrong with the precedent "if" condition.

^ permalink raw reply	[relevance 2%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  @ 2018-01-15 15:50  2%             ` Mehdi Saada
  2018-01-15 17:53  2%               ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-01-15 15:50 UTC (permalink / raw)


I know (and saw) others mistakes, but that's for later. What's wrong with this "if" line ?


^ permalink raw reply	[relevance 2%]

Results 1-200 of ~3000   | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2018-01-15  1:18     ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782 Mehdi Saada
2018-01-15  8:29     ` Dmitry A. Kazakov
2018-01-15 10:49       ` Simon Wright
2018-01-15 11:51         ` Mehdi Saada
2018-01-15 12:00           ` Mehdi Saada
2018-01-15 18:55  2%         ` Shark8
2018-01-15 13:51           ` Simon Wright
2018-01-15 15:18             ` Mehdi Saada
2018-01-15 15:29               ` Mehdi Saada
2018-01-15 15:50  2%             ` Mehdi Saada
2018-01-15 17:53  2%               ` Simon Wright
2018-01-15 17:22  2%   ` Anh Vo
2018-01-15 17:48  2%     ` Dmitry A. Kazakov
2018-01-15 19:56  2%       ` Anh Vo
2018-01-16 16:06  1%     ` Brian Drummond
2018-01-16 17:21  2%       ` Anh Vo
2018-01-15 16:06  2% ` Mehdi Saada
2018-01-17 19:23  2%   ` Niklas Holsti
2018-01-16 16:24  2% ` Mehdi Saada
2018-01-16 18:20  2%   ` Jacob Sparre Andersen
2018-01-16 20:00  2%     ` Mehdi Saada
2018-01-17 15:45  2% ` Mehdi Saada
2018-01-17 16:30  2%   ` Dmitry A. Kazakov
2018-01-17 22:50  2%     ` Mehdi Saada
2018-01-18  8:34  2%       ` Dmitry A. Kazakov
2018-01-18 11:14  2%         ` Simon Wright
2018-01-18 11:55  2%           ` Dmitry A. Kazakov
2018-01-18 12:21  2%             ` Mehdi Saada
2018-01-18 13:08  1%               ` J-P. Rosen
2018-01-18 15:23  2%                 ` Dmitry A. Kazakov
2018-01-19  1:10  2%                   ` Randy Brukardt
2018-01-19  8:52  2%                     ` Dmitry A. Kazakov
2018-01-20  0:42  1%                       ` Randy Brukardt
2018-01-20  9:47  1%                         ` Dmitry A. Kazakov
2018-01-23  0:44  1%                           ` Randy Brukardt
2018-01-18 14:05  2%         ` AdaMagica
2018-01-18 14:17  2%           ` Mehdi Saada
2018-01-18 14:56  2%             ` J-P. Rosen
2018-01-18 15:38  2%               ` Mehdi Saada
2018-01-19  1:13  2%                 ` Randy Brukardt
2018-01-18 16:48  2%             ` AdaMagica
2018-01-18 16:59  2%               ` Dmitry A. Kazakov
2018-01-18 19:36  2%                 ` Mehdi Saada
2018-01-19  1:21  2%                   ` Randy Brukardt
2018-01-19 16:15  2%                 ` AdaMagica
2018-01-19 16:58  2%                   ` Dmitry A. Kazakov
2018-01-21 23:27  1%             ` G.B.
2018-01-18 14:10     implementation of Bounded_String Mehdi Saada
2018-01-18 22:24  1% ` Simon Wright
2018-01-25  0:22     Iterable container as generic parameter Lionel Draghi
2018-01-25  3:36     ` Randy Brukardt
2018-01-25 14:58  2%   ` Lionel Draghi
2018-01-26  4:50         ` Randy Brukardt
2018-01-26  9:09           ` briot.emmanuel
2018-01-28 18:08  2%         ` Lionel Draghi
2018-02-01  5:52     Reference counter in smart pointers are not updated properly when used by multiple tasks onox
2018-02-01 19:04  2% ` Robert A Duff
2018-02-03 11:06  2% Array of records with default values not propagating to array Bojan Bozovic
2018-02-03 14:16  2% ` Jere
2018-02-03 15:26  2%   ` Simon Wright
2018-02-04  9:21  0%     ` Niklas Holsti
2018-02-04  9:32  0%       ` Simon Wright
2018-02-04  4:59  0% ` Bojan Bozovic
2018-02-04 10:07       ` Niklas Holsti
2018-02-04 11:38  1%     ` Bojan Bozovic
2018-02-21 23:57  1% article on acces types and dynamic serialization in Ada (2003) Mehdi Saada
2018-02-22 22:54  1% alternative elsif branch not tested Mehdi Saada
2018-02-22 23:09  1% ` Mehdi Saada
2018-02-22 23:29  0%   ` Anh Vo
2018-02-22 23:54  1%   ` Randy Brukardt
2018-02-24 19:42     open a file non-blocking ? patrick
2018-02-26  2:53     ` Robert Eachus
2018-02-26 16:41  2%   ` Jeffrey R. Carter
2018-03-01  0:27     CONSTRAINT ERROR? access check failed Mehdi Saada
2018-03-01  8:07     ` Niklas Holsti
2018-03-01 12:44  2%   ` Mehdi Saada
2018-03-01 13:45  2%     ` Björn Lundin
2018-04-15 21:48     How to get Ada to “cross the chasm”? Dan'l Miller
2018-04-16  5:35     ` Paul Rubin
2018-04-18 13:29       ` Jere
2018-04-18 17:02         ` Lucretia
2018-05-04 13:30           ` Jere
2018-05-04 19:07             ` Niklas Holsti
2018-05-05  4:01               ` Dennis Lee Bieber
2018-05-05  8:06                 ` Simon Wright
2018-05-05 20:02                   ` Paul Rubin
2018-05-05 20:22                     ` Niklas Holsti
2018-05-05 23:06                       ` Paul Rubin
2018-05-06 16:58  2%                     ` Jacob Sparre Andersen
2018-04-30 11:28  1% ` Mehdi Saada
2018-04-30 12:39  0%   ` Dmitry A. Kazakov
2018-05-26 21:43  2% Strings with discriminated records NiGHTS
2018-06-08  5:52     GNATCOLL JSON Parsing eduardsapotski
2018-11-26  6:42     ` eduardsapotski
2018-12-03 18:10  1%   ` Simon Wright
2018-06-14 15:37     Unknown constraints and type composition Alejandro R. Mosteo
2018-06-14 17:53     ` Jeffrey R. Carter
2018-06-15  5:13       ` J-P. Rosen
2018-07-08 13:53  2%     ` Jacob Sparre Andersen
2018-06-30 10:48     Strange crash on custom iterator Lucretia
2018-06-30 11:32     ` Simon Wright
2018-06-30 12:02       ` Lucretia
2018-06-30 14:25         ` Simon Wright
2018-06-30 14:33           ` Lucretia
2018-06-30 19:25             ` Simon Wright
2018-06-30 19:36               ` Luke A. Guest
2018-07-01 18:06                 ` Jacob Sparre Andersen
2018-07-01 19:59                   ` Simon Wright
2018-07-02 17:43                     ` Luke A. Guest
2018-07-02 19:42  1%                   ` Simon Wright
2018-07-03 14:08                         ` Lucretia
2018-07-03 14:17  1%                       ` J-P. Rosen
2018-07-03 15:06  0%                         ` Lucretia
2018-07-03 15:45                               ` J-P. Rosen
2018-07-03 15:57                                 ` Dmitry A. Kazakov
2018-07-03 16:07                                   ` Lucretia
2018-07-03 16:36                                     ` Dmitry A. Kazakov
2018-07-04  7:33                                       ` J-P. Rosen
2018-07-04  7:53                                         ` Dmitry A. Kazakov
2018-07-04  9:55                                           ` J-P. Rosen
2018-07-04 10:01                                             ` Dmitry A. Kazakov
2018-07-04 11:30                                               ` J-P. Rosen
2018-07-04 13:27                                                 ` Dmitry A. Kazakov
2018-07-04 14:37                                                   ` Dan'l Miller
2018-07-04 15:41                                                     ` Lucretia
2018-07-04 16:55                                                       ` Dan'l Miller
2018-07-04 18:01                                                         ` Shark8
2018-07-04 18:57                                                           ` Dmitry A. Kazakov
2018-07-04 19:53                                                             ` Shark8
2018-07-04 20:05                                                               ` Lucretia
2018-07-04 22:04                                                                 ` Shark8
2018-07-05  0:12                                                                   ` Dan'l Miller
2018-07-05  1:46                                                                     ` Shark8
2018-07-05  2:07                                                                       ` Luke A. Guest
2018-07-05 16:47                                                                         ` Shark8
2018-07-05 17:19  1%                                                                       ` Dan'l Miller
2018-07-05 19:14  0%                                                                         ` Shark8
2018-07-16  8:20     Simple hash or pseudo-random function gautier_niouzes
2018-07-16 17:17     ` Jeffrey R. Carter
2018-07-16 21:14       ` gautier_niouzes
2018-07-17  6:09  1%     ` Jeffrey R. Carter
2018-07-18 13:38  0%       ` gautier_niouzes
2018-08-01  9:08  2%         ` gautier_niouzes
2018-10-31  2:57     windows-1251 to utf-8 eduardsapotski
2018-10-31 15:28  2% ` eduardsapotski
2018-10-31 17:01  0%   ` Dmitry A. Kazakov
2018-10-31 20:58  2%     ` Randy Brukardt
2018-11-01 12:49  0%   ` Björn Lundin
2018-12-29 15:34     Gtk Ada Message box example ldries46
2018-12-29 16:09     ` Dmitry A. Kazakov
2018-12-31  7:31  2%   ` ldries46
2019-01-02 15:48     class wide iterable (and indexable) George Shapovalov
2019-01-02 17:39     ` Simon Wright
2019-01-02 18:11       ` George Shapovalov
2019-01-03  8:52  2%     ` Simon Wright
2019-01-04  4:32  0%       ` Shark8
2019-01-05  9:03  0%         ` Randy Brukardt
2019-01-03 22:56         ` Randy Brukardt
2019-01-04  0:00           ` George Shapovalov
2019-01-04  8:43             ` Dmitry A. Kazakov
2019-01-05  9:21               ` Randy Brukardt
2019-01-05 10:07  1%             ` Dmitry A. Kazakov
2019-01-07 21:07  0%               ` Randy Brukardt
2019-01-08  9:51  0%                 ` Dmitry A. Kazakov
2019-02-06 23:10     Ada x <whatever> Datagram Sockets Rego, P.
2019-02-07  0:42     ` Jere
2019-02-07  5:28       ` Rego, P.
2019-02-07  6:00  1%     ` Egil H H
2019-02-07  6:41  0%       ` Rego, P.
2019-02-07  7:23  0%         ` Egil H H
2019-02-07 11:47  0%         ` Jere
2019-03-01 13:07     Chess game in character over MS Windows manueledensenster
2019-03-01 13:17  1% ` manueledensenster
2019-05-07 11:26     Ada programmers: Stéphane Carrez - interview Tomek Wałkuski
2019-05-07 14:11     ` Optikos
2019-05-07 20:20  1%   ` stephane.carrez
2019-05-24 15:49     Suggestions needed to split a package A. Cervetti
2019-05-24 16:14     ` Björn Lundin
2019-05-24 20:26       ` Randy Brukardt
2019-05-24 21:21  1%     ` Shark8
2019-06-15 23:59  1% Latest suggestion for 202x Micah Waddoups
2019-06-16  7:17  0% ` Dmitry A. Kazakov
2019-06-16 19:34  0% ` Optikos
2019-06-23 20:17  0% ` Per Sandberg
2019-10-29  1:54     gnat.string_split , howto manipulate slice numbers Alain De Vos
2019-10-29  8:17  2% ` briot.emmanuel
2019-10-29 13:43  1% How to Iterate over all elements of a hashed_map Alain De Vos
2019-10-29 14:20  2% ` Alain De Vos
2019-10-29 15:02  0%   ` joakimds
2019-10-29 21:56  0%     ` Randy Brukardt
2019-11-22 13:09     I need to show extended Ascii codes in GtkAda environment L Dries
2019-11-22 14:12     ` Dmitry A. Kazakov
2019-11-22 21:22  2%   ` Randy Brukardt
2019-11-22 21:36  2%     ` Dmitry A. Kazakov
2020-01-25 21:52     GNATCOLL-Mmap example Bob Goddard
2020-01-28  8:25     ` Dmitry A. Kazakov
2020-01-28 18:53  2%   ` Bob Goddard
2020-03-16 18:51     Good/best way to enforce library-level instantiation a generic package Vincent Marciante
2020-03-17  1:21  2% ` Randy Brukardt
2020-03-17 11:21  1%   ` Jeffrey R. Carter
2020-03-18  1:03  0%     ` Randy Brukardt
2020-03-18  9:23  0%       ` Jeffrey R. Carter
2020-03-20 20:37  0%         ` Randy Brukardt
2020-04-03 22:48     Proposal: Auto-allocation of Indefinite Objects Stephen Davies
2020-04-03 23:45  2% ` Stephen Leake
2020-04-04 10:54  0%   ` Jeffrey R. Carter
2020-07-27  7:47     ` Yannick Moy
2020-07-27 17:48       ` Brian Drummond
2020-07-27 20:31  2%     ` Jeffrey R. Carter
2020-04-14  7:15     Put the access value ldries46
2020-04-14  7:42     ` J-P. Rosen
2020-04-20 23:02  2%   ` Robert A Duff
2020-04-20 15:24  1% Image attribute (yet again) Stephen Davies
2020-07-23 15:48     Unable to use "Find all references" with GPS CE 2020 !? Jérôme Haguet
2020-07-23 17:33     ` gautier_niouzes
2020-08-26 14:47       ` Jérôme Haguet
2020-08-28 10:35  1%     ` Jérôme Haguet
2021-06-18 11:02  0%       ` Jérôme Haguet
2020-09-11 10:37     Visibility issue Daniel
2020-09-17 21:47  1% ` Shark8
2020-12-02 22:47  1% Advent of Code day 2 Stephen Leake
2020-12-06  8:39  1% Advent of Code Day 6 John Perry
2020-12-06 11:07  0% ` Jeffrey R. Carter
2020-12-28  9:44     Messing with access types Marek
2020-12-28 10:14     ` Dmitry A. Kazakov
2020-12-28 11:43       ` Marek
2020-12-28 13:56         ` Dmitry A. Kazakov
2020-12-28 18:56           ` Marek
2020-12-28 19:53  1%         ` Dmitry A. Kazakov
2021-01-05 11:04     Lower bounds of Strings Stephen Davies
2021-01-05 11:57  1% ` Dmitry A. Kazakov
2021-01-06  3:08     ` Randy Brukardt
2021-01-06  9:13       ` Dmitry A. Kazakov
2021-01-07  0:17         ` Randy Brukardt
2021-01-07  9:57           ` Dmitry A. Kazakov
2021-01-07 22:03             ` Randy Brukardt
2021-01-08 17:23               ` Shark8
2021-01-09  2:31  1%             ` Randy Brukardt
2021-01-11 21:35  0%               ` Shark8
2021-01-14 11:38     ` AdaMagica
2021-01-15 10:24  2%   ` Stephen Davies
2021-01-15 11:48  1%     ` Jeffrey R. Carter
2021-01-27 19:59  2% Problem with unbounded string input Brian McGuinness
2021-02-08 11:22  1% [ANN] UXStrings package available (UXS_20210207) Blady
2021-02-11  8:19  2% ` Emmanuel Briot
2021-02-27  9:14  0%   ` Blady
2021-03-06 18:13  0%     ` Blady
2021-02-20 15:26     set_index and and end_of_file with just a stream reference Mehdi Saada
2021-02-20 16:04     ` Dmitry A. Kazakov
2021-02-20 16:22       ` Mehdi Saada
2021-02-20 16:30         ` Mehdi Saada
2021-02-20 17:59           ` Dmitry A. Kazakov
2021-02-20 19:08             ` Mehdi Saada
2021-02-23 17:21  2%           ` Shark8
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  4:55         ` Randy Brukardt
2021-03-15 14:16           ` Matt Borchers
2021-03-16  6:58  1%         ` Randy Brukardt
2021-04-17 21:45     Unchecked_Deallocation with tagged types DrPi
2021-04-18  8:21     ` Dmitry A. Kazakov
2021-04-18  8:46       ` Gautier write-only address
2021-04-18  9:09         ` Jeffrey R. Carter
2021-04-18 10:20           ` J-P. Rosen
2021-04-18 10:34             ` Dmitry A. Kazakov
2021-04-18 15:14               ` J-P. Rosen
2021-04-18 15:23                 ` Gautier write-only address
2021-04-18 15:53                   ` J-P. Rosen
2021-04-18 16:08                     ` Gautier write-only address
2022-04-16  5:00  1%                   ` Thomas
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                           ` 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  2%     ` Thomas
2021-04-19  9:08  2% ` Stephen Leake
2021-04-19 11:56  2%   ` Luke A. Guest
2021-04-19 12:13  0%     ` Luke A. Guest
2021-04-19 15:48  0%       ` DrPi
2021-04-19 12:52  0%     ` Dmitry A. Kazakov
2021-04-19 13:00           ` Luke A. Guest
2021-04-19 13:24             ` J-P. Rosen
2022-04-03 18:04  1%           ` Thomas
2022-04-06 18:57                 ` J-P. Rosen
2022-04-07  1:30  2%               ` Randy Brukardt
2022-04-08  8:56                     ` Simon Wright
2022-04-08  9:26                       ` Dmitry A. Kazakov
2022-04-08 19:19                         ` Simon Wright
2022-04-08 19:45                           ` Dmitry A. Kazakov
2022-04-09  4:05  1%                         ` Randy Brukardt
2022-04-09 10:27  0%                           ` DrPi
2022-04-10  5:58                                 ` Vadim Godunko
2022-04-12  6:13  2%                               ` Randy Brukardt
2021-04-20 19:06             ` Randy Brukardt
2022-04-03 18:37  1%           ` Thomas
2021-04-19 16:14  0%   ` DrPi
2021-04-19 13:18     ` Vadim Godunko
2022-04-03 16:51  1%   ` Thomas
2023-04-04  0:02  2%     ` Thomas
2021-06-19 18:28     XMLAda & unicode symbols 196...@googlemail.com
2021-06-19 21:24     ` Simon Wright
2021-06-20 17:10       ` 196...@googlemail.com
2021-06-21 15:26  1%     ` Simon Wright
2021-08-29  9:38  1% Postcondition on Strings.Maps.To_Sequence mockturtle
2021-09-01 21:07  0% ` Stephen Leake
2021-11-07 10:41     GNAT Community 2021 and PolyORB: Can't find source for a-sttebu.ali Frank Jørgen Jørgensen
2021-11-07 16:38  1% ` Jesper Quorning
2021-11-29 17:34     Empty String confusion; Positive and Natural Kevin Chadwick
2021-11-29 19:19     ` Niklas Holsti
2021-11-29 22:50       ` Kevin Chadwick
2021-11-30  8:29  2%     ` Simon Wright
2021-11-30  8:34  2%     ` Niklas Holsti
2021-11-30  7:40  2% ` ldries46
2021-11-30  8:21  1%   ` Simon Wright
2021-11-30 12:39  0%     ` ldries46
2021-12-02 18:17     String Buffer Kevin Chadwick
2021-12-02 20:51  2% ` Simon Wright
2021-12-22  5:57  2% Ada.Numerics.Big_Numbers.Big_Integer has a limit of 300 digits? Michael Ferguson
2022-01-05  0:54     Ok - WHAT are those "Maps.Identity" things ??? 1.AAC0831
2022-01-05  5:49  1% ` Rod Kay
2022-01-07  2:31  0%   ` 1.AAC0832
2022-01-07  4:14         ` Randy Brukardt
2022-01-10  5:13           ` 1.AAC0832
2022-01-10 10:19  1%         ` Marius Amado-Alves
2022-01-11  5:20  0%           ` 1.AAC0832
2022-01-07 11:48  2%     ` G.B.
2022-01-10  4:49  0%       ` 1.AAC0832
2022-01-05 13:01  1% ` Jeffrey R.Carter
2022-01-07  2:41  0%   ` 1.AAC0832
2022-01-07  9:49  2%     ` Jeffrey R.Carter
2022-01-10  4:46  0%       ` 1.AAC0832
2022-03-01 20:47  2% [ANN] UXStrings package available (UXS_20220226) Blady
2022-04-05 16:26     Ada_GUI AdaMagica
2022-04-05 19:30     ` Ada_GUI Jeffrey R.Carter
2022-04-06  7:21       ` Ada_GUI Jeffrey R.Carter
2022-04-06 15:29         ` Ada_GUI AdaMagica
2022-04-06 15:38           ` Ada_GUI Jeffrey R.Carter
2022-04-06 15:52             ` Ada_GUI AdaMagica
2022-04-08 14:05               ` Ada_GUI AdaMagica
2022-04-08 14:31                 ` Ada_GUI Jeffrey R.Carter
2022-04-08 20:56  1%               ` Ada_GUI Jeffrey R.Carter
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-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-16 11:33  1%           ` Björn Lundin
2022-09-16 15:00  0%             ` Marius Amado-Alves
2022-09-16 15:42  2%               ` Egil H H
2022-09-16 18:53  2%               ` Björn Lundin
2022-09-24  7:52     MS going to rust (and Linux too) Dmitry A. Kazakov
2022-09-24  8:50     ` Luke A. Guest
2022-09-24  9:13       ` Dmitry A. Kazakov
2022-09-24 11:41         ` G.B.
2022-09-24 13:05           ` Luke A. Guest
2022-09-24 17:49  1%         ` G.B.
2022-10-15 14:28  1% Gtk in ada using radiobuttons ldries46
2022-10-15 15:58     ` Ludovic Brenta
2022-10-16 20:09       ` Jeffrey R.Carter
2022-10-16 22:14         ` Ludovic Brenta
2022-10-17  8:18  1%       ` Jeffrey R.Carter
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  2%   ` Mace Ayres
2023-01-11 21:42  0%     ` Niklas Holsti
2023-02-22 16:34  2% wait does not perform as expected Daniel Gaudry
2023-05-05  3:36     [ANN] Release of UXStrings 0.5.0 Blady
2023-06-29  8:49     ` Vincent D.
2023-07-01 14:41  2%   ` Blady
2023-05-05  9:51     problemn with string'last Daniel Gaudry
2023-05-05 11:17     ` Jeffrey R.Carter
2023-05-05 16:28  1%   ` Manuel Gomez
2023-05-05 16:33  0%     ` Simon Wright
2023-05-05 18:18  0%       ` Manuel Gomez
2023-05-05 20:44  0%         ` Simon Wright
     [not found]     <13757589-8844-46ec-8d09-24b4bfd65a52n@googlegroups.com>
2023-05-15 10:41     ` GnatStudio 20230501 released Rod Kay
2023-05-15 13:58  1%   ` Jeffrey R.Carter
2023-07-14 19:17  1% Formal Package Compiler Differences Jeffrey R.Carter
2023-07-14 19:27  0% ` Jeffrey R.Carter
2023-08-13 16:16     Unifont static compiled and stack size Micah Waddoups
2023-08-14  8:07     ` Niklas Holsti
2023-08-14  8:31       ` Dmitry A. Kazakov
2023-08-14  9:25         ` Kevin Chadwick
2023-08-14  9:39  1%       ` Dmitry A. Kazakov
2023-08-27  5:18     [Ann] WinRt - version 3 AlexG
2023-09-03  9:07  2% ` AlexG
2023-09-04  9:19     project euler 26 CSYH (QAQ)
2023-09-04 14:23  1% ` Dmitry A. Kazakov
2024-01-14 11:05     String_Access in unbounded string handling? Blady
2024-01-14 11:17     ` Jeffrey R.Carter
2024-01-17  1:24  1%   ` Randy Brukardt
2024-01-17  9:54  0%     ` Blady
2024-01-17 13:34     ` Tucker Taft
2024-01-19  1:36  1%   ` Randy Brukardt
2024-01-30 15:53  0%     ` Blady

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