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: Ada and Unicode
  2021-04-19  8:29  7% ` Maxim Reznik
@ 2021-04-19  9:28  0%   ` DrPi
  0 siblings, 0 replies; 14+ results
From: DrPi @ 2021-04-19  9:28 UTC (permalink / raw)


Le 19/04/2021 à 10:29, Maxim Reznik a écrit :
> воскресенье, 18 апреля 2021 г. в 01:03:14 UTC+3, DrPi:
>>
>> Any way to use source code encoded in UTF-8 ?
> 
> Yes, with GNAT just use "-gnatW8" for compiler flag (in command line or your project file):
> 
> --  main.adb:
> with Ada.Wide_Wide_Text_IO;
> 
> procedure Main is
>     Привет : constant Wide_Wide_String := "Привет";
> begin
>     Ada.Wide_Wide_Text_IO.Put_Line (Привет);
> end Main;
> 
> $ gprbuild -gnatW8 main.adb
> $ ./main
> Привет
> 
> 
>> In some languages, it is possible to set a tag at the beginning of the
>> source file to direct the compiler which encoding to use.
> 
> You can do this with putting the Wide_Character_Encoding pragma (This is a GNAT specific pragma) at the top of the file. Take a look:
> 
> --  main.adb:
> pragma Wide_Character_Encoding (UTF8);
> 
> with Ada.Wide_Wide_Text_IO;
> 
> procedure Main is
>     Привет : constant Wide_Wide_String := "Привет";
> begin
>     Ada.Wide_Wide_Text_IO.Put_Line (Привет);
> end Main;
> 
> $ gprbuild main.adb
> $ ./main
> Привет
> 
Wide and Wide_Wide characters and UTF-8 are two distinct things.
Wide and Wide_Wide characters are supposed to contain Unicode code 
points (Unicode characters).
UTF-8 is a stream of bytes, the encoding of Wide or Wide_Wide characters.
What's the purpose of "pragma Wide_Character_Encoding (UTF8);" ?

> 
> 
>> What's the way to manage Unicode correctly ?
>>
> 
> You can use Wide_Wide_String and Unbounded_Wide_Wide_String type to process Unicode strings. But this is not very handy. I use the Matreshka library for Unicode strings. It has a lot of features (regexp, string vectors, XML, JSON, databases, Web Servlets, template engine, etc.). URL: https://forge.ada-ru.org/matreshka

Thanks
> 
>> Regards,
>> Nicolas

^ permalink raw reply	[relevance 0%]

* Re: Ada and Unicode
  @ 2021-04-19  8:29  7% ` Maxim Reznik
  2021-04-19  9:28  0%   ` DrPi
  0 siblings, 1 reply; 14+ results
From: Maxim Reznik @ 2021-04-19  8:29 UTC (permalink / raw)


воскресенье, 18 апреля 2021 г. в 01:03:14 UTC+3, DrPi:
> 
> Any way to use source code encoded in UTF-8 ? 

Yes, with GNAT just use "-gnatW8" for compiler flag (in command line or your project file):

--  main.adb:
with Ada.Wide_Wide_Text_IO;

procedure Main is
   Привет : constant Wide_Wide_String := "Привет";
begin
   Ada.Wide_Wide_Text_IO.Put_Line (Привет);
end Main;

$ gprbuild -gnatW8 main.adb
$ ./main 
Привет


> In some languages, it is possible to set a tag at the beginning of the 
> source file to direct the compiler which encoding to use. 

You can do this with putting the Wide_Character_Encoding pragma (This is a GNAT specific pragma) at the top of the file. Take a look:

--  main.adb:
pragma Wide_Character_Encoding (UTF8);

with Ada.Wide_Wide_Text_IO;

procedure Main is
   Привет : constant Wide_Wide_String := "Привет";
begin
   Ada.Wide_Wide_Text_IO.Put_Line (Привет);
end Main;

$ gprbuild main.adb
$ ./main 
Привет



> What's the way to manage Unicode correctly ? 
> 

You can use Wide_Wide_String and Unbounded_Wide_Wide_String type to process Unicode strings. But this is not very handy. I use the Matreshka library for Unicode strings. It has a lot of features (regexp, string vectors, XML, JSON, databases, Web Servlets, template engine, etc.). URL: https://forge.ada-ru.org/matreshka

> Regards, 
> Nicolas

^ permalink raw reply	[relevance 7%]

* Re: Type inference with String_Literal.
  2020-12-26  9:12  5% Type inference with String_Literal Blady
