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: use clauses
  2022-04-19  3:53  5%                       ` Thomas
@ 2022-04-19  5:59  3%                         ` Randy Brukardt
  0 siblings, 0 replies; 58+ 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 3%]

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


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

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


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

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

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


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

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


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

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

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


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

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


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

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

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


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

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

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

^ permalink raw reply	[relevance 5%]

* Problem with unbounded string input
@ 2021-01-27 19:59  6% Brian McGuinness
  0 siblings, 0 replies; 58+ 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 6%]

* Re: windows-1251 to utf-8
  2018-10-31 15:28  5% ` eduardsapotski
  2018-10-31 17:01  0%   ` Dmitry A. Kazakov
@ 2018-11-01 12:49  0%   ` Björn Lundin
  1 sibling, 0 replies; 58+ 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  0%     ` Randy Brukardt
  0 siblings, 0 replies; 58+ 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 0%]

* Re: windows-1251 to utf-8
  2018-10-31 15:28  5% ` eduardsapotski
@ 2018-10-31 17:01  0%   ` Dmitry A. Kazakov
  2018-10-31 20:58  0%     ` Randy Brukardt
  2018-11-01 12:49  0%   ` Björn Lundin
  1 sibling, 1 reply; 58+ 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  5% ` eduardsapotski
  2018-10-31 17:01  0%   ` Dmitry A. Kazakov
  2018-11-01 12:49  0%   ` Björn Lundin
  0 siblings, 2 replies; 58+ 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 5%]

* Re: Array of records with default values not propagating to array
  2018-02-03 11:06  3% Array of records with default values not propagating to array Bojan Bozovic
  2018-02-03 14:16  3% ` Jere
@ 2018-02-04  4:59  0% ` Bojan Bozovic
  1 sibling, 0 replies; 58+ 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 11:06  3% Array of records with default values not propagating to array Bojan Bozovic
@ 2018-02-03 14:16  3% ` Jere
  2018-02-04  4:59  0% ` Bojan Bozovic
  1 sibling, 0 replies; 58+ 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 3%]

* Array of records with default values not propagating to array
@ 2018-02-03 11:06  3% Bojan Bozovic
  2018-02-03 14:16  3% ` Jere
  2018-02-04  4:59  0% ` Bojan Bozovic
  0 siblings, 2 replies; 58+ 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 3%]

* Re: implementation of Bounded_String
  @ 2018-01-19  1:25  5% ` Randy Brukardt
  0 siblings, 0 replies; 58+ results
From: Randy Brukardt @ 2018-01-19  1:25 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:2eaf6de3-ce95-4c69-b22b-441a7ed6d5c9@googlegroups.com...
>I suppose it's obvious but...
> If I want to reimplement IO of Bounded_String without relying on
> Unbounded_String, can I do without getting reading input one character
> after another ? Has it to do with streams ?

Are you talking about the language-defined Bounded_Strings or something 
else? There is a package specifically for Text_IO of (language-defined) 
Bounded_Strings called Ada.Text_IO.Bounded_IO.

(There's a similar package for Unbounded_Strings, called 
Ada.Text_IO.Unbounded_IO. And of course Ada.Text_IO directly contains 
operations for the predefined type String.)

                           Randy.



^ permalink raw reply	[relevance 5%]

* Re: Why does this input get "skipped"?
  2016-08-21  0:01  0%   ` John Smith
@ 2016-08-21  0:36  0%     ` John Smith
  0 siblings, 0 replies; 58+ results
From: John Smith @ 2016-08-21  0:36 UTC (permalink / raw)


On Saturday, August 20, 2016 at 8:01:16 PM UTC-4, John Smith wrote:
> On Saturday, August 20, 2016 at 7:16:39 PM UTC-4, Jeffrey R. Carter wrote:
> > On 08/20/2016 03:41 PM, John Smith wrote:
> > > This is the snippet in question:
> > > Ada.Text_IO.Put("Delete a value - > ");
> > > String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
> > > Ada.Text_IO.New_Line;
> > > 
> > > The purpose is to have the user enter some string and then keep going.  When I ran the above code, I found that I saw "Delete a value - > " being printed, but the program didn't even give me a chance to enter some form of text...
> > > 
> > > Why did my code keep running?
> > 
> > It's impossible to be sure from the little information given, but the most
> > likely explanation is that there was already a line terminator waiting to be
> > consumed, and the call to Get_Line consumed it (and any characters preceding
> > it). This is often the case after a call to something like Ada.Integer_Text_IO.Get.
> > 
> > -- 
> > Jeff Carter
> > "People called Romanes, they go the house?"
> > Monty Python's Life of Brian
> > 79
> 
> Hi, I do have an Ada.Integer_Text_IO.Get above this call (some ways above it.)
> 
> How can I clear out that line terminator?  Another call to Get_Line, but not save the input?

Adding a Get_Line right after the Integer_Text_IO.Get did get me the result that I want.  However, why does this feel like a kludge?


^ permalink raw reply	[relevance 0%]

* Re: Why does this input get "skipped"?
  2016-08-20 23:16  0% ` Jeffrey R. Carter
@ 2016-08-21  0:01  0%   ` John Smith
  2016-08-21  0:36  0%     ` John Smith
  0 siblings, 1 reply; 58+ results
From: John Smith @ 2016-08-21  0:01 UTC (permalink / raw)


On Saturday, August 20, 2016 at 7:16:39 PM UTC-4, Jeffrey R. Carter wrote:
> On 08/20/2016 03:41 PM, John Smith wrote:
> > This is the snippet in question:
> > Ada.Text_IO.Put("Delete a value - > ");
> > String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
> > Ada.Text_IO.New_Line;
> > 
> > The purpose is to have the user enter some string and then keep going.  When I ran the above code, I found that I saw "Delete a value - > " being printed, but the program didn't even give me a chance to enter some form of text...
> > 
> > Why did my code keep running?
> 
> It's impossible to be sure from the little information given, but the most
> likely explanation is that there was already a line terminator waiting to be
> consumed, and the call to Get_Line consumed it (and any characters preceding
> it). This is often the case after a call to something like Ada.Integer_Text_IO.Get.
> 
> -- 
> Jeff Carter
> "People called Romanes, they go the house?"
> Monty Python's Life of Brian
> 79

Hi, I do have an Ada.Integer_Text_IO.Get above this call (some ways above it.)

How can I clear out that line terminator?  Another call to Get_Line, but not save the input?

^ permalink raw reply	[relevance 0%]

* Re: Why does this input get "skipped"?
  2016-08-20 22:41  5% Why does this input get "skipped"? John Smith
  2016-08-20 23:16  0% ` Jeffrey R. Carter
@ 2016-08-21  0:00  4% ` rieachus
  1 sibling, 0 replies; 58+ results
From: rieachus @ 2016-08-21  0:00 UTC (permalink / raw)


On Saturday, August 20, 2016 at 6:41:57 PM UTC-4, John Smith wrote:
> This is the snippet in question:
> Ada.Text_IO.Put("Delete a value - > ");
> String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
> Ada.Text_IO.New_Line;
> 
> The purpose is to have the user enter some string and then keep going.  When I ran the above code, I found that I saw "Delete a value - > " being printed, but the program didn't even give me a chance to enter some form of text...
> 
> Why did my code keep running?

There are two possibilities I see.  The first is that you expect that there is no input waiting when you output "Delete a value ->"  The call to Put will not erase any waiting input.  If there is a line waiting, in particular if End_Of_Line is true, you will get input.  If EOL is not true, and there is no EOL or EOP in the in the input buffer, it should wait.  But...  You next execute  New_Line.  If Current_Input and Current_Output are different files, no problem.  But there is no explicit barrier between the two calls, and any decent implementation of Text_IO will allow for task switches when waiting for input.  Looking at the New_Line is a bug, but I don't imagine there are any tests for it.  Consuming it would be wrong, but looking at the input and seeing a previous EOL is correct.

If you write your code:

Ada.Text_IO.Put_Line("Delete a value - > ");
String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
Ada.Text_IO.New_Line;

You should get what you want.  When working with a screen, I would not use Text_IO which was really designed for a terminal consisting of a keyboard and printer.  With Text_IO though, two good rules are: 1) A sequence of Puts should always end with a Put_Line or New_Line. 2) For input files, read input a line at a time into a String, then read from that String. Again, if you need to do other than line at a time I/O, you shouldn't beusing Text_IO.

(Confession: I wrote several Lisp drivers for specific display terminals on Multics.  When I needed to use display terminals with Ada, I knew enough to be able to treat them as full screen character displays.  Every time I thought I should create a clean Ada package instead of kludging Text_IO, but I never did.)

^ permalink raw reply	[relevance 4%]

* Re: Why does this input get "skipped"?
  2016-08-20 22:41  5% Why does this input get "skipped"? John Smith
@ 2016-08-20 23:16  0% ` Jeffrey R. Carter
  2016-08-21  0:01  0%   ` John Smith
  2016-08-21  0:00  4% ` rieachus
  1 sibling, 1 reply; 58+ results
From: Jeffrey R. Carter @ 2016-08-20 23:16 UTC (permalink / raw)


On 08/20/2016 03:41 PM, John Smith wrote:
> This is the snippet in question:
> Ada.Text_IO.Put("Delete a value - > ");
> String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
> Ada.Text_IO.New_Line;
> 
> The purpose is to have the user enter some string and then keep going.  When I ran the above code, I found that I saw "Delete a value - > " being printed, but the program didn't even give me a chance to enter some form of text...
> 
> Why did my code keep running?

It's impossible to be sure from the little information given, but the most
likely explanation is that there was already a line terminator waiting to be
consumed, and the call to Get_Line consumed it (and any characters preceding
it). This is often the case after a call to something like Ada.Integer_Text_IO.Get.

-- 
Jeff Carter
"People called Romanes, they go the house?"
Monty Python's Life of Brian
79


^ permalink raw reply	[relevance 0%]

* Why does this input get "skipped"?
@ 2016-08-20 22:41  5% John Smith
  2016-08-20 23:16  0% ` Jeffrey R. Carter
  2016-08-21  0:00  4% ` rieachus
  0 siblings, 2 replies; 58+ results
From: John Smith @ 2016-08-20 22:41 UTC (permalink / raw)


This is the snippet in question:
Ada.Text_IO.Put("Delete a value - > ");
String_Input := Ada.Text_IO.Unbounded_IO.Get_Line;
Ada.Text_IO.New_Line;

The purpose is to have the user enter some string and then keep going.  When I ran the above code, I found that I saw "Delete a value - > " being printed, but the program didn't even give me a chance to enter some form of text...

Why did my code keep running?


^ permalink raw reply	[relevance 5%]

* An extra CR character when writing to file (in addition to CR LF)
@ 2016-06-05 23:26  5% John Smith
  0 siblings, 0 replies; 58+ results
From: John Smith @ 2016-06-05 23:26 UTC (permalink / raw)


Here is my little example.  The problem that I have with it is that when it comes time to writing to the output file, the newline characters for some reason are CR CR LF.  I'm working in Windows, so I don't understand why I have the extra carriage return.

======================================================================

with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded;
with Ada.Command_Line;
with Ada.Directories;
with Ada.Direct_IO;
with Ada.Text_IO;