@ 2020-12-27  5:26  0% ` Randy Brukardt
  0 siblings, 0 replies; 14+ results
From: Randy Brukardt @ 2020-12-27  5:26 UTC (permalink / raw)


Well, the rules for conditional expressions are separate from the rules for 
literals, so it certainly is possible for them to get different results.

However, it appears to me that 4.5.7(13/3) applies to your examples on line 
18 (the expression is "expected" to be of type My_Type1) and on line 19 
(here the expression "shall resolve to" My_Type1). If that rule applies, 
then the dependent expressions should be resolved individually using 
My_Type1 - which obviously should work. So I think this is a bug in GNAT, 
although I'm not 100% certain (if the rule doesn't apply, then there isn't 
enough context to resolve the expression -- but I don't know why the rule 
wouldn't apply).

                              Randy.

"Blady" <p.p11@orange.fr> wrote in message 
news:rs6uql$uj1$1@gioia.aioe.org...
> Hello,
>
> In the following test program, line 16 the string literal is correctly 
> inferred to Wide_Wide_String and line 17 the string literal is correctly 
> inferred to My_Type1 as aspect String_Literal is defined line 7 for this 
> type.
> But line 18, GNAT reports a type match error in a "if expression" with 
> string literals.
> String literal in the "if expression" has to qualified by My_Type1 as in 
> line 20:
>
>     1. with Ada.Wide_Wide_Text_IO;
>      2. procedure Test_20201225_str_lit is
>      3.
>      4.    type My_Type1 (Length : Natural) is record
>      5.       Value : Wide_Wide_String (1 .. Length);
>      6.    end record with
>      7.       String_Literal => From_String1;
>      8.    function From_String1 (Value : Wide_Wide_String) return 
> My_Type1 is ((Length => Value'Length, Value => Value));
>      9.    procedure Print1 (Self : My_Type1) is
>     10.    begin
>     11.       Ada.Wide_Wide_Text_IO.Put_Line (Self.Value);
>     12.    end Print1;
>     13.
>     14.    function Test return Boolean is (True);
>     15.
>     16.    S : Wide_Wide_String := (if Test then "test0" else "");
>     17.    MV0 : My_Type1 := "test0";
>     18.    MV1 : My_Type1 := (if Test then "test1" else "");
>                               |
>         >>> expected type "My_Type1" defined at line 4
>         >>> found a string type
>
>     19.    MV2 : My_Type1 := My_Type1'(if Test then "test2" else "");
>                                        |
>         >>> expected type "My_Type1" defined at line 4
>         >>> found a string type
>
>     20.    MV3 : My_Type1 := (if Test then My_Type1'("test3") else "");
>     21.
>     22. begin
>     23.    Print1 ("Test ""string""");
>     24.    Print1 ("88");
>     25.    Print1 (MV1);
>     26.    Print1 (MV2);
>     27. end Test_20201225_str_lit;
>
> Shouldn't GNAT set the type My_Type1 for the string literal in line 18 as 
> it does line 17?
>
> Thanks, Pascal.
> 


^ permalink raw reply	[relevance 0%]

* Type inference with String_Literal.
@ 2020-12-26  9:12  5% Blady
  2020-12-27  5:26  0% ` Randy Brukardt
  0 siblings, 1 reply; 14+ results
From: Blady @ 2020-12-26  9:12 UTC (permalink / raw)


Hello,

In the following test program, line 16 the string literal is correctly 
inferred to Wide_Wide_String and line 17 the string literal is correctly 
inferred to My_Type1 as aspect String_Literal is defined line 7 for this 
type.
But line 18, GNAT reports a type match error in a "if expression" with 
string literals.
String literal in the "if expression" has to qualified by My_Type1 as in 
line 20:

     1. with Ada.Wide_Wide_Text_IO;
      2. procedure Test_20201225_str_lit is
      3.
      4.    type My_Type1 (Length : Natural) is record
      5.       Value : Wide_Wide_String (1 .. Length);
      6.    end record with
      7.       String_Literal => From_String1;
      8.    function From_String1 (Value : Wide_Wide_String) return 