procedure stuff is
  Original_File : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.To_Unbounded_String(
    Source => "");

  procedure Manipulate_Contents(
    Contents : in out Ada.Strings.Unbounded.Unbounded_String) is

  begin
    Ada.Strings.Unbounded.Append(Contents, "    A hello!");
  end Manipulate_Contents;

  procedure Write_File(
    Contents  : in out Ada.Strings.Unbounded.Unbounded_String;
    File_Name : in Ada.Strings.Unbounded.Unbounded_String) is

    New_File : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.To_Unbounded_String(
      Source => "");

    F_Type : Ada.Text_IO.File_Type;
  begin
    Ada.Text_IO.Put("Enter the name of the new file: ");
    New_File := Ada.Text_IO.Unbounded_IO.Get_Line;

    begin
      Ada.Text_IO.Open(
        File => F_Type,
        Mode => Ada.Text_IO.Out_File,
        Name => Ada.Strings.Unbounded.To_String(New_File));
    exception
      when Ada.Text_IO.Name_Error =>
        Ada.Text_IO.Create(
          File => F_Type,
          Mode => Ada.Text_IO.Out_File,
          Name => Ada.Strings.Unbounded.To_String(New_File));
    end;

    Ada.Text_IO.Put(
      File => F_Type,
      Item => Ada.Strings.Unbounded.To_String(Contents));

    Ada.Text_IO.Close(
      File => F_Type);
  end Write_File;
begin
  if Ada.Command_Line.Argument_Count = 1
  then
    Original_File := Ada.Strings.Unbounded.To_Unbounded_String(Ada.Command_Line.Argument(1));
  else
    Ada.Text_IO.Put_Line(
      File => Ada.Text_IO.Standard_Error,
      Item => "ERROR: Incorrect number of command line arguments passed in.");

    return;
  end if;

  declare
    File_Size : Natural := Natural(Ada.Directories.Size(Ada.Strings.Unbounded.To_String(Original_File)));

    subtype File_String    is String(1 .. File_Size);
    package File_String_IO is new Ada.Direct_IO(File_String);

    F_Type        : File_String_IO.File_Type;
    File_Contents : File_String;

    U_File_Contents : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.To_Unbounded_String("");
  begin
    File_String_IO.Open(
      File => F_Type,
      Mode => File_String_IO.In_File,
      Name => Ada.Strings.Unbounded.To_String(Original_File));

    File_String_IO.Read(
      File => F_Type,
      Item => File_Contents);

    File_String_IO.Close(
      File => F_Type);

    U_File_Contents := Ada.Strings.Unbounded.To_Unbounded_String(File_Contents);

    Manipulate_Contents(
      Contents => U_File_Contents);

    Write_File(
      Contents => U_File_Contents,
      File_Name => Original_File);
  exception
    when Ada.Text_IO.Name_Error =>
      Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "ERROR:Name_Error: The file does not exist.  Exiting.");

      return;
    when Ada.Text_IO.Status_Error =>
      Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "ERROR:Status_Error: The file does not exist.  Exiting.");

      return;
    when Ada.Text_IO.Use_Error =>
      Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "ERROR:Use_Error: The file does not exist.  Exiting.");

      return;
    when others =>
      Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "Error encountered, exiting.");

      return;
  end;
end stuff;

======================================================================


^ permalink raw reply	[relevance 5%]

* Re: Why am I getting "missing operand" from get_line()?
  @ 2016-05-31  5:51  6%       ` Niklas Holsti
  0 siblings, 0 replies; 58+ results
From: Niklas Holsti @ 2016-05-31  5:51 UTC (permalink / raw)


On 16-05-31 08:40 , Egil H H wrote:
> On Tuesday, May 31, 2016 at 1:09:17 AM UTC+2, John Smith wrote:
>> On page 459 of the 2012 reference manual, on the last line, I can
>> clearly see that Get_Line() does not take any inputs and returns an
>> unbounded string.
>
> No, you can clearly see that Get_Line does not take any inputs and
> returns an unbounded string. Like I said, it does not take
> parenthesis

Just to make it very clear: a parameterless call in Ada consists of just 
the subprogram name, without any ().

Do not write:

   First_Name := Ada.Text_IO.Unbounded_IO.Get_Line();

Do write:

   First_Name := Ada.Text_IO.Unbounded_IO.Get_Line;

HTH,

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

^ permalink raw reply	[relevance 6%]

* Why am I getting "missing operand" from get_line()?
@ 2016-05-30 20:31  7% John Smith
    0 siblings, 1 reply; 58+ results
From: John Smith @ 2016-05-30 20:31 UTC (permalink / raw)


This is my code:

-- run_time_entry.adb:

with Ada.Text_IO.Unbounded_IO;
with Ada.Text_IO;

procedure Run_Time_Entry is
  First_Name : Ada.Strings.Unbounded.Unbounded_String;
  Last_Name  : Ada.Strings.Unbounded.Unbounded_String;
begin
  Ada.Text_IO.Put("Hello.  What is your first name => ");
  First_Name := Ada.Text_IO.Unbounded_IO.Get_Line();
  Ada.Text_IO.Put("What is your last name => ");
  Last_Name  := Ada.Text_IO.Unbounded_IO.Get_Line();

  Ada.Text_IO.Put("Nice to meet you ");
  Ada.Text_IO.Unbounded_IO.Put(First_Name);
  Ada.Text_IO.Put("  ");
  Ada.Text_IO.Unbounded_IO.Put_Line(Last_Name);
end Run_Time_Entry;




This is what happens when I compile it:

> gnatmake -g .\run_time_entry.adb
gcc -c -I.\ -g -I- .\run_time_entry.adb
run_time_entry.adb:11:51: missing operand
run_time_entry.adb:13:51: missing operand
gnatmake: ".\run_time_entry.adb" compilation error

Lines 11 and 13 is where I call Get_Line.  I don't understand, the reference manual (for 2012) says that this function ought to exist and it returns a string.

What am I missing?


^ permalink raw reply	[relevance 7%]

* Re: Out_File , excess line
    2016-01-22 20:01  6% ` comicfanzine
@ 2016-01-23 20:06  5% ` comicfanzine
  1 sibling, 0 replies; 58+ results
From: comicfanzine @ 2016-01-23 20:06 UTC (permalink / raw)


I figured out how to use the package ?

The code compile , and is launchable too .

But , when we try to open the file manually , the text editor print :

" This is not a text file . Type unknown . "

Same information for the file manager( Thunar ) .

??

---------------
WITH Ada.Text_IO.Unbounded_IO ; USE Ada.Text_IO.Unbounded_IO ;
WITH Ada.Strings.Unbounded ;    USE Ada.Strings.Unbounded ;
WITH Ada.Text_IO  ;             USE Ada.Text_IO  ;
WITH Ada.Streams.Stream_IO ;

Procedure count_nb_lines is

  this_file : File_type ;

  count_line : integer := 0 ;

Begin

    Open
     (File => this_file ,
      Mode => In_file ,
      Name => "count_nb_lines.adb");

   loop exit when End_Of_File( this_file );
     skip_line( this_file );
     count_line := count_line + 1 ;
   end loop ;


   declare

   Type Tableau_file is array( 1 .. count_line) of Unbounded_String ;

   case_array : Tableau_file ;


   PACKAGE ST_IO RENAMES Ada.Streams.Stream_IO ;

   test_file : ST_IO.File_type ;

   Input_Stream : ST_IO.Stream_Access ;

   begin

   Reset( this_file );

    Loop exit when End_Of_File( this_file );
        for i in 1..case_array'Length loop
         case_array(i) := get_line(this_file);
       end loop ;
   End loop;

   ST_IO.Create( File => test_file ,
               Mode => ST_IO.Out_File ,
               Name => "test" );

    Input_Stream := ST_IO.Stream( test_file );

    for j in 1..case_array'Length loop
      Unbounded_String'Write( Input_Stream , case_array(j) );
   end loop;

    end;
End count_nb_lines ;




^ permalink raw reply	[relevance 5%]

* Re: Out_File , excess line
  @ 2016-01-22 20:01  6% ` comicfanzine
  2016-01-23 20:06  5% ` comicfanzine
  1 sibling, 0 replies; 58+ results
From: comicfanzine @ 2016-01-22 20:01 UTC (permalink / raw)


I'm working with a text file .

Now , i use the package Ada.Text_IO.Unbounded_IO for text in Unbounded_Strings .

If i use the package Ada.Streams.Stream_IO , instead of Ada.Text_IO , for text handling , there is some changes to do :

Is there a Unbounded_String package for Stream_IO  ?

Or a another simplier way ?
-----------------------
WITH Ada.Text_IO.Unbounded_IO ; USE Ada.Text_IO.Unbounded_IO ;
WITH Ada.Strings.Unbounded ;    USE Ada.Strings.Unbounded ;
WITH Ada.Text_IO  ;             USE Ada.Text_IO  ;

Procedure count_nb_lines is

  this_file , test_file : File_type ;

  count : integer := 0 ;

Begin

    Open
     (File => this_file ,
      Mode => In_file ,
      Name => "count_nb_lines.adb");

   loop exit when End_Of_File( this_file );
     skip_line( this_file );
     count := count + 1 ;
   end loop ;

   Open
     (File => test_file ,
      Mode => Out_File ,
      Name => "test.adb");

   declare

   Type Tableau_lines_file is array( 1 .. count) of Unbounded_String;

   case_array : Tableau_lines_file ;

   begin

   Reset( this_file );

    Loop exit when End_Of_File( this_file );
        for i in 1..case_array'Length loop
         case_array(i) := get_line(this_file);
       end loop ;
   End loop;

    for j in 1..case_array'Length loop
      put_line( test_file , case_array(j) );
   end loop;

    end;
End count_nb_lines ;


^ permalink raw reply	[relevance 6%]

* Re: Re-write a file in Ada
  2016-01-19 12:04  6% ` comicfanzine
@ 2016-01-19 14:29  0%   ` Anh Vo
  0 siblings, 0 replies; 58+ results
From: Anh Vo @ 2016-01-19 14:29 UTC (permalink / raw)


On Tuesday, January 19, 2016 at 4:04:22 AM UTC-8, comicf...@gmail.com wrote:
> It compile now .
> 
> At launching , there is empty lines in the test_file , instead of the this_file'lines .
> 
> Am i missing something ?
> 
> WITH Ada.Text_IO.Unbounded_IO ; USE Ada.Text_IO.Unbounded_IO ;
> WITH Ada.Strings.Unbounded ;    USE Ada.Strings.Unbounded ;
> WITH Ada.Text_IO  ;             USE Ada.Text_IO  ;
> 
>    loop exit when End_Of_File( this_file );
>      skip_line( this_file );
>      count := count + 1 ;
>    end loop ;

This loop can be simplified by replacing exit when by not.

>     Loop exit when End_Of_File( this_file );
>         for i in 1..count loop
>          case_array(i) := get_line(this_file);
>        end loop ;
>    End loop;

This loop can be simplified same as previous loop.

Anh Vo



^ permalink raw reply	[relevance 0%]

* Re: Re-write a file in Ada
  2016-01-06 15:55  5% Re-write a file in Ada comicfanzine
                   ` (4 preceding siblings ...)
  2016-01-18  0:22  5% ` comicfanzine
@ 2016-01-19 12:04  6% ` comicfanzine
  2016-01-19 14:29  0%   ` Anh Vo
  5 siblings, 1 reply; 58+ results
From: comicfanzine @ 2016-01-19 12:04 UTC (permalink / raw)


It compile now .

At launching , there is empty lines in the test_file , instead of the this_file'lines .

Am i missing something ?

WITH Ada.Text_IO.Unbounded_IO ; USE Ada.Text_IO.Unbounded_IO ;
WITH Ada.Strings.Unbounded ;    USE Ada.Strings.Unbounded ;
WITH Ada.Text_IO  ;             USE Ada.Text_IO  ;

Procedure count_nb_lines is

  this_file , test_file : File_type ;

  count : integer := 0 ;

Begin

    Open
     (File => this_file ,
      Mode => In_file ,
      Name => "count_nb_lines.adb");

   loop exit when End_Of_File( this_file );
     skip_line( this_file );
     count := count + 1 ;
   end loop ;

   Open
     (File => test_file ,
      Mode => Out_file ,
      Name => "test.adb");

   declare

   Type Tableau_lines_file is array( 1 .. count) of Unbounded_String;

   case_array : Tableau_lines_file ;

   begin

    Loop exit when End_Of_File( this_file );
        for i in 1..count loop
         case_array(i) := get_line(this_file);
       end loop ;
   End loop;

    for j in 1..count loop
      put_line( test_file , case_array(j) );
   end loop;

    end;
End count_nb_lines ;


^ permalink raw reply	[relevance 6%]

* Re: Re-write a file in Ada
  2016-01-18  0:22  5% ` comicfanzine
@ 2016-01-18  9:50  0%   ` AdaMagica
  0 siblings, 0 replies; 58+ results
From: AdaMagica @ 2016-01-18  9:50 UTC (permalink / raw)


Am Montag, 18. Januar 2016 01:22:22 UTC+1 schrieb comicf...@gmail.com:
> First , I want to copy every line in a file , in a array of unbounded_Strings , to work on them later .
> 
> The problem is that i don't want to give a specific
> range at initializing .
> 
> In fact , it size must be known according to the number of lines in the file .

How about giving an upper bound of 1000 or 10_000 lines? This should be enough for most cases.

> WITH Ada.Text_IO ;              USE Ada.Text_IO ;
> WITH Ada.Text_IO.Unbounded_IO ; USE Ada.Text_IO.Unbounded_IO ;
> WITH Ada.Strings.Unbounded ;    USE Ada.Strings.Unbounded ;
> 
> Procedure main is
> 
>   this_file : File_type ;
> 
    Last_case : Natural := 0 ;  -- last filled line

    Type T_Tableau is array (1 .. 10_000) of unbounded_string ;
    -- size with upper limit to the number of lines in the file.

    case_of_array : T_Tableau ;  -- now a definite type
> 
> Begin
> 
>     Open
>      (File => this_file ,
>       Mode => In_file ,
>       Name => "main.adb");
> 
>    loop exit when End_Of_File ( this_file ) ;
> 
>     case_of_array( Last_case ) := Get_Line( this_file );
>     
>      Last_case := Last_case + 1 ;
>    end loop ;    
> End main ;

^ permalink raw reply	[relevance 0%]

* Re: Re-write a file in Ada
  2016-01-06 15:55  5% Re-write a file in Ada comicfanzine
                   ` (3 preceding siblings ...)
  2016-01-10 22:57  5% ` comicfanzine
@ 2016-01-18  0:22  5% ` comicfanzine
  2016-01-18  9:50  0%   ` AdaMagica
  2016-01-19 12:04  6% ` comicfanzine
  5 siblings, 1 reply; 58+ results
From: comicfanzine @ 2016-01-18  0:22 UTC (permalink / raw)


Hi ,

 björn lundin .

First , I want to copy every line in a file , in a array of unbounded_Strings , to work on them later .

The problem is that i don't want to give a specific
range at initializing .

In fact , it size must be known according to the number of lines in the file .


I changed several times the code .
I tried for instance , to determine how many lines a file have by using set_line until the end of the file , but it failed . 

Here the code simplified to be clear :

WITH Ada.Text_IO ;              USE Ada.Text_IO ;
WITH Ada.Text_IO.Unbounded_IO ; USE Ada.Text_IO.Unbounded_IO ;
WITH Ada.Strings.Unbounded ;    USE Ada.Strings.Unbounded ;

Procedure main is

  this_file : File_type ;

  Last_case : integer := 1 ;

  Type T_Tableau is array( Integer range <> ) of unbounded_string ;
  -- size according to the number of lines in the file .

  case_of_array : T_Tableau ;

Begin

    Open
     (File => this_file ,
      Mode => In_file ,
      Name => "main.adb");

   loop exit when End_Of_File ( this_file ) ;

    case_of_array( Last_case ) := Get_Line( this_file );
    
     Last_case := Last_case + 1 ;
   end loop ;    
End main ;


^ permalink raw reply	[relevance 5%]

* Re: Re-write a file in Ada
  2016-01-10 22:57  5% ` comicfanzine
  2016-01-11  1:59  0%   ` Anh Vo
@ 2016-01-11 10:09  0%   ` Björn Lundin
  1 sibling, 0 replies; 58+ results
From: Björn Lundin @ 2016-01-11 10:09 UTC (permalink / raw)


On 2016-01-10 23:57, comicfanzine@gmail.com wrote:
> Thanks björn lundin and the others !
> 
> I finally suceed :
> 
> WITH Ada.Text_IO ;  		USE Ada.Text_IO ;
> WITH Ada.Text_IO.Unbounded_IO ;	USE Ada.Text_IO.Unbounded_IO ;
> WITH Ada.Strings.Unbounded ;	USE Ada.Strings.Unbounded ;
> 
> Procedure main is


...

Compare your code to mine.
what is the array for ?
what kind of manipulating are you doing ?
To me it looks like you are doing nothing
more that storing the lines in an array,
and then write the array to a new file.
Why? And why not doing that in the loop
in my example?

And as others pointed out:
Get_Line will get you the whole line,
and next call will get you the whole NEXT line,
so Set_Line is not needed.




-- 
--
Björn


^ permalink raw reply	[relevance 0%]

* Re: Re-write a file in Ada
  2016-01-10 22:57  5% ` comicfanzine
@ 2016-01-11  1:59  0%   ` Anh Vo
  2016-01-11 10:09  0%   ` Björn Lundin
  1 sibling, 0 replies; 58+ results
From: Anh Vo @ 2016-01-11  1:59 UTC (permalink / raw)


On Sunday, January 10, 2016 at 2:57:42 PM UTC-8, comicf...@gmail.com wrote:
> Thanks björn lundin and the others !
> 
> I finally suceed :
> 
> WITH Ada.Text_IO ;  		USE Ada.Text_IO ;
> WITH Ada.Text_IO.Unbounded_IO ;	USE Ada.Text_IO.Unbounded_IO ;
> WITH Ada.Strings.Unbounded ;	USE Ada.Strings.Unbounded ;
> 
> Procedure main is
> 
>   next_l : Positive_Count := 1 ;
> 
>   this_file : File_type ;
> 
>   f_deux : File_type ;
> 
>   Type T_Tableau is array( 1 .. 1_000 ) of unbounded_string ;
> 
>   case_of_array : T_Tableau ;
> 
>   get_l : integer := 1 ;
>   -- Rôle d'intervalle dans le tableau , dans la boucle
> 
>   c_to_put : integer ;
> 
>   nb_lign_to_put : integer := 1 ;
> 
> Begin
> 
> 	Open
>      (File => this_file ,
>       Mode => In_file ,
>       Name => "main.adb");
> 
>     un : loop exit when End_Of_File ( this_file ) ;
> 	    set_line ( this_file , next_l ) ;
> 
> 	    case_of_array(get_l) := Get_Line( this_file );
> 
> 		next_l := next_l + 1 ;
> 		get_l := get_l + 1 ;
> 
> 		 c_to_put := get_l ;
> 	    -- compte le nbr de get_line effectué
> 
>    end loop un ;
> 
>       Open
>      (File => f_deux ,
>       Mode => Out_file ,
>       Name => "verify");
> 
>     deux : loop exit when nb_lign_to_put = c_to_put ;
> 
>      Put_line( f_deux , case_of_array(nb_lign_to_put) ) ;
> 
>      nb_lign_to_put := nb_lign_to_put + 1 ;
> 
>    end loop deux ;
> End main ;

It is very inefficient. In fact, the Set_Line (...) can be eliminated. In addition, next_l, c_to_put and nb_lign_to_put variables are not needed.

Anh Vo


^ permalink raw reply	[relevance 0%]

* Re: Re-write a file in Ada
  2016-01-06 15:55  5% Re-write a file in Ada comicfanzine
                   ` (2 preceding siblings ...)
  @ 2016-01-10 22:57  5% ` comicfanzine
  2016-01-11  1:59  0%   ` Anh Vo
  2016-01-11 10:09  0%   ` Björn Lundin
  2016-01-18  0:22  5% ` comicfanzine
  2016-01-19 12:04  6% ` comicfanzine
  5 siblings, 2 replies; 58+ results
From: comicfanzine @ 2016-01-10 22:57 UTC (permalink / raw)


Thanks björn lundin and the others !

I finally suceed :

WITH Ada.Text_IO ;  		USE Ada.Text_IO ;
WITH Ada.Text_IO.Unbounded_IO ;	USE Ada.Text_IO.Unbounded_IO ;
WITH Ada.Strings.Unbounded ;	USE Ada.Strings.Unbounded ;

Procedure main is

  next_l : Positive_Count := 1 ;

  this_file : File_type ;

  f_deux : File_type ;

  Type T_Tableau is array( 1 .. 1_000 ) of unbounded_string ;

  case_of_array : T_Tableau ;

  get_l : integer := 1 ;
  -- Rôle d'intervalle dans le tableau , dans la boucle

  c_to_put : integer ;

  nb_lign_to_put : integer := 1 ;

Begin

	Open
     (File => this_file ,
      Mode => In_file ,
      Name => "main.adb");

    un : loop exit when End_Of_File ( this_file ) ;
	    set_line ( this_file , next_l ) ;

	    case_of_array(get_l) := Get_Line( this_file );

		next_l := next_l + 1 ;
		get_l := get_l + 1 ;

		 c_to_put := get_l ;
	    -- compte le nbr de get_line effectué

   end loop un ;

      Open
     (File => f_deux ,
      Mode => Out_file ,
      Name => "verify");

    deux : loop exit when nb_lign_to_put = c_to_put ;

     Put_line( f_deux , case_of_array(nb_lign_to_put) ) ;

     nb_lign_to_put := nb_lign_to_put + 1 ;

   end loop deux ;
End main ;

^ permalink raw reply	[relevance 5%]

* Re: Re-write a file in Ada
  @ 2016-01-10 18:59  6%   ` Björn Lundin
  0 siblings, 0 replies; 58+ results
From: Björn Lundin @ 2016-01-10 18:59 UTC (permalink / raw)


On 2016-01-10 17:54, comicfanzine@gmail.com wrote:
> Ok , in others words :
> 
> I want to open the file , copy all the lines in it , then do some change in those lignes ( unbounded_strings ) , and finally paste all in the file ( mode : Out_file ) .
> 
> This is what i meant by " Re-write a file " .
> 
> 
> The error :
> 
> raised ADA.IO_EXCEPTIONS.END_ERROR : a-tigeli.adb:96
> 

Below, you need tocomplement with paramters for
open/create, and declare from_file and to_file

try something like :


--pseudo code

with Ada.Text_IO.Unbounded_IO ;	use Ada.Text_IO.Unbounded_IO ;
with Ada.Strings.Unbounded ;	use Ada.Strings.Unbounded ;
with Ada.Text_IO ;              use Ada.Text_IO ;

procedure Rewrite is
  Buffer : Unbounded_String := Null_Unbounded_String;
begin
  Open (From_file);
  Create(To_File);

  begin
    loop
      Buffer := Get_Line(From_File);
      Put_Line(To_File, Buffer);
    end loop;
  exception
    when End_Error =>
      Close(From_File);
      Close(To_File);
  end;
end Rewrite;



-- 
--
Björn


^ permalink raw reply	[relevance 6%]

* Re: Re-write a file in Ada
  @ 2016-01-08 22:08  6%   ` Anh Vo
  0 siblings, 0 replies; 58+ results
From: Anh Vo @ 2016-01-08 22:08 UTC (permalink / raw)