My_Type1 is ((Length => Value'Length, Value => Value));
      9.    procedure Print1 (Self : My_Type1) is
     10.    begin
     11.       Ada.Wide_Wide_Text_IO.Put_Line (Self.Value);
     12.    end Print1;
     13.
     14.    function Test return Boolean is (True);
     15.
     16.    S : Wide_Wide_String := (if Test then "test0" else "");
     17.    MV0 : My_Type1 := "test0";
     18.    MV1 : My_Type1 := (if Test then "test1" else "");
                               |
         >>> expected type "My_Type1" defined at line 4
         >>> found a string type

     19.    MV2 : My_Type1 := My_Type1'(if Test then "test2" else "");
                                        |
         >>> expected type "My_Type1" defined at line 4
         >>> found a string type

     20.    MV3 : My_Type1 := (if Test then My_Type1'("test3") else "");
     21.
     22. begin
     23.    Print1 ("Test ""string""");
     24.    Print1 ("88");
     25.    Print1 (MV1);
     26.    Print1 (MV2);
     27. end Test_20201225_str_lit;

Shouldn't GNAT set the type My_Type1 for the string literal in line 18 
as it does line 17?

Thanks, Pascal.

^ permalink raw reply	[relevance 5%]

* Re: Ada.Text_IO.File_Type object with user defined Get and Put subprograms.
  @ 2020-08-01 17:23  6%     ` Shark8
  0 siblings, 0 replies; 14+ results
From: Shark8 @ 2020-08-01 17:23 UTC (permalink / raw)


On Saturday, August 1, 2020 at 1:46:24 AM UTC-6, Blady wrote:
> Le 31/07/2020 à 20:19, Shark8 a écrit :
> > On Thursday, July 30, 2020 at 2:21:10 PM UTC-6, Blady wrote:
> >> Hello,
> >>
> >> Given a legacy code calling many Put_Line from Ada.Text_IO which works
> >> nice in a Terminal, I want to add a mode which sends these outputs to
> >> another process without changing the legacy code too much.
> >> And I want to keep the Terminal mode.
> >>
> >> Is there a way to create a File_Type object (from Ada.Text_IO) which
> >> would have user defined Get and Put subprograms instead of the
> >> predefined ones of the file system?
> > 
> > Kind of; I have a generic interface-package that I use for dealing with text-io and its permutations.
> > 
> > I just published it on github: https://github.com/OneWingedShark/EVIL/tree/master/src
> > It's part of what's intended to be a verified, general purpose library -- though I'm still teaching myself SPARK -- and so I've only published the file-interfacing utility portion.
> 
> Have you an example of how to use it?

with
--Ada.Wide_Wide_Text_IO.Text_Streams;
Ada.Text_IO.Text_Streams;

use
--Ada.Wide_Wide_Text_IO;
Ada.Text_IO;

Package Example is
   -- Bring in the Text-stream namespace.
   Use Ada.Text_IO.Text_Streams;
   
   -- Instantiate EVIL.Util.Files.
   Package Uniform_IO is New EVIL.Util.Files
      (
        Character	=> Character,
        String		=> String,
	File_Type	=> Ada.Text_IO.File_Type,
	File_Mode	=> Ada.Text_IO.File_Mode,
	Stream_Access	=> Ada.Text_IO.Text_Streams.Stream_Access
      );
  File : Uniform_IO.File:= Uniform_IO.Create( "Test.tmp", Ada.Text_IO.Out_File );
Begin

   Declare
      Test_String : Constant String := "-TESTING!!-";
   Begin
      String'Write( Test_File.Stream, Test_String );
   End;

End Example;

I don't have it implemented yet, but I plan on doing a "stream splitter" so you could say, use one stream to write to both the file and Standard_IO.

> >> Thus in my case, I will create a custom File_Type object My_Output with
> >> the user define Put which will send the lines to the other process and
> >> then I will call "Set_Output (My_Ouput);" before the legacy code.
> > 
> > It might be a better idea to have them as TASKs and in a single program, selecting and/or creating/executing the proper task ass needed. (If you have access to the legacy-program sources, you could wrap them or their interfaces in the TASK.)
> 
> Yes, I'll try in that way.

It'll probably save you some headache; I've found tasks really good at timed/cyclic events.

^ permalink raw reply	[relevance 6%]

* Have I found an error in the index of the ARM?
@ 2020-02-27 22:54  5% mgr
  0 siblings, 0 replies; 14+ results
From: mgr @ 2020-02-27 22:54 UTC (permalink / raw)


Hello,

While generating some stubs (wiki draft) for the Ada Programming 
wikibook, I've found an inconsistency that ultimately comes from the 
index of Ada 2005 and 2012 Reference Manual.

The index in Wikibooks [1] was probably derived from the RM index [2]. I 
generated the stubs from the actual package names provided by GNAT 
implementation. As can be seen in the Wikibooks index, some  links are 
broken, despite having generated stubs for all the Ada children. The 
index in Wikibooks follows the RM index:

Ada.Wide_Text_IO.Bounded_IO   A.11(4/3)
Ada.Wide_Text_IO.Unbounded_IO   A.11(5/3)

Ada.Wide_Wide_Text_IO.Bounded_IO   A.11(4/3)
Ada.Wide_Wide_Text_IO.Unbounded_IO   A.11(5/3)

But in A.11 [3] the package names repeat Wide[_Wide] at the 
grandchildren level:
4/3
The specification of package Wide_Text_IO.Wide_Bounded_IO is the same as

5/3
The specification of package Wide_Text_IO.Wide_Unbounded_IO is the same

So generated stubs are not linked to the index. I guess the problem is 
in the RM index, because implementors have follow the letter of A.11.


[1] https://en.wikibooks.org/wiki/Ada_Programming/Libraries/Ada
[2] http://www.ada-auth.org/standards/12rm/html/RM-0-4.html
[3] http://www.ada-auth.org/standards/12rm/html/RM-A-11.html


^ permalink raw reply	[relevance 5%]

* Re: win32 interfacing check (SetClipboardData)
  @ 2017-09-02  9:38  3%           ` Xavier Petit
  0 siblings, 0 replies; 14+ results
From: Xavier Petit @ 2017-09-02  9:38 UTC (permalink / raw)


Le 01/09/2017 à 15:10, Dmitry A. Kazakov a écrit :
> On 01/09/2017 14:51, Xavier Petit wrote:
>> Thanks but even with Set_Clipboard (Ada.[Wide_]Wide_Text_IO.Get_Line); 
>> I was getting weird clipboard text without -gnatW8 flag.
> 
> But these are not UTF-8! They are UCS-2 and UCS-4.
Yes but having a look at :
https://gcc.gnu.org/onlinedocs/gnat_ugn/Character-Set-Control.html
https://gcc.gnu.org/onlinedocs/gnat_ugn/Wide_005fCharacter-Encodings.html
https://gcc.gnu.org/onlinedocs/gnat_ugn/Wide_005fWide_005fCharacter-Encodings.html

It appears that without the -gnatW8 flag, "Brackets Coding" is the default :
- “In this encoding, a wide character is represented by the following 
eight character sequence: [...]”
- “In this encoding, a wide wide character is represented by the 
following ten or twelve byte character sequence”

...and with the flag, "UTF-8 Coding" is used : “A wide character is 
represented using UCS Transformation Format 8 (UTF-8)”

I think I'm still missing something because one thing is sure :
Ada.Strings.UTF_Encoding.Wide_Wide_String.Encode 
(Ada.Wide_Wide_Text_IO.Get_Line) doesn't not work without the UTF-8 flag...

 From UTF_Encoding.Wide_Wide_Strings package :
“
The encoding routines take a Wide_Wide_String as input and encode the
result using the specified UTF encoding method.
Encode Wide_Wide_String using UTF-8 encoding
Encode Wide_Wide_String using UTF_16 encoding
”
So it means Get_Line returns a Wide_Wide_String without the USC-4 
encoding ? because Encode doesn't return UTF-(8/16) encoding without the 
flag.

> ([Wide_]Wide_Text_IO should never be used, there is no single case one 
> would need these.)
yeah I'm gonna try not to use the Wide_Wide packages, one thing I liked 
with Wide_Wide_String is the correct 'Length attribute.

> If you have a UTF-8 encoded file (e.g. created using Notepad++, saved 
> without BOM), you should use Ada.Streams.Stream_IO, best in binary mode 
> if you are using GNAT.
> 
> You will have to detect line ends manually, but at least there will be 
> guaranty that the run-time does not mangle anything.
Ok, “binary mode”, do you mean using Stream_Element_Array ?

> If you are using Windows calls with the "W" suffix, then all strings 
> there are already UTF-16 and you don't need to convert anything.
Ok, if I stay with win32 functions, I'll get only UTF-16, if I mess with 
external text sources (like files) or Ada standard, I'll deal with 
others text encoding formats like UTF-8, UCS-2, etc...

^ permalink raw reply	[relevance 3%]

* Re: Running a preprocessor from GPS?
  @ 2015-07-30 22:53  4%                         ` Jeffrey R. Carter
  0 siblings, 0 replies; 14+ results
From: Jeffrey R. Carter @ 2015-07-30 22:53 UTC (permalink / raw)


On 07/30/2015 12:54 PM, EGarrulo wrote:
> 
> I had already explained in this discussion why I think that the "Printf"
> solution is preferable:
> 
>   Thanks to its format string, "printf" lets you see
>   at a glance what the output will look like.  On the contrary,
>   solutions in Ada -- that involve more than simple string
>   concatenation -- tend to obscure what the final result will look
>   like, and are cumbersome both to write and to read.
> 
>   -- 
> 
>   Now, multiply this for all the times that your program needs
>   to print formatted text...  Not to mention that the order of the
>   arguments is hard-coded in the valid Ada snippet, whilst you could
>   need a different order to support formatted output in different
>   languages.

Your Print as described at that point did not have any support for different
languages without changing the order of the arguments, either. So again you
changed the problem. I can do the same thing: take your Printf with its format
string of type String and numbered placeholders and show how it handles Hebrew.

> If I don't repeat my arguments, it is because doing so would be redundant, not
> because I am playing fancy tricks to win an argument.  So... have you got an
> alternative to propose, or do you agree that "Printf" is a more flexible
> approach?  Before you reply, I am adding that I have already proposed a
> specification of Printf that takes an array of strings as the arguments to its
> format string, so that formatting can be done outside, and be customized for
> new types.  Actually, I think that such a function should become
> standard, because it would integrate well with existing functions (like
> To_Picture).

Printf is a bad idea since humans are bad at mentally parsing things like the
format string and bad at counting things such as the position of an argument in
the argument list, and doing both at once while also trying to match the
placeholders in the format string with the arguments tends to be error-prone.

If formatting can be done "outside", then it's reasonable for such formatting to
result in the entire text to be output:

Ada.Wide_Wide_Text_IO.Put_Line
   (Item =>
       Internationalized (Who_Won, Language, (Surname, Image (Amount) ) ) );

-- 
Jeff Carter
"Pray that there's intelligent life somewhere up in
space, 'cause there's bugger all down here on earth."
Monty Python's Meaning of Life
61

^ permalink raw reply	[relevance 4%]

* Re: Is this expected behavior or not
  @ 2013-03-16 16:55  3%                                           ` Shark8
  0 siblings, 0 replies; 14+ results
From: Shark8 @ 2013-03-16 16:55 UTC (permalink / raw)
  Cc: mailbox

On Saturday, March 16, 2013 1:41:27 AM UTC-6, Dmitry A. Kazakov wrote:
> On Fri, 15 Mar 2013 22:52:02 -0700 (PDT), Shark8 wrote:
> 
> > True; but there could be some more interesting cases, say, for Ada 2020.
> > Something like:
> > 
> > Abstract Type UNIVERSAL_STRING(Element : UNIVERSAL_CHARACTER) is 
> >     Array(Positive Range <>) of Element'Type;
> 
> That would not work. I presume that here you want to create a root type for
> the class of string types and get at the members of the class (specific
> types like Wide_String) using a constraint. The problem is that string
> types must have different representations. The mechanism of constraining
> does not support. 

Kind of, but not really; I'm thinking a sort of combination of generics and classes (in the general sense, not the OOP-sense): a way to specify a general behavior for a type-class. (i.e. having the ability to fully-specify things like attributes [not really shown in this example].)

> Thus either subtypes will have same representation or you
> won't have a class.

I'm thinking of it more in the terms of generic operations: independent of representation.

> Another problem is that string types must have more 
> than one interface to deal with UTF-8 etc. An UTF-8 string is *both* an
> array of Wide_Wide_Character (= Unicode code points) and an array or
> sequence of Character (octets).

Ah, things get tricky here; Unicode is kind of a bear when you consider 'characters' because its codepoints aren't necessarily characters. An example would be the so-called "combining characters" which you can use for things like accents or ZALGO-text. (See these, respectively: http://en.wikipedia.org/wiki/Combining_character and, http://eeemo.net/ )

An important implication of this is that string search/manipulation becomes MUCH more complex. (`+a = à) means that you now have to search for multiple possibilities when your target is "à" -> the single-glyph code-point, or the combining-character points... and that's not taking into consideration whether you should consider a & à & (a+diacritic) to be the same or unique entities -- and casing is another combinatorial factor.

It would be a big mistake to assume character = code-point when dealing with Unicode.

> An UTF-16 string is an array of Wide_Wide_Character and an array of Wide_String.

UTF-16 is perhaps the worst possible encoding you can have for Unicode. With UTF-8 you don't need to worry about byte-order (everything's sequential) and with UTF-32 you don't need to decode the information (each element *IS* a code-point)... but UTF-16 offers neither of these.

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

I guess what I'm trying to say is that if we did it right, we could modify/expand the type-system so that something like UNIVERSAL_INTEGER could be made/explicitly-specified. (And if done extremely well, something like UNIVERSAL_STRING where perhaps the only thing differentiating the strings would be the 'instantiation' with their proper character-type* and manipulation-functions.) -- GNAT already has the 'Universal_Literal_String which works in either of the following lines:

Ada.Wide_Wide_Text_IO.Put_Line( Ada.Numerics.Pi'Universal_Literal_String )
Ada.Text_IO.Put_Line( Ada.Numerics.Pi'Universal_Literal_String )

In any case; I think it worth considering not just outward/downward expansion of the language, but inward/upward [unification] as well.



^ permalink raw reply	[relevance 3%]

* Re: Why is not Stream_Access defined Ada.Streams ?
  2010-05-07  1:02  5% Why is not Stream_Access defined Ada.Streams ? Yannick Duchêne (Hibou57)
@ 2010-05-07  2:24  0% ` Randy Brukardt
  0 siblings, 0 replies; 14+ results
From: Randy Brukardt @ 2010-05-07  2:24 UTC (permalink / raw)


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

"Yannick Duch�ne (Hibou57)" <yannick_duchene@yahoo.fr> wrote in message 
news:op.vca852lexmjfy8@garhos...
> Hi all and Hi others as well,
>
> My dirty stuff of the day : why is Stream_Access not defined once a time 
> in Ada.Streams and is instead defined elsewhere multiple times, like in 
> Ada.Streams.Stream_IO, Ada.Text_IO.Text_Streams, 
> Ada.Wide_Text_IO.Text_Streams and Ada.Wide_Wide_Text_IO.Text_Streams ?
>
> Isn't it funny design ?

Ada 95 didn't have anonymous access returns, so a named type had to be 
defined. I suspect that there was no intent that it be used for anything 
other than defining the result of these functions -- and there was no intent 
that that result be stored: just directly dereferenced and passed to a 
stream attribute.

If we were writing it today, I'm pretty sure that no named type would be 
used at all. But making a change like that now would be incompatible.

                                Randy.





^ permalink raw reply	[relevance 0%]

* Why is not Stream_Access defined Ada.Streams ?
@ 2010-05-07  1:02  5% Yannick Duchêne (Hibou57)
  2010-05-07  2:24  0% ` Randy Brukardt
  0 siblings, 1 reply; 14+ results
From: Yannick Duchêne (Hibou57) @ 2010-05-07  1:02 UTC (permalink / raw)


Hi all and Hi others as well,

My dirty stuff of the day : why is Stream_Access not defined once a time  
in Ada.Streams and is instead defined elsewhere multiple times, like in  
Ada.Streams.Stream_IO, Ada.Text_IO.Text_Streams,  
Ada.Wide_Text_IO.Text_Streams and Ada.Wide_Wide_Text_IO.Text_Streams ?

Isn't it funny design ?

-- 
No-no, this isn't an oops ...or I hope (TM) - Don't blame me... I'm just  
not lucky



^ permalink raw reply	[relevance 5%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  2008-03-09 12:40  6%     ` Vadim Godunko
  2008-03-11 13:58  0%       ` george.priv
@ 2008-03-11 22:09  0%       ` gpriv
  1 sibling, 0 replies; 14+ results
From: gpriv @ 2008-03-11 22:09 UTC (permalink / raw)


On Mar 9, 8:40 am, Vadim Godunko <vgodu...@gmail.com> wrote:
> On Mar 9, 11:20 am, Pascal Obry <pas...@obry.net> wrote:
>
> > I prefer using Ada, even losing 10% performance initially.
>
> I usually have 4+ times penalty for Ada program with controlled object
> for memory allocation/deallocation control and protected objects for
> thread safe operations in comparison with equivalent C++ program. :-(
>
> #include <QString>
> #include <QTime>
>
> void test(unsigned length)
> {
>         uint x[length];
>         QString a[1024];
>         QString b[1024];
>         QTime timer;
>
>         timer.start();
>
>         for (int i = 0; i < 1024; i++)
>         {
>                 a[i] = QString::fromUcs4(x, length);
>         }
>
>         qDebug("Init %d %lf", length, (double)timer.elapsed() / 1000);
>
>         timer.restart();
>
>         for (int i = 0; i < 1000; i++)
>         {
>                 if (i % 2)
>                 {
>                         for (int j = 0; j < 1024; j++)
>                         {
>                                 a[j] = b[j];
>                         }
>                 }
>                 else
>                 {
>                         for (int j = 0; j < 1024; j++)
>                         {
>                                 b[j] = a[j];
>                         }
>                 }
>         }
>
>         qDebug("Copy %d %lf", length, (double)timer.elapsed() / 1000);
>
> }
>
> int main()
> {
>         test (128);
>         test (1024);
>         return 0;
>
> }
>
> with Ada.Calendar;
> with Ada.Wide_Wide_Text_IO;
>
> with League.Strings;
>
> procedure Speed_Test_League is
>
>    type Universal_String_Array is
>      array (Positive range <>) of League.Strings.Universal_String;
>
>    procedure Test (Length : in Positive);
>
>    procedure Test (Length : in Positive) is
>       use type Ada.Calendar.Time;
>
>       X : constant Wide_Wide_String (1 .. Length) := (others => ' ');
>       A : Universal_String_Array (1 .. 1_024);
>       B : Universal_String_Array (1 .. 1_024);
>       S : Ada.Calendar.Time;
>
>    begin
>       S := Ada.Calendar.Clock;
>
>       for J in A'Range loop
>          A (J) := League.Strings.To_Universal_String (X);
>       end loop;
>
>       Ada.Wide_Wide_Text_IO.Put_Line
>        ("Init"
>           & Positive'Wide_Wide_Image (Length)
>           & Duration'Wide_Wide_Image (Ada.Calendar.Clock - S));
>
>       S := Ada.Calendar.Clock;
>
>       for J in 1 .. 1_000 loop
>          if J mod 2 = 1 then
>             B := A;
>
>          else
>             A := B;
>          end if;
>       end loop;
>
>       Ada.Wide_Wide_Text_IO.Put_Line
>        ("Copy"
>           & Positive'Wide_Wide_Image (Length)
>           & Duration'Wide_Wide_Image (Ada.Calendar.Clock - S));
>    end Test;
>
> begin
>    Test (128);
>    Test (1_024);
> end Speed_Test_League;

Does QString has vtable?




^ permalink raw reply	[relevance 0%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  2008-03-09 12:40  6%     ` Vadim Godunko
@ 2008-03-11 13:58  0%       ` george.priv
  2008-03-11 22:09  0%       ` gpriv
  1 sibling, 0 replies; 14+ results
From: george.priv @ 2008-03-11 13:58 UTC (permalink / raw)


On Mar 9, 8:40 am, Vadim Godunko <vgodu...@gmail.com> wrote:
> On Mar 9, 11:20 am, Pascal Obry <pas...@obry.net> wrote:
>
> > I prefer using Ada, even losing 10% performance initially.
>
> I usually have 4+ times penalty for Ada program with controlled object
> for memory allocation/deallocation control and protected objects for
> thread safe operations in comparison with equivalent C++ program. :-(
>
> #include <QString>
> #include <QTime>
>
> void test(unsigned length)
> {
>         uint x[length];
>         QString a[1024];
>         QString b[1024];
>         QTime timer;
>
>         timer.start();
>
>         for (int i = 0; i < 1024; i++)
>         {
>                 a[i] = QString::fromUcs4(x, length);
>         }
>
>         qDebug("Init %d %lf", length, (double)timer.elapsed() / 1000);
>
>         timer.restart();
>
>         for (int i = 0; i < 1000; i++)
>         {
>                 if (i % 2)
>                 {
>                         for (int j = 0; j < 1024; j++)
>                         {
>                                 a[j] = b[j];
>                         }
>                 }
>                 else
>                 {
>                         for (int j = 0; j < 1024; j++)
>                         {
>                                 b[j] = a[j];
>                         }
>                 }
>         }
>
>         qDebug("Copy %d %lf", length, (double)timer.elapsed() / 1000);
>
> }
>
> int main()
> {
>         test (128);
>         test (1024);
>         return 0;
>
> }
>
> with Ada.Calendar;
> with Ada.Wide_Wide_Text_IO;
>
> with League.Strings;
>
> procedure Speed_Test_League is
>
>    type Universal_String_Array is
>      array (Positive range <>) of League.Strings.Universal_String;
>
>    procedure Test (Length : in Positive);
>
>    procedure Test (Length : in Positive) is
>       use type Ada.Calendar.Time;
>
>       X : constant Wide_Wide_String (1 .. Length) := (others => ' ');
>       A : Universal_String_Array (1 .. 1_024);
>       B : Universal_String_Array (1 .. 1_024);
>       S : Ada.Calendar.Time;
>
>    begin
>       S := Ada.Calendar.Clock;
>
>       for J in A'Range loop
>          A (J) := League.Strings.To_Universal_String (X);
>       end loop;
>
>       Ada.Wide_Wide_Text_IO.Put_Line
>        ("Init"
>           & Positive'Wide_Wide_Image (Length)
>           & Duration'Wide_Wide_Image (Ada.Calendar.Clock - S));
>
>       S := Ada.Calendar.Clock;
>
>       for J in 1 .. 1_000 loop
>          if J mod 2 = 1 then
>             B := A;
>
>          else
>             A := B;
>          end if;
>       end loop;
>
>       Ada.Wide_Wide_Text_IO.Put_Line
>        ("Copy"
>           & Positive'Wide_Wide_Image (Length)
>           & Duration'Wide_Wide_Image (Ada.Calendar.Clock - S));
>    end Test;
>
> begin
>    Test (128);
>    Test (1_024);
> end Speed_Test_League;

This code is not multi-core safe.  Are you sure that QString has
Vtab?  If not then comparison will be unfair.



^ permalink raw reply	[relevance 0%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  @ 2008-03-09 12:40  6%     ` Vadim Godunko
  2008-03-11 13:58  0%       ` george.priv
  2008-03-11 22:09  0%       ` gpriv
  0 siblings, 2 replies; 14+ results
From: Vadim Godunko @ 2008-03-09 12:40 UTC (permalink / raw)


On Mar 9, 11:20 am, Pascal Obry <pas...@obry.net> wrote:
>
> I prefer using Ada, even losing 10% performance initially.
I usually have 4+ times penalty for Ada program with controlled object
for memory allocation/deallocation control and protected objects for
thread safe operations in comparison with equivalent C++ program. :-(

#include <QString>
#include <QTime>

void test(unsigned length)
{
        uint x[length];
        QString a[1024];
        QString b[1024];
        QTime timer;

        timer.start();

        for (int i = 0; i < 1024; i++)
        {
                a[i] = QString::fromUcs4(x, length);
        }

        qDebug("Init %d %lf", length, (double)timer.elapsed() / 1000);

        timer.restart();

        for (int i = 0; i < 1000; i++)
        {
                if (i % 2)
                {
                        for (int j = 0; j < 1024; j++)
                        {
                                a[j] = b[j];
                        }
                }
                else
                {
                        for (int j = 0; j < 1024; j++)
                        {
                                b[j] = a[j];
                        }
                }
        }

        qDebug("Copy %d %lf", length, (double)timer.elapsed() / 1000);
}

int main()
{
        test (128);
        test (1024);
        return 0;
}

with Ada.Calendar;
with Ada.Wide_Wide_Text_IO;

with League.Strings;

procedure Speed_Test_League is

   type Universal_String_Array is
     array (Positive range <>) of League.Strings.Universal_String;

   procedure Test (Length : in Positive);

   procedure Test (Length : in Positive) is
      use type Ada.Calendar.Time;

      X : constant Wide_Wide_String (1 .. Length) := (others => ' ');
      A : Universal_String_Array (1 .. 1_024);
      B : Universal_String_Array (1 .. 1_024);
      S : Ada.Calendar.Time;

   begin
      S := Ada.Calendar.Clock;

      for J in A'Range loop
         A (J) := League.Strings.To_Universal_String (X);
      end loop;

      Ada.Wide_Wide_Text_IO.Put_Line
       ("Init"
          & Positive'Wide_Wide_Image (Length)
          & Duration'Wide_Wide_Image (Ada.Calendar.Clock - S));

      S := Ada.Calendar.Clock;

      for J in 1 .. 1_000 loop
         if J mod 2 = 1 then
            B := A;

         else
            A := B;
         end if;
      end loop;

      Ada.Wide_Wide_Text_IO.Put_Line
       ("Copy"
          & Positive'Wide_Wide_Image (Length)
          & Duration'Wide_Wide_Image (Ada.Calendar.Clock - S));
   end Test;

begin
   Test (128);
   Test (1_024);
end Speed_Test_League;



^ permalink raw reply	[relevance 6%]

Results 1-14 of 14 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2008-03-08  6:04     Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing! ME
2008-03-08 22:11     ` Maciej Sobczak
2008-03-09  8:20       ` Pascal Obry
2008-03-09 12:40  6%     ` Vadim Godunko
2008-03-11 13:58  0%       ` george.priv
2008-03-11 22:09  0%       ` gpriv
2010-05-07  1:02  5% Why is not Stream_Access defined Ada.Streams ? Yannick Duchêne (Hibou57)
2010-05-07  2:24  0% ` Randy Brukardt
2013-03-11 19:42     Is this expected behavior or not Anh Vo
2013-03-12  9:27     ` Dmitry A. Kazakov
2013-03-12 17:19       ` Robert A Duff
2013-03-12 17:42         ` Dmitry A. Kazakov
2013-03-12 18:04           ` Georg Bauhaus
2013-03-12 18:21             ` Dmitry A. Kazakov
2013-03-12 22:23               ` Georg Bauhaus
2013-03-13  8:49                 ` Dmitry A. Kazakov
2013-03-13  9:45                   ` J-P. Rosen
2013-03-13 13:31                     ` Dmitry A. Kazakov
2013-03-13 14:34                       ` Georg Bauhaus
2013-03-13 17:05                         ` Shark8
2013-03-13 17:45                           ` Simon Wright
2013-03-13 19:37                             ` Dmitry A. Kazakov
2013-03-13 21:09                               ` Randy Brukardt
2013-03-13 22:48                                 ` Shark8
2013-03-14 22:01                                   ` Randy Brukardt
2013-03-15  3:27                                     ` Shark8
2013-03-15 21:05                                       ` Randy Brukardt
2013-03-15 21:46                                         ` Robert A Duff
2013-03-16  5:52                                           ` Shark8
2013-03-16  7:41                                             ` Dmitry A. Kazakov
2013-03-16 16:55  3%                                           ` Shark8
2015-07-27 14:28     Running a preprocessor from GPS? EGarrulo
2015-07-27 20:26     ` Randy Brukardt
2015-07-28 11:36       ` EGarrulo
2015-07-28 21:12         ` Randy Brukardt
2015-07-28 22:11           ` EGarrulo
2015-07-29 20:32             ` Randy Brukardt
2015-07-29 22:32               ` EGarrulo
2015-07-30  8:27                 ` Pascal Obry
2015-07-30 11:51                   ` EGarrulo
2015-07-30 18:12                     ` Jeffrey R. Carter
2015-07-30 18:51                       ` EGarrulo
2015-07-30 19:27                         ` Jeffrey R. Carter
2015-07-30 19:54                           ` EGarrulo
2015-07-30 22:53  4%                         ` Jeffrey R. Carter
2017-08-29 20:28     win32 interfacing check (SetClipboardData) Xavier Petit
2017-08-30 16:04     ` Dmitry A. Kazakov
2017-08-30 18:41       ` Xavier Petit
2017-08-30 21:17         ` Dmitry A. Kazakov
2017-09-01 12:51           ` Xavier Petit
2017-09-01 13:10             ` Dmitry A. Kazakov
2017-09-02  9:38  3%           ` Xavier Petit
2020-02-27 22:54  5% Have I found an error in the index of the ARM? mgr
2020-07-30 20:21     Ada.Text_IO.File_Type object with user defined Get and Put subprograms Blady
2020-07-31 18:19     ` Shark8
2020-08-01  7:46       ` Blady
2020-08-01 17:23  6%     ` Shark8
2020-12-26  9:12  5% Type inference with String_Literal Blady
2020-12-27  5:26  0% ` Randy Brukardt
2021-04-17 22:03     Ada and Unicode DrPi
2021-04-19  8:29  7% ` Maxim Reznik
2021-04-19  9:28  0%   ` DrPi

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