On Friday, January 8, 2016 at 1:22:57 PM UTC-8, Randy Brukardt wrote:
> <comicfanzine@gmail.com> wrote in message 
> news:77e47c8b-7dcc-4e86-8f89-1f348cdf08dd@googlegroups.com...
> > Hello everybody ,
> >
> > Next , a working code which re-write entirely a file .
> >
> > I would like to modify it , doing the same thing exept that :
> >
> > Undounded_strings will be generate every time there is a next line .
> >
> > Then , several get_line will be done on those strings .
> >
> > And in final , put those modified strings in the file .
> >
> >
> > Anyone knows how to code that ?
> 
> I'm sure most of us can code whatever we need, and the above seems trivial. 
> But most of us are also professional programmers, either working in Ada or 
> working in some other language and doing hobby projects in Ada. We're happy 
> to help, but being pros has two effects:
> 
> (1) We're not interested in writing other people's programs for them. We'll 
> help people learn, but that's very different.
> (2) One of the first things that professional programmers learn is that the 
> hardest thing to do is to debug someone else's code.
> 
> On top of which, you gave code (which is good), but you never explained (in 
> detail!) what happens compared to what you expect. Given that, the only 
> serious alternative is to spend a hour or more figuring out what you're 
> trying to do and then create a program (from scratch) that does that. I 
> suspect most everyone here has something better to do than that. (The only 
> time I'd do this is if I find the problem is interesting, which certainly is 
> not the case here.)
> 
> I, personally, rarely look at the code posted here; I provide help based on 
> the error and then work backwards from there. Since you didn't provide the 
> error, and I'm surely not going try to load and compile your code, attempt 
> to figure out what data you are reading, whether the results I get make any 
> sense, and so on.
> 
> I'd suggest telling us what results you are getting from your code and what 
> you are expecting, and perhaps someone will want to help you (but no 
> promises).

I agreed 100% with Randy. 

Tell me if I understood you correctly. You wanted to read text in your source text (main.adb) one line at time. Then, they are concatenated into a single line of text for entire file. For example, if there are two lines of text, as shown below, the result would be one line of text as shown in the bottom.

with Ada.Text_IO.Unbounded_IO ;  use Ada.Text_IO.Unbounded_IO ;
with Ada.Strings.Unbounded ;  use Ada.Strings.Unbounded ;

with Ada.Text_IO.Unbounded_IO ;  use Ada.Text_IO.Unbounded_IO ;with Ada.Strings.Unbounded ;  use Ada.Strings.Unbounded ;

Anh Vo

^ permalink raw reply	[relevance 6%]

* Re: Re-write a file in Ada
  2016-01-06 15:55  5% Re-write a file in Ada comicfanzine
@ 2016-01-07 13:02  6% ` comicfanzine
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 58+ results
From: comicfanzine @ 2016-01-07 13:02 UTC (permalink / raw)


I tried with a array but the program crash .

============================================
with Ada.Text_IO.Unbounded_IO ;	use Ada.Text_IO.Unbounded_IO ;
with Ada.Strings.Unbounded ;	use Ada.Strings.Unbounded ;
with Ada.Text_IO ;				use Ada.Text_IO ;

Procedure main is

  this_file : File_Type ;

  next_line : Positive_Count := 1 ;

  Type T_Tableau is array(1..1_000) of unbounded_string ;

  phrases : T_Tableau ;


Begin

	 Open
     (Mode => In_file ,
      File => this_file ,
      Name => "main.adb" ) ;


   loop
		exit when End_Of_File ( this_file ) ;

	  Set_Line ( this_file , next_line );

        if next_line > 1 then

            for i in 1 .. 1_000 loop
                phrases(i) := get_line ( this_file ) ;
            end loop ;

        end if ;

      next_line := next_line + 1 ;

   end loop ;

    Close ( this_file ) ;

     Open
     (Mode => Out_file ,
      File => this_file ,
      Name => "main.adb" ) ;

    for i in 1..1_000 loop
      put ( this_file , phrases(i) ) ;
   end loop ;


     Close ( this_file ) ;

end main ;


^ permalink raw reply	[relevance 6%]

* Re: Unbounded.String instead of Standard.String
  2016-01-06 15:21  6%     ` comicfanzine
@ 2016-01-06 17:41  0%       ` Anh Vo
  0 siblings, 0 replies; 58+ results
From: Anh Vo @ 2016-01-06 17:41 UTC (permalink / raw)


On Wednesday, January 6, 2016 at 7:21:54 AM UTC-8, comicf...@gmail.com wrote:
> > Here is a tiny hint. Linkable/Executable procedure has no parameter.
> > 
> > Anh Vo
> 
> I didn't knew that a main procedure has no parameter .
> Plus , i was a beginner with ubunded_string , so here is the correction :
> 
> with Ada.Text_IO;
> with Ada.Strings.Unbounded;
> with Ada.Text_IO.Unbounded_IO;
>   
> use Ada.Text_IO;
> use Ada.Strings.Unbounded;
> use Ada.Text_IO.Unbounded_IO;
>  
> procedure autre is  
>   var_string : Unbounded_String;
>  begin
>     get_line(var_string);
>     put(var_string);
> end autre;

To make it clearer I would suggest to add a statement before get_line telling the operator to type a message.

     put ("Please type a message then press Enter key: ");

^ permalink raw reply	[relevance 0%]

* Re-write a file in Ada
@ 2016-01-06 15:55  5% comicfanzine
  2016-01-07 13:02  6% ` comicfanzine
                   ` (5 more replies)
  0 siblings, 6 replies; 58+ results
From: comicfanzine @ 2016-01-06 15:55 UTC (permalink / raw)


Hello everybody ,

Next , a working code which re-write entirely a file .

I would like to modify it , doing the same thing exept that : 

Undounded_strings will be generate every time there is a next line .

Then , several get_line will be done on those strings .

And in final , put those modified strings in the file .


Anyone knows how to code that ?

Here is what i done for now =

with Ada.Text_IO.Unbounded_IO ; use Ada.Text_IO.Unbounded_IO ;
with Ada.Strings.Unbounded ;    use Ada.Strings.Unbounded ;
with Ada.Text_IO ;              use Ada.Text_IO ;
 
Procedure main is
 
  this_file : File_Type ;
 
  copy_file_1 : Unbounded_String ;
  copy_file_in_1 : Unbounded_String ;
 
  next_line : Positive_Count := 1 ;
 
Begin
 
     Open
     (Mode => In_file ,
      File => this_file ,
      Name => "main.adb" ) ;
 
 
     loop
        exit when End_Of_File ( this_file ) ;
 
     Set_Line ( this_file , next_line );
 
     get_line ( this_file , copy_file_in_1 ) ;
 
     Append
     ( Source  => copy_file_1 ,
       New_Item => copy_file_in_1 ) ;
 
      next_line := next_line + 1 ;
 
     end loop ;
 
    Close ( this_file ) ;
 
     Open
     (Mode => Out_file ,
      File => this_file ,
      Name => "main.adb" ) ;
 
     put ( this_file , copy_file_1 ) ;
 
     Close ( this_file ) ;
 
end main ;

^ permalink raw reply	[relevance 5%]

* Re: Unbounded.String instead of Standard.String
  @ 2016-01-06 15:21  6%     ` comicfanzine
  2016-01-06 17:41  0%       ` Anh Vo
  0 siblings, 1 reply; 58+ results
From: comicfanzine @ 2016-01-06 15:21 UTC (permalink / raw)


> Here is a tiny hint. Linkable/Executable procedure has no parameter.
> 
> Anh Vo

I didn't knew that a main procedure has no parameter .
Plus , i was a beginner with ubunded_string , so here is the correction :

with Ada.Text_IO;
with Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;
  
use Ada.Text_IO;
use Ada.Strings.Unbounded;
use Ada.Text_IO.Unbounded_IO;
 
procedure autre is  
  var_string : Unbounded_String;
 begin
    get_line(var_string);
    put(var_string);
end autre;

^ permalink raw reply	[relevance 6%]

* Re: Running a preprocessor from GPS?
  @ 2015-07-31  7:53  5%                               ` gautier_niouzes
  0 siblings, 0 replies; 58+ results
From: gautier_niouzes @ 2015-07-31  7:53 UTC (permalink / raw)


Le jeudi 30 juillet 2015 22:53:28 UTC+2, EGarrulo a écrit :

> I am not thinking in C++ terms.  I am thinking in terms of patterns
> that I know for managing resources.  So far, I only know the "shared/weak
> pointer" idiom.  If Ada offers something else, besides manual reclamation, I am
> eager to learn about it.

Fantastic, then the example below is for you!
Of course it is a trivial example. You can add a field of type Text to a window type for instance, and the memory will be automatically freed when the window itself is finalized. No pointer, no manual reclamation, no garbage waiting to be collected!... Magic, isn't it ?

--  This test program reads an entire text file into a variable
--  of type Text which is a vector of unbounded strings.

with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO, Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Containers.Vectors;

procedure Text_Container is

  package Text_Pkg is new Ada.Containers.Vectors(Positive, Unbounded_String);
  
  ---------------------
  --  Text container --
  ---------------------
  subtype Text is Text_Pkg.Vector;
  --
  name: constant String:= "text_container.adb";
  t: Text;
  f: File_Type;
begin
  Open(f, In_File, name);
  while not End_of_File(f) loop
    t.Append(Get_Line(f));
  end loop;
  Close(f);
  --
  Create(f, Out_File, "copy_of_" & name);
  for line of t loop
    Put_Line(f, line);
  end loop;
  Close(f);
end;
_________________________
Gautier's Ada programming
http://gautiersblog.blogspot.com/search/label/Ada
NB: follow the above link for a valid e-mail address

^ permalink raw reply	[relevance 5%]

* Re: Error "exception not permitted here" when putting EXCEPTION in a loop
  2015-07-18 14:32  5%           ` Trish Cayetano
@ 2015-07-18 14:59  6%             ` Björn Lundin
  0 siblings, 0 replies; 58+ results
From: Björn Lundin @ 2015-07-18 14:59 UTC (permalink / raw)


On 2015-07-18 16:32, Trish Cayetano wrote:
> On Saturday, July 18, 2015 at 9:55:12 PM UTC+8, björn lundin wrote:

This one works.
As Tero said - skip_line in exception handler does it.
But you ONLY need it there.

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.IO_Exceptions; use Ada.IO_Exceptions;

procedure Main is
   GuessWord : String(1..20);
   last: Natural;
   option : Integer := 0;
   endGame: Boolean := False;
begin
    while not endGame loop
      begin
          Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass
3)Enter Word 4)Exit ");
          Ada.Integer_Text_IO.Get(option);
          case option is
             when 1 =>
                Ada.Text_IO.Put_Line("Shuffle");
             when 2 =>
                Ada.Text_IO.Put_Line("Pass");
             when 3 =>
                Skip_Line; -- needed ????
                Ada.Text_IO.Put_Line("Enter word: ");
                Ada.Text_IO.Get_Line(GuessWord, Last);
             when 4 =>
                Ada.Text_IO.Put_Line("See you again soon!");
                endGame := true;
             when others =>
                Ada.Text_IO.Put_Line("Invalid Option");
          end case;
	exception
	  when ADA.IO_EXCEPTIONS.Data_Error =>
	    Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");
	    skip_line;
         end;
     end loop;
end Main;

--
Björn

^ permalink raw reply	[relevance 6%]

* Re: Error "exception not permitted here" when putting EXCEPTION in a loop
  @ 2015-07-18 14:32  5%           ` Trish Cayetano
  2015-07-18 14:59  6%             ` Björn Lundin
  0 siblings, 1 reply; 58+ results
From: Trish Cayetano @ 2015-07-18 14:32 UTC (permalink / raw)


On Saturday, July 18, 2015 at 9:55:12 PM UTC+8, björn lundin wrote:
> On 2015-07-18 14:41, Trish Cayetano wrote:
> > Hello Björn, 
> > 
> > I don't need the inner loop after all.
> > I removed the inner loop but it still run in infinite loops.
> 
> it runs fine as long as you do not enter a non-digit.
> Then it seems like the call to
>   Ada.Integer_Text_IO.Get(option);
> does not clear the buffer.
> 
> if fed a character, Data_error is raised - which is correct.
> But the next time the code enters the loop, it seems it does
> not wait for input again.
> It raises the data_error again, and the infinite loop is there.
> 
> Seems like a compiler bug to me, but the behavior of *text_io.get
> has surprised me before.
> 
> --
> Björn

Well which reminds me! I added a SKIP_LINE... The expected output is close... It shows the exception error every other input... it waits for 2 inputs and then 1 input and then 2... 

REVISED

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.IO_Exceptions; use Ada.IO_Exceptions;

procedure Main is

   GuessWord : String(1..20);
   last: Natural;

   option : Integer := 0;

   endGame: Boolean := False;


begin

    while not endGame loop


         begin

         Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit ");
         Skip_Line;
         Ada.Integer_Text_IO.Get(option);
         
          exception
            when ADA.IO_EXCEPTIONS.Data_Error =>
            Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");


      case option is
         when 1 =>
            Ada.Text_IO.Put_Line("Shuffle");
         when 2 =>
            Ada.Text_IO.Put_Line("Pass");
         when 3 =>
            Skip_Line;
            Ada.Text_IO.Put_Line("Enter word: ");
            Ada.Text_IO.Get_Line(GuessWord, Last);
         when 4 =>
            Ada.Text_IO.Put_Line("See you again soon!");
            endGame := true;
         when others =>
            Ada.Text_IO.Put_Line("Invalid Option");


      end case;

           
           



         end;

          end loop;



end Main;


=====

OUTPUT

C:\Users\a0284014\Desktop\ada\exception\obj\main
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
e
1
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
3
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
e
Try a number from 1 to 4, Buddy
Enter word: 
e
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
r
t
Try a number from 1 to 4, Buddy
Enter word: 
r
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
r

^ permalink raw reply	[relevance 5%]

* Re: Error "exception not permitted here" when putting EXCEPTION in a loop
  @ 2015-07-18 12:41  5%       ` Trish Cayetano
    0 siblings, 1 reply; 58+ results
From: Trish Cayetano @ 2015-07-18 12:41 UTC (permalink / raw)


On Saturday, July 18, 2015 at 6:07:12 PM UTC+8, björn lundin wrote:
> On 2015-07-18 10:14, Trish Cayetano wrote:
> 
> e is my own code (i removed the functions and others)... S
> 
> orry I am really new to Ada. I actually tried also to put
> 
> another loop and added declare, begin and end. It
> 
> hang after I ran. And when I terminated the process, it looks like it
> ran infinitely in loops.
> > 
> 
> when you set endGame to true,
> you are in the *inner* loop.
> but the *outer* loop tests for endGame.
> 
> How do you exit the *inner* loop?
> 
> what purpose has the *inner* loop?
> 
> When you have the answer,
> your program will be easy to fix.
> 
> --
> Björn

Hello Björn, 

I don't need the inner loop after all.
I removed the inner loop but it still run in infinite loops.

REVISED CODE:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.IO_Exceptions; use Ada.IO_Exceptions;

procedure Main is

   GuessWord : String(1..20);
   last: Natural;

   option : Integer := 0;

   endGame: Boolean := False;


begin

    while not endGame loop


         begin

      Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit ");
      Ada.Integer_Text_IO.Get(option);

      case option is
         when 1 =>
            Ada.Text_IO.Put_Line("Shuffle");
         when 2 =>
            Ada.Text_IO.Put_Line("Pass");
         when 3 =>
            Skip_Line;
            Ada.Text_IO.Put_Line("Enter word: ");
            Ada.Text_IO.Get_Line(GuessWord, Last);
         when 4 =>
            Ada.Text_IO.Put_Line("See you again soon!");
            endGame := true;
         when others =>
            Ada.Text_IO.Put_Line("Invalid Option");


      end case;

            Skip_Line;
            exception
            when ADA.IO_EXCEPTIONS.Data_Error =>
            Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");
           



         end;
      
          end loop;



end Main;


RESULT:
C:\Users\a0284014\Desktop\ada\exception\obj\main
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
f
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
Try a number from 1 to 4, Buddy

[2015-07-18 20:39:33] process exited with status 1, elapsed time: 10.81s

^ permalink raw reply	[relevance 5%]

* Re: Error "exception not permitted here" when putting EXCEPTION in a loop
  @ 2015-07-18  8:14  5%   ` Trish Cayetano
    0 siblings, 1 reply; 58+ results
From: Trish Cayetano @ 2015-07-18  8:14 UTC (permalink / raw)


On Friday, July 17, 2015 at 11:58:18 PM UTC+8, G.B. wrote:
> On 17.07.15 17:47, Trish Cayetano wrote:
> > Hi,
> >
> > I am getting error "exception not permitted here" when running below in a loop.
> > Well it runs if I put it outside the loop but I need it inside the loop...
> >
> >             exception
> >              when ADA.IO_EXCEPTIONS.DATA_ERROR =>
> >              Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");
> >
> > Thanks in advance for your help...
> >
> 
> does it look like
> 
>   loop
>      ...
>     exception ...
>      ...
>   end loop
> 
> If so, then note that "exception" must be in a block,
> such as a procedure body, or a block statement (LRM 5.6):
> 
> 
>    loop
>      begin
>        ...  -- handled sequence of statements
>      exception ...
>      ...
>      end;
>    end loop
> 
> More complete examples would help reducing guess work.

Thanks, David and GB.
It still does not work... 
Here is my own code (i removed the functions and others)... Sorry I am really new to Ada. I actually tried also to put another loop and added declare, begin and end. It hang after I ran. And when I terminated the process, it looks like it ran infinitely in loops. 

   
===== 
--start of code

   with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.IO_Exceptions; use Ada.IO_Exceptions;

procedure Main is

   GuessWord : String(1..20);
   last: Natural;
 
   option : Integer := 0;
 
   endGame: Boolean := False;


begin

    while not endGame loop

      loop
         begin

      Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit ");
      Ada.Integer_Text_IO.Get(option);

      case option is
         when 1 =>
            Ada.Text_IO.Put_Line("Shuffle");
         when 2 =>
            Ada.Text_IO.Put_Line("Pass");
         when 3 =>
            Skip_Line;
            Ada.Text_IO.Put_Line("Enter word: ");
            Ada.Text_IO.Get_Line(GuessWord, Last);
         when 4 =>
            Ada.Text_IO.Put_Line("See you again soon!");
            endGame := true;
         when others =>
            Ada.Text_IO.Put_Line("Invalid Option");


      end case;

            exception
            when ADA.IO_EXCEPTIONS.Data_Error =>
            Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");




         end;
          end loop;
      end loop;


end Main;



--end of code
==============
RESULT:

C:\Users\a0284014\Desktop\ada\exception\obj\main
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
1
Shuffle
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
e
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
Try a number from 1 to 4, Buddy
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 

--retracted repeats
[2015-07-18 16:11:13] process exited with status 1, elapsed time: 19.58s

^ permalink raw reply	[relevance 5%]

* Re: array of string
  @ 2014-10-07  2:08  6% ` Jerry
  0 siblings, 0 replies; 58+ results
From: Jerry @ 2014-10-07  2:08 UTC (permalink / raw)


with Ada.Strings.Unbounded;    use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
procedure Strings_Demo is
    type String_Array is array (Integer range <>) of Unbounded_String;
    Cities : String_Array(1 .. 2);
begin
    Cities(1) := To_Unbounded_String("London");
    Cities(2) := To_Unbounded_String("Toronto");
    Put_Line(Cities(1));
    Put_Line(Cities(2));
end Strings_Demo;

^ permalink raw reply	[relevance 6%]

* Vectors.Insert_Space bug?
@ 2009-05-20 20:59  4% Thomas Løcke
  0 siblings, 0 replies; 58+ results
From: Thomas Løcke @ 2009-05-20 20:59 UTC (permalink / raw)


Hey all,

I've stumbled on some weird behavior while trying to make use of the 
Ada.Containers.Vectors.Insert_Space procedure. According to the RM, this 
is what it should do:

"... Then Insert_Space slides the elements in the range Before .. 
Last_Index (Container) up by Count positions, and then inserts empty 
elements in the positions starting at Before."

But that is not at all what I'm seeing, as this small test-program will 
show:

--  Pasted code start  --

with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded;      use Ada.Strings.Unbounded;
with Ada.Containers.Vectors;     use Ada.Containers;

procedure Test is
    package SUIO renames Ada.Text_IO.Unbounded_IO;
    package US_Container is new Vectors (Positive, Unbounded_String);
    Testing : US_Container.Vector;
begin
    Testing.Append (New_Item => To_Unbounded_String ("Item 1"));
    Testing.Append (New_Item => To_Unbounded_String ("Item 2"));
    Testing.Append (New_Item => To_Unbounded_String ("Item 3"));
    Testing.Append (New_Item => To_Unbounded_String ("Item 4"));
    Testing.Append (New_Item => To_Unbounded_String ("Item 5"));

    Testing.Insert_Space (Before => 5,
                       Count => 3);

    for i in 1 .. Testing.Length loop
       SUIO.Put_Line (i'Img & " " & Testing.Element (Integer (i)));
    end loop;
end Test;

--  Pasted code end  --

The output from the Test program is:

  1 Item 1
  2 Item 2
  3 Item 3
  4 Item 4
  5 Item 5
  6
  7
  8 Item 5

Which IMHO is wrong. There shouldn't be two "Item 5" elements. And it's 
possible to make it even worse, by calling Insert_Space multiple times 
with different Before and Count parameters.

It seems as if the element located at the Before index is copied and 
inserted as the first new element, and only after that, does 
Insert_Space actually start inserting empty elements.

I've tried to compile with two different compilers, and both exhibit 
this odd behavior:
	GNATMAKE 4.2.3
	GNATMAKE  GPL 2008 (20080521)

I admit to just being a hobbyist, so this might just be me not "getting" 
what the RM is trying to tell me, but I do think the text is fairly clear.

Any help would be greatly appreciated.

Regards,
Thomas L�cke



^ permalink raw reply	[relevance 4%]

* Defaulting to Standard_Output
@ 2008-10-23 23:10  5% deadlyhead
  0 siblings, 0 replies; 58+ results
From: deadlyhead @ 2008-10-23 23:10 UTC (permalink / raw)


I'm writing a text processing program in the Unix tradition where, if
given no specific output file, all output is directed to
Standard_Output.  I've found this to be confusing as File_Type is
limited private.  Thus operations such as Outfile := Standard_Output
don't work.  I tried using File_Access for my Outfile object, but that
proved to be cumbersome as I was having a lot of trouble with
scoping.  My solution is as follows:

-------------------
-- begin example --
-------------------

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded;
use  Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;
use  Ada.Text_IO.Unbounded_IO;

procedure Default_Output is

   --  our output file
   Outfile : File_Type;

   --  for getting the file name
   Name : Unbounded_String;

   -- rename the Text_IO function Put
   procedure TIO_Put (File : in File_Type;
		      Item : in String) renames Ada.Text_IO.Put;

   procedure Put (File : in File_Type; Item : in String) is
   begin
      -- Check to see if File has been Open'ed
      -- If not, send to Standard_Output
      if Is_Open (File) then
	 TIO_Put (File, Item);
      else
	 Put (Item);			--  to Standard_Output
      end if;
   end Put;

begin  -- Default_Output

   Put ("Name of file to process: ");
   Get_Line (Name);

   --  Open the file if we have a file name
   if Name /= "" then
      Create (Outfile, Out_File,
	      Slice (Name, 1,
		     Index (Name, " ") - 1));
   end if;

   Put (Outfile, "Default_Output output!");

   if Is_Open (Outfile) then
      Close (Outfile);
   end if;

end Default_Output;

-----------------
-- end example --
-----------------

I did not actually use the Ada.Strings.Unbounded procedures is my
code, and I'm posting this from a machine where I cannot validate what
I've written, but it looks right to me.

If anybody has a better way of handling defaulting to Standard_Output,
I'd like to see it.  This works for me, and seems elegant enough.  It
avoids a lot of messy conditionals in the body, anyway.

-- deadlyhead



^ permalink raw reply	[relevance 5%]

* Re: The future of Ada is at risk
  2008-01-06  9:34  3%     ` Agyaras
  2008-01-07  3:46  5%       ` Brian May
@ 2008-01-08  2:22  0%       ` Randy Brukardt
  1 sibling, 0 replies; 58+ results
From: Randy Brukardt @ 2008-01-08  2:22 UTC (permalink / raw)


"Agyaras" <agyaras@kerekerdoe.hu> wrote in message
news:agyaras-50CE35.10341806012008@news.inode.at...
> In article <1199452391.7932.27.camel@K72>,
...
> The problem for many people starts earlier. Consider these two programs:-
>
> -- Ada (221 chars)
> with Ada.Strings.Unbounded, Ada.Text_IO.Unbounded_IO;
> use Ada.Strings.Unbounded, Ada.Text_IO.Unbounded_IO;
>
> procedure str is
>    Strg: Unbounded_String := To_Unbounded_String("ergonomy");
> begin
>    Put_Line(Strg);
> end str;

Boy, that's sure a long-winded way to write this. I'd write something like
this:

with Ada.Text_IO;
procedure Str is
    Strg : String := "ergonomy";
begin
    Ada.Text_IO.Put_Line (Strg);
end Str;

I didn't count the characters, but it's surely a lot shorter than the
original version.

Moral: Don't even think about using Unbounded_String unless you have to; the
native strings of Ada are quite powerful. I've found that Unbounded_String
is more work than it is worth about 80% of the time. Ada is surely wordy
when that 20% comes up (especially for those of use who rarely use use
clauses), but that is about the least important attribute of a programming
language.

Moral2: Writing C++ code in Ada is rather likely to make lousy Ada code (I'm
sure the reverse is true, too.)

                     Randy.





^ permalink raw reply	[relevance 0%]

* Re: The future of Ada is at risk
  2008-01-06  9:34  3%     ` Agyaras
@ 2008-01-07  3:46  5%       ` Brian May
  2008-01-08  2:22  0%       ` Randy Brukardt
  1 sibling, 0 replies; 58+ results
From: Brian May @ 2008-01-07  3:46 UTC (permalink / raw)


>>>>> "Agyaras" == Agyaras  <agyaras@kerekerdoe.hu> writes:

    Agyaras> The problem for many people starts earlier. Consider these two programs:-

    Agyaras> -- Ada (221 chars)
    Agyaras> with Ada.Strings.Unbounded, Ada.Text_IO.Unbounded_IO;
    Agyaras> use Ada.Strings.Unbounded, Ada.Text_IO.Unbounded_IO;

    Agyaras> procedure str is
    Agyaras> Strg: Unbounded_String := To_Unbounded_String("ergonomy");
    Agyaras> begin
    Agyaras> Put_Line(Strg);
    Agyaras> end str;

    Agyaras> // C++ (148 chars)
    Agyaras> #include <string>
    Agyaras> #include <iostream>
    Agyaras> using namespace std;

    Agyaras> int main(int argc, char *argv[])
    Agyaras> {
    Agyaras> string Strg("ergonomy");
    Agyaras> cout<<Strg<<endl;
    Agyaras> }

I find the Ada version easier to understand.

Also it is interesting to note that:

Put_Line(Strg);

Is shorter and easier to understand then:

cout<<Strg<<endl;

Where Ada misses out most, is the top two lines. Maybe it could have a
clause that does both "with"+"use" at the same time.
-- 
Brian May <bam@snoopy.apana.org.au>



^ permalink raw reply	[relevance 5%]

* Re: The future of Ada is at risk
  @ 2008-01-06  9:34  3%     ` Agyaras
  2008-01-07  3:46  5%       ` Brian May
  2008-01-08  2:22  0%       ` Randy Brukardt
  0 siblings, 2 replies; 58+ results
From: Agyaras @ 2008-01-06  9:34 UTC (permalink / raw)


In article <1199452391.7932.27.camel@K72>,
 Georg Bauhaus <rm.tsoh+bauhaus@maps.futureapps.de> wrote:

> > I can confirm this. E.g. it is a major headache to get the GNAT compiler 
> > working under Mac OS X.
> 
> What do you think of http://www.macada.org/ ?

Yes, I know the site, and have downloaded the FSF gcc4.3 version from 
there ( both PPC and Intel). The problem is that this gcc sometimes 
cannot compile packages the "official" Apple gcc can. So one has to 
switch back and forth, using gcc4.3 for Ada work and the Apple gcc for 
other work (e.g. C++). This is probably Apple's fault though.

> >  AdaCore stopped distributing GNAT/GPS (GPL) for 
> > the Mac.
> 
> Huh? It is still there (the 2006 edition)
That is PowerPC only, based on gcc 3.4, with incomplete Ada2005 support. 
It would be nice to have GPS for Intel Macs, gcc4.2 at least, with 
complete Ada2005 support. I tried to compile GPS from the Linux sources 
(2007 edition) on the Mac and it turned to be very time-consuming, 
because GPS needs lots of libraries that in turn needed more 
libraries... finally I gave up, after I asked on this newsgroup and 
people told me that it was really difficult to do... but maybe the good 
folks at AdaCore have the proper setup and the know-how to do it.

> , and support for the
> later Intel based Macs is officially announced on the AdaCore
> supported platforms page.
I was perhaps not clear on this: I am missing the **GPL** editions of 
GNAT **and** the GPS IDE for a number of platforms. In 2007 the GPL-ed 
GNAT+GPS packages are available for Windows and 32-bit/64-bit Linux 
only. I cannot afford the license costs.

> >  There has never been a GNAT/GPS package for Solaris AFAIK. 
> > etc.etc.
> 
> Huh? Please, have a look. It is still there.
Sorry, I meant the **GPL** editions (see above).

IMHO it is absolutely necessary to provide freely available compilers 
and IDEs for as many platforms as possible to make a language popular. 
People should have the opportunity to "give Ada a spin" free of charge, 
even if they live outside the Intel X86/Windows/Linux galaxy.

GPS is great for learning Ada because you can "look" into the sources of 
the spec files of the standard library. It helped me a lot when I was 
learning the containers: John Barnes' otherwise excellent Ada2005 book 
is sometimes a bit tight-lipped on how these work.

> >  she needs simple but powerful string handling, 
> 
> I don't see how simple but powerful string handling
> is missing with GNAT's SPITBOL support. [...]
> Even the String packages are full of useful algorithms and
> data structures, even though there is no general character
> type in Ada.

The problem for many people starts earlier. Consider these two programs:-

-- Ada (221 chars)
with Ada.Strings.Unbounded, Ada.Text_IO.Unbounded_IO;
use Ada.Strings.Unbounded, Ada.Text_IO.Unbounded_IO;

procedure str is
   Strg: Unbounded_String := To_Unbounded_String("ergonomy");
begin
   Put_Line(Strg);
end str;

// C++ (148 chars)
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    string Strg("ergonomy");
    cout<<Strg<<endl;
}

The fact that the type of the string constant "ergonomy" is String 
requires the (semantically unnecessary) conversion To_Unbounded_String() 
in the Ada version. This is what I meant by clumsiness, not even 
mentioning the separate I/O library necessary to print this string 
afterwards. You don't really want to go through all these hoops just to 
print a string...

I think that the default string type should be the unbounded string, 
just like in C++, for ergonomic reasons. (Fixed strings may be needed in 
special cases. But the bounded string type family, where you have to 
convert from a 70-char string type to a 71-char string type, is an 
abomination and should be forgotten quickly.) And there should be only 
one I/O library, not dozens, otherwise programming ergonomics suffers, 
and that frightens people away. We should keep in mind that CPU time is 
cheaper than "brain time", so let the computer suffer a bit more 
instead. :-)

Talking about safety and ergonomics: how do you tell which Ada 
subprograms raise which exceptions? Well, you cannot. The Java designers 
got this absolutely right: the method signatures can contain a throws() 
clause. Either you catch an exception or let it propagate and the 
compiler complains if you omit the throws() in the latter case. It would 
be nice if the Ada2005 standard could be amended with a similar 
mechanism. If it can be done in Java, then it certainly could be done in 
Ada! :-)

"Make computers work so that humans won't have to"

A

-- 
"Non est volentis, neque currentis, sed miserentis Dei"



^ permalink raw reply	[relevance 3%]

* Re: STRING length
  2006-11-15  1:09  4%     ` markww
@ 2006-11-15  1:21  0%       ` Ludovic Brenta
  0 siblings, 0 replies; 58+ results
From: Ludovic Brenta @ 2006-11-15  1:21 UTC (permalink / raw)


"markww" <markww@gmail.com> writes:

> Actually please disregard the previous post, I found I needed to with
> and use:
>
>     Ada.Text_IO.Unbounded_IO
>
> So.. finally one compilation error remains, the actual call to my
> function:
>
>     begin
>
>         Add_Record("Mark", "555-555-5555", "123 main street");
>
>     end LinkList;
>
> the error is:
>
>     expected private type "Ada.Strings.Unbounded.Unbounded_String"
>
> what does that mean? The problem is with calling the procedure, if I
> comment the call out compilation is successful. The procedure looks
> like:

"Mark" is a regular, not unbounded string.  Try this:

begin
   Add_Record (To_Unbounded_String ("Mark"),
               To_Unbounded_String ("555-555-5555"),
               To_Unbounded_String ("123 main street"));
end;

You may also like:

declare
   function "+" (R : in String) return Unbounded_String
      renames To_Unbounded_String;
begin
   Add_Record (+"Mark", +"555-555-5555", +"123 main street");
end;

-- 
Ludovic Brenta.



^ permalink raw reply	[relevance 0%]

* Re: STRING length
  @ 2006-11-15  1:09  4%     ` markww
  2006-11-15  1:21  0%       ` Ludovic Brenta
  0 siblings, 1 reply; 58+ results
From: markww @ 2006-11-15  1:09 UTC (permalink / raw)


Actually please disregard the previous post, I found I needed to with
and use:

    Ada.Text_IO.Unbounded_IO

So.. finally one compilation error remains, the actual call to my
function:

    begin

        Add_Record("Mark", "555-555-5555", "123 main street");

    end LinkList;

the error is:

    expected private type "Ada.Strings.Unbounded.Unbounded_String"

what does that mean? The problem is with calling the procedure, if I
comment the call out compilation is successful. The procedure looks
like:

    procedure Add_Record(strName : in UNBOUNDED_STRING;
                                      strPhone : in UNBOUNDED_STRING;
                                      strAddress : in UNBOUNDED_STRING)
is
       Temp : CHAR_REC_POINT;
   begin
	Put(strName);
	New_Line;
	Put(strPhone);
	New_Line;
	Put(strAddress);
	New_Line;
    end Add_Record;

I guess the compiler doesn't interpret a literal string as an
unbounded_string?

Thanks,
Mark


On Nov 14, 7:44 pm, "markww" <mar...@gmail.com> wrote:
> Thanks Georg, that looks to be exactly what I need. I do have a problem
> '#including', or, 'withing' rather unbounded string.
> Now the head of my source file looks like:
>
>     with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded;
>     use Ada.Text_IO, Ada.Integer_Text_IO;
>
> which is alright but as soon as I try:
>
>     use Ada.Strings.Unbounded;
>
> the compiler gives me a bunch of errors, it seems to conflict with
> Text_IO / Integer_Text_IO? Seems like all my previous calls to Put()
> now became invalid. I'm not familiar with Ada but with C++ and
> understand namespace collisions, is the same thing going on here?
>
> Thanks
>
> On Nov 14, 5:24 pm, Georg Bauhaus <bauh...@futureapps.de> wrote:
>
>
>
> > On Tue, 2006-11-14 at 14:51 -0800, markww wrote:
> > > Hi,
>
> > > How does one use a variable length string in ada?You use variable length strings in Ada by declaring them
> > to be of type UNBOUNDED_STRING which is defined in
> > Ada.Strings.Unbounded.
>
> > type MY_RECORD is
> >   record
> >     Name: UNBOUNDED_STRING;
> >     Phone: UNBOUNDED_STRING;
> >     Address: UNBOUNDED_STRING;
> >   end record;
>
> > Given that Phone is likely to be limited in length, you
> > could consider declaring the Phone component to be of
> > type BOUNDED_STRING, which is a string type with a maximum length.
> > Unlike STRING, objects of this type can have any number
> > of characters up to the maximum. See Ada.Strings.Bounded.
>
> > Yet another use of strings is in nested scopes: If you need
> > a string in just one place, e.g. temporarily, you can use
> > a plain STRING as in
>
> >   declare
> >     temp: constant STRING := some_string_returning_func(...);
> >   begin
> >     -- use temp
> >   end;
>
> > The point here is that the `temp` string variable takes
> > its bound from the initialization. You can also make it a
> > variable, if you need to write to string components.
>
> > Seehttp://en.wikibooks.org/wiki/Ada_Programming/Strings
> 
> > -- Georg- Hide quoted text -- Show quoted text -




^ permalink raw reply	[relevance 4%]

* Re: ada and pl/sql
  2006-03-27 21:15  0%   ` Martin Dowie
@ 2006-03-27 23:28  0%     ` Jason King
  0 siblings, 0 replies; 58+ results
From: Jason King @ 2006-03-27 23:28 UTC (permalink / raw)


Now don't laugh folks, but most of my work is done on Windows.  Is the 
gcc Ada usable and does it include Ada 2005?  I'd prefer something 
gnat-like as a cursory examination of add-on packages leads me to 
believe gnat has more contributions and extensions than all the other 
implementations combined.  If I understand correctly the current free 
GNAT builds are GPL'ed not LGPL'ed which would put a crimp in some of 
the things I want to develop.
Martin Dowie wrote:
> Bj�rn Persson wrote:
> 
>> (Ada.Text_IO.Unbounded_IO is new in Ada 2005, so it's only present in 
>> the newest libraries.)
> 
> 
> <shameless_plug>
> Or you can pick up the source and compile your own from 
> http://www.martin.dowie.btinternet.co.uk/
> </shameless_plug>
> 
> :-)
> 
> Cheers
> -- Martin



^ permalink raw reply	[relevance 0%]

* Re: ada and pl/sql
  2006-03-27 21:07  6% ` Björn Persson
@ 2006-03-27 21:15  0%   ` Martin Dowie
  2006-03-27 23:28  0%     ` Jason King
  0 siblings, 1 reply; 58+ results
From: Martin Dowie @ 2006-03-27 21:15 UTC (permalink / raw)


Bj�rn Persson wrote:
> (Ada.Text_IO.Unbounded_IO is new in Ada 2005, so it's only present in 
> the newest libraries.)

<shameless_plug>
Or you can pick up the source and compile your own from 
http://www.martin.dowie.btinternet.co.uk/
</shameless_plug>

:-)

Cheers
-- Martin



^ permalink raw reply	[relevance 0%]

* Re: ada and pl/sql
  @ 2006-03-27 21:07  6% ` Björn Persson
  2006-03-27 21:15  0%   ` Martin Dowie
  0 siblings, 1 reply; 58+ results
From: Björn Persson @ 2006-03-27 21:07 UTC (permalink / raw)


Jason King wrote:
> declare
>    v1 varchar2(10) := 'Hello';
>    v2 varchar2(10) := 'World';
>    v3 varchar2(30);
> begin
>    v3 := v1 || ' ' || v2 ; -- || is string concat operator.
>                            -- no error here since 'Hello World'
>                            -- fits.
>    dbms_output.put_line(v3) ; -- prints "Hello World"
[...]
> ada.strings.bounded and 
> ada.strings.unbounded are issues because assignment (:=) doesn't work 
> for them and concatenation is method not an operator.

Assignment and concatenation work just fine. Here's your example in Ada:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;

procedure Unbounded_Demo is
    String_1 : Unbounded_String := To_Unbounded_String("Hello");
    String_2 : Unbounded_String := To_Unbounded_String("World");
    String_3 : Unbounded_String;
begin
    String_3 := String_1 & ' ' & String_2;
    Ada.Text_IO.Unbounded_IO.Put_Line(String_3);
end Unbounded_Demo;

(Ada.Text_IO.Unbounded_IO is new in Ada 2005, so it's only present in 
the newest libraries.)

> As far as I can 
> tell I can't overload the assignment operator or the || operator.

That's right. Instead of overloadable assignment, Ada has controlled 
types. "||" isn't an operator in Ada; the string concatenation operator 
is "&", and that one is overloadable.

> Other than creating a new language is there some way to make a 
> varchar2-like first-class datatype that has its own operators?

It's perfectly possible to create such a type in pure Ada, but you don't 
need to, because it's already there in the standard library. Bounded or 
unbounded strings are what you want.

I have actually written a string handling package of my own. I got sick 
of the endless character encoding bugs, so I created an unbounded string 
type where each string object keeps track of its own encoding. I call it 
EAstrings � encoding-aware strings.

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



^ permalink raw reply	[relevance 6%]

* Re: Why these "Drop" parameters? (was: variable lenght strings)
  2004-10-24 18:38  0%     ` Why these "Drop" parameters? (was: variable lenght strings) Björn Persson
@ 2004-10-26  0:13  0%       ` Randy Brukardt
  0 siblings, 0 replies; 58+ results
From: Randy Brukardt @ 2004-10-26  0:13 UTC (permalink / raw)


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

I think it is a typo for the Bounded_Slice and Unbounded_Slice routines;
nowhere can I find any description of what it means (the text description of
these functions never mentions "Drop"). Nor do any of the meeting minutes
that I checked.

Could you submit your comment to Ada-Comment (e-mail it to
ada-comment@ada-auth.org)? We need to get it on the record so this can be
fixed.

                Randy Brukardt
                ARG Editor.

"Bj�rn Persson" <spam-away@nowhere.nil> wrote in message
news:lESed.6963$d5.58967@newsb.telia.net...
Martin Dowie wrote:

> Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12

Reading that file I see these declarations:

procedure Set_Bounded_String
    (Target :    out Bounded_String;
     Source : in     String;
     Drop   : in     Truncation := Error);

function Bounded_Slice
    (Source : in Bounded_String;
     Low    : in Positive;
     High   : in Natural;
     Drop   : in Truncation := Error)
        return Bounded_String;

procedure Bounded_Slice
    (Source : in     Bounded_String;
     Target :    out Bounded_String;
     Low    : in     Positive;
     High   : in     Natural;
     Drop   : in     Truncation := Error);

procedure Set_Unbounded_String
    (Target :    out Unbounded_String;
     Source : in     String;
     Drop   : in     Truncation := Error);

function Unbounded_Slice
    (Source : in Unbounded_String;
     Low    : in Positive;
     High   : in Natural;
     Drop   : in Truncation := Error)
        return Unbounded_String;

procedure Unbounded_Slice
    (Source : in     Unbounded_String;
     Target :    out Unbounded_String;
     Low    : in     Positive;
     High   : in     Natural;
     Drop   : in     Truncation := Error);

For Set_Bounded_String it is quite obvious that Drop specifies what
should happen if Source is longer than the maximum length of Target, but
can anyone explain what all the other "Drop" parameters are for?

In the case of Bounded_Slice, shouldn't a slice of Source always fit in
Target? Aren't they the same type, with the same max length?

Unbounded strings are supposed to be unbounded. Their only limit should
be the available memory, no? So, are the "Drop" parameters there meant
as a way to avoid Storage_Error?

--
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu






^ permalink raw reply	[relevance 0%]

* Re: variable lenght strings
  2004-10-25  7:30  0%         ` Martin Krischik
@ 2004-10-26  0:06  0%           ` Randy Brukardt
  0 siblings, 0 replies; 58+ results
From: Randy Brukardt @ 2004-10-26  0:06 UTC (permalink / raw)


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

"Martin Krischik" <krischik@users.sourceforge.net> wrote in message
news:1154613.ipZcUgduzp@linux1.krischik.com...
> Bj�rn Persson wrote:
>
> > Martin Krischik wrote:
> >> Martin Dowie wrote:
> >>
> >>>Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
> >>>http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12
> >>
> >> Cool. How will it handle a missing CR/LF at the end of file?
> >
> > There is a brief discussion of that in the AI file. Randy said that the
> > implementation has always been required to provide an implicit line
> > terminator.
>
> Well, last time i checked GNAT didn't and raised an end of file exception.

My opinion is that GNAT is wrong in that case. A.10(7) makes it quite clear
that you can't have a file terminator without a line and page terminator in
front of it.

I vaguely recall having argued this with Robert Dewar, and I think that they
had a different interpretation, based on the idea that a file with a missing
CR/LF is incorrect for use with Text_IO. I hope I misremember that, because
it is stupid (even if it is logically correct) as it essentially says that
you can't read outside generated text files with Text_IO (you can't know
whether the file has CR/LFs as required).

But I can understand why they wouldn't want to do this properly, because it
is a pain to get right, and it saps the performance of Text_IO (since you
have the be prepared to check for implied characters for each one you read).

                     Randy.






^ permalink raw reply	[relevance 0%]

* Re: variable lenght strings
  2004-10-24 18:37  0%       ` Björn Persson
@ 2004-10-25  7:30  0%         ` Martin Krischik
  2004-10-26  0:06  0%           ` Randy Brukardt
  0 siblings, 1 reply; 58+ results
From: Martin Krischik @ 2004-10-25  7:30 UTC (permalink / raw)


Bjï¿œrn Persson wrote:

> Martin Krischik wrote:
>> Martin Dowie wrote:
>> 
>>>Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
>>>http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12
>> 
>> Cool. How will it handle a missing CR/LF at the end of file?
> 
> There is a brief discussion of that in the AI file. Randy said that the
> implementation has always been required to provide an implicit line
> terminator.

Well, last time i checked GNAT didn't and raised an end of file exception.

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[relevance 0%]

* Why these "Drop" parameters? (was: variable lenght strings)
  2004-10-22 11:11  4%   ` Martin Dowie
  2004-10-24 15:43  0%     ` Martin Krischik
@ 2004-10-24 18:38  0%     ` Björn Persson
  2004-10-26  0:13  0%       ` Randy Brukardt
  1 sibling, 1 reply; 58+ results
From: Björn Persson @ 2004-10-24 18:38 UTC (permalink / raw)


Martin Dowie wrote:

> Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12

Reading that file I see these declarations:

procedure Set_Bounded_String
    (Target :    out Bounded_String;
     Source : in     String;
     Drop   : in     Truncation := Error);

function Bounded_Slice
    (Source : in Bounded_String;
     Low    : in Positive;
     High   : in Natural;
     Drop   : in Truncation := Error)
        return Bounded_String;

procedure Bounded_Slice
    (Source : in     Bounded_String;
     Target :    out Bounded_String;
     Low    : in     Positive;
     High   : in     Natural;
     Drop   : in     Truncation := Error);

procedure Set_Unbounded_String
    (Target :    out Unbounded_String;
     Source : in     String;
     Drop   : in     Truncation := Error);

function Unbounded_Slice
    (Source : in Unbounded_String;
     Low    : in Positive;
     High   : in Natural;
     Drop   : in Truncation := Error)
        return Unbounded_String;

procedure Unbounded_Slice
    (Source : in     Unbounded_String;
     Target :    out Unbounded_String;
     Low    : in     Positive;
     High   : in     Natural;
     Drop   : in     Truncation := Error);

For Set_Bounded_String it is quite obvious that Drop specifies what 
should happen if Source is longer than the maximum length of Target, but 
can anyone explain what all the other "Drop" parameters are for?

In the case of Bounded_Slice, shouldn't a slice of Source always fit in 
Target? Aren't they the same type, with the same max length?

Unbounded strings are supposed to be unbounded. Their only limit should 
be the available memory, no? So, are the "Drop" parameters there meant 
as a way to avoid Storage_Error?

-- 
Björn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu




^ permalink raw reply	[relevance 0%]

* Re: variable lenght strings
  2004-10-24 15:43  0%     ` Martin Krischik
  2004-10-24 17:39  0%       ` Martin Dowie
@ 2004-10-24 18:37  0%       ` Björn Persson
  2004-10-25  7:30  0%         ` Martin Krischik
  1 sibling, 1 reply; 58+ results
From: Björn Persson @ 2004-10-24 18:37 UTC (permalink / raw)


Martin Krischik wrote:
> Martin Dowie wrote:
> 
>>Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
>>http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12
> 
> Cool. How will it handle a missing CR/LF at the end of file?

There is a brief discussion of that in the AI file. Randy said that the 
implementation has always been required to provide an implicit line 
terminator.

-- 
Björn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu




^ permalink raw reply	[relevance 0%]

* Re: variable lenght strings
  2004-10-24 15:43  0%     ` Martin Krischik
@ 2004-10-24 17:39  0%       ` Martin Dowie
  2004-10-24 18:37  0%       ` Björn Persson
  1 sibling, 0 replies; 58+ results
From: Martin Dowie @ 2004-10-24 17:39 UTC (permalink / raw)


"Martin Krischik" <krischik@users.sourceforge.net> wrote in message 
news:1195374.UMjBCk7lO1@linux1.krischik.com...
> Martin Dowie wrote:
>
>> Martin Krischik wrote:
>>>> 1) Is it possible to use Get_Line with Unbounded and/or Bounded
>>>> Strings?
>>>
>>> Well the Standart overlooked that one. However it is quite easy to
>>> write your own - either a recursive solution for String or a loop
>>> solution with Unbounded_String.
>>
>> Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
>> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12
>
> Cool. How will it handle a missing CR/LF at the end of file?

The AI defines:
function Get_Line
  (File : in File_Type)
   return Strings.Unbounded.Unbounded_String;

   Returns Strings.Unbounded.To_Unbounded_String(Text_IO.Get_Line(File));So, 
I'm guessing it will be consistant with the current Get_Line behaviour.--  
Martin 





^ permalink raw reply	[relevance 0%]

* Re: variable lenght strings
  2004-10-22 11:11  4%   ` Martin Dowie
@ 2004-10-24 15:43  0%     ` Martin Krischik
  2004-10-24 17:39  0%       ` Martin Dowie
  2004-10-24 18:37  0%       ` Björn Persson
  2004-10-24 18:38  0%     ` Why these "Drop" parameters? (was: variable lenght strings) Björn Persson
  1 sibling, 2 replies; 58+ results
From: Martin Krischik @ 2004-10-24 15:43 UTC (permalink / raw)


Martin Dowie wrote:

> Martin Krischik wrote:
>>> 1) Is it possible to use Get_Line with Unbounded and/or Bounded
>>> Strings?
>>
>> Well the Standart overlooked that one. However it is quite easy to
>> write your own - either a recursive solution for String or a loop
>> solution with Unbounded_String.
> 
> Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12

Cool. How will it handle a missing CR/LF at the end of file?

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[relevance 0%]

* Re: variable lenght strings
  @ 2004-10-22 11:11  4%   ` Martin Dowie
  2004-10-24 15:43  0%     ` Martin Krischik
  2004-10-24 18:38  0%     ` Why these "Drop" parameters? (was: variable lenght strings) Björn Persson
  0 siblings, 2 replies; 58+ results
From: Martin Dowie @ 2004-10-22 11:11 UTC (permalink / raw)


Martin Krischik wrote:
>> 1) Is it possible to use Get_Line with Unbounded and/or Bounded
>> Strings?
>
> Well the Standart overlooked that one. However it is quite easy to
> write your own - either a recursive solution for String or a loop
> solution with Unbounded_String.

Being added in Ada2005, see Ada.Text_IO.Unbounded_IO in
http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00301.TXT?rev=1.12





^ permalink raw reply	[relevance 4%]

Results 1-58 of 58 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2004-10-21 17:52     variable lenght strings fabio de francesco
2004-10-22  7:25     ` Martin Krischik
2004-10-22 11:11  4%   ` Martin Dowie
2004-10-24 15:43  0%     ` Martin Krischik
2004-10-24 17:39  0%       ` Martin Dowie
2004-10-24 18:37  0%       ` Björn Persson
2004-10-25  7:30  0%         ` Martin Krischik
2004-10-26  0:06  0%           ` Randy Brukardt
2004-10-24 18:38  0%     ` Why these "Drop" parameters? (was: variable lenght strings) Björn Persson
2004-10-26  0:13  0%       ` Randy Brukardt
2006-03-27 20:05     ada and pl/sql Jason King
2006-03-27 21:07  6% ` Björn Persson
2006-03-27 21:15  0%   ` Martin Dowie
2006-03-27 23:28  0%     ` Jason King
2006-11-14 22:51     STRING length markww
2006-11-14 22:24     ` Georg Bauhaus
2006-11-15  0:44       ` markww
2006-11-15  1:09  4%     ` markww
2006-11-15  1:21  0%       ` Ludovic Brenta
2007-12-29  3:06     The future of Ada is at risk Rico Secada
2008-01-04  8:45     ` Agyaras
2008-01-04 13:13       ` Georg Bauhaus
2008-01-06  9:34  3%     ` Agyaras
2008-01-07  3:46  5%       ` Brian May
2008-01-08  2:22  0%       ` Randy Brukardt
2008-10-23 23:10  5% Defaulting to Standard_Output deadlyhead
2009-05-20 20:59  4% Vectors.Insert_Space bug? Thomas Løcke
2014-10-03 23:29     array of string Stribor40
2014-10-07  2:08  6% ` Jerry
2015-07-17 15:47     Error "exception not permitted here" when putting EXCEPTION in a loop Trish Cayetano
2015-07-17 15:58     ` G.B.
2015-07-18  8:14  5%   ` Trish Cayetano
2015-07-18 10:08         ` Björn Lundin
2015-07-18 12:41  5%       ` Trish Cayetano
2015-07-18 13:56             ` Björn Lundin
2015-07-18 14:32  5%           ` Trish Cayetano
2015-07-18 14:59  6%             ` Björn Lundin
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-29 23:51                 ` Jeffrey R. Carter
2015-07-30  0:10                   ` EGarrulo
2015-07-30  6:01                     ` Niklas Holsti
2015-07-30  7:33                       ` Björn Lundin
2015-07-30  8:03                         ` EGarrulo
2015-07-30  8:08                           ` Jacob Sparre Andersen
2015-07-30  8:37                             ` EGarrulo
2015-07-30 19:29                               ` Jeffrey R. Carter
2015-07-30 20:53                                 ` EGarrulo
2015-07-31  7:53  5%                               ` gautier_niouzes
2015-12-27 17:34     Unbounded.String instead of Standard.String comicfanzine
2015-12-27 17:39     ` Jeffrey R. Carter
2015-12-28 19:00       ` Anh Vo
2016-01-06 15:21  6%     ` comicfanzine
2016-01-06 17:41  0%       ` Anh Vo
2016-01-06 15:55  5% Re-write a file in Ada comicfanzine
2016-01-07 13:02  6% ` comicfanzine
2016-01-08 21:22     ` Randy Brukardt
2016-01-08 22:08  6%   ` Anh Vo
2016-01-10 16:54     ` comicfanzine
2016-01-10 18:59  6%   ` Björn Lundin
2016-01-10 22:57  5% ` comicfanzine
2016-01-11  1:59  0%   ` Anh Vo
2016-01-11 10:09  0%   ` Björn Lundin
2016-01-18  0:22  5% ` comicfanzine
2016-01-18  9:50  0%   ` AdaMagica
2016-01-19 12:04  6% ` comicfanzine
2016-01-19 14:29  0%   ` Anh Vo
2016-01-20  1:39     Out_File , excess line comicfanzine
2016-01-22 20:01  6% ` comicfanzine
2016-01-23 20:06  5% ` comicfanzine
2016-05-30 20:31  7% Why am I getting "missing operand" from get_line()? John Smith
2016-05-30 20:36     ` Egil H H
2016-05-30 23:09       ` John Smith
2016-05-31  5:40         ` Egil H H
2016-05-31  5:51  6%       ` Niklas Holsti
2016-06-05 23:26  5% An extra CR character when writing to file (in addition to CR LF) John Smith
2016-08-20 22:41  5% Why does this input get "skipped"? John Smith
2016-08-20 23:16  0% ` Jeffrey R. Carter
2016-08-21  0:01  0%   ` John Smith
2016-08-21  0:36  0%     ` John Smith
2016-08-21  0:00  4% ` rieachus
2018-01-18 14:10     implementation of Bounded_String Mehdi Saada
2018-01-19  1:25  5% ` Randy Brukardt
2018-02-03 11:06  3% Array of records with default values not propagating to array Bojan Bozovic
2018-02-03 14:16  3% ` Jere
2018-02-04  4:59  0% ` Bojan Bozovic
2018-10-31  2:57     windows-1251 to utf-8 eduardsapotski
2018-10-31 15:28  5% ` eduardsapotski
2018-10-31 17:01  0%   ` Dmitry A. Kazakov
2018-10-31 20:58  0%     ` Randy Brukardt
2018-11-01 12:49  0%   ` Björn Lundin
2021-01-27 19:59  6% Problem with unbounded string input Brian McGuinness
2021-04-17 21:45     Unchecked_Deallocation with tagged types DrPi
2021-04-18  8:21     ` Dmitry A. Kazakov
2021-04-18  9:13       ` DrPi
2021-04-18 16:48         ` Jeffrey R. Carter
2021-04-20 15:57           ` Stephen Leake
2021-04-20 17:24             ` Jeffrey R. Carter
2021-04-20 17:34               ` Vincent Marciante
2021-04-20 20:56                 ` Jeffrey R. Carter
2021-04-21 10:21                   ` Vincent Marciante
2021-04-24  1:04                     ` Randy Brukardt
2022-04-12 23:25                       ` use clauses Thomas
2022-04-13  1:05                         ` Randy Brukardt
2022-04-19  3:53  5%                       ` Thomas
2022-04-19  5:59  3%                         ` Randy Brukardt

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