comp.lang.ada
 help / color / mirror / Atom feed
* How to write "Hello" to a text file without a line terminator
@ 2016-08-12  4:05 Jerry
  2016-08-12  6:41 ` G.B.
  2016-08-12  7:23 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 28+ messages in thread
From: Jerry @ 2016-08-12  4:05 UTC (permalink / raw)


How does one write "Hello" to a text file without a line terminator?

Put("Hello");

adds a line terminator after "Hello".

Put("Hello");
Put(" world");

adds a line terminator after "world" but not after "Hello".


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12  4:05 How to write "Hello" to a text file without a line terminator Jerry
@ 2016-08-12  6:41 ` G.B.
  2016-08-12  7:23 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 28+ messages in thread
From: G.B. @ 2016-08-12  6:41 UTC (permalink / raw)


On 12.08.16 06:05, Jerry wrote:
> How does one write "Hello" to a text file without a line terminator?

Streaming a String to a file not handled by Text_IO should work
this way.


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12  4:05 How to write "Hello" to a text file without a line terminator Jerry
  2016-08-12  6:41 ` G.B.
@ 2016-08-12  7:23 ` Dmitry A. Kazakov
  2016-08-12  7:41   ` J-P. Rosen
                     ` (3 more replies)
  1 sibling, 4 replies; 28+ messages in thread
From: Dmitry A. Kazakov @ 2016-08-12  7:23 UTC (permalink / raw)


On 12/08/2016 06:05, Jerry wrote:
> How does one write "Hello" to a text file without a line terminator?
>
> Put("Hello");
>
> adds a line terminator after "Hello".

No, it does not, if you are talking about the standard library Put.

It is Put_Line that does.

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

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12  7:23 ` Dmitry A. Kazakov
@ 2016-08-12  7:41   ` J-P. Rosen
  2016-08-12  7:46     ` Jerry
  2016-08-12  7:44   ` Jerry
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 28+ messages in thread
From: J-P. Rosen @ 2016-08-12  7:41 UTC (permalink / raw)


Le 12/08/2016 à 09:23, Dmitry A. Kazakov a écrit :
> On 12/08/2016 06:05, Jerry wrote:
>> How does one write "Hello" to a text file without a line terminator?
>>
>> Put("Hello");
>>
>> adds a line terminator after "Hello".
> 
> No, it does not, if you are talking about the standard library Put.
> 
> It is Put_Line that does.
> 
More precisely, Put does not output a line terminator, but when your
program terminates either Text_IO itself or the OS may output a line
terminator "just in case".

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


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12  7:23 ` Dmitry A. Kazakov
  2016-08-12  7:41   ` J-P. Rosen
@ 2016-08-12  7:44   ` Jerry
  2016-08-12 17:34     ` Jeffrey R. Carter
  2016-08-12  7:46   ` Simon Wright
       [not found]   ` <noka54$ci$1@dont-email.me>
  3 siblings, 1 reply; 28+ messages in thread
From: Jerry @ 2016-08-12  7:44 UTC (permalink / raw)


On Friday, August 12, 2016 at 12:23:55 AM UTC-7, Dmitry A. Kazakov wrote:
> No, it does not, if you are talking about the standard library Put.
> 
> It is Put_Line that does.
> 

Both of these programs put a line terminator after Hello.

with Ada.Text_IO; use Ada.Text_IO;
procedure test_ada_eol is
begin
Put("Hello");
end test_ada_eol;


with Ada.Text_IO; use Ada.Text_IO;
procedure test_ada_eol_to_file is
   Test_Ada_EOL_File : Ada.Text_IO.File_Type;
begin
   Create(Test_Ada_EOL_File, Out_File, "Test Ada EOL.txt");    
   Put(Test_Ada_EOL_File, "Hello");
   Close(Test_Ada_EOL_File);
end test_ada_eol_to_file;


You can see it directly in the file or on a terminal, optinally with

$ ./test_ada_eol |od -a

Jerry


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12  7:23 ` Dmitry A. Kazakov
  2016-08-12  7:41   ` J-P. Rosen
  2016-08-12  7:44   ` Jerry
@ 2016-08-12  7:46   ` Simon Wright
       [not found]   ` <noka54$ci$1@dont-email.me>
  3 siblings, 0 replies; 28+ messages in thread
From: Simon Wright @ 2016-08-12  7:46 UTC (permalink / raw)


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

> On 12/08/2016 06:05, Jerry wrote:
>> How does one write "Hello" to a text file without a line terminator?
>>
>> Put("Hello");
>>
>> adds a line terminator after "Hello".
>
> No, it does not, if you are talking about the standard library Put.
>
> It is Put_Line that does.

Dmitry, Jerry has obviously seen this behaviour under _some_ circumstances,
so perhaps we should think about what those circumstances might have
been!

If the 'Put("Hello");' is the last output before the output file is
closed, probably by ending the program, then ARM A.10.2(3) applies:

   For the procedure Close: If the file has the current mode Out_File or
   Append_File, *has the effect of calling New_Page*, unless the current
   page is already terminated; then outputs a file terminator.

and ARM A.10.5(16) for New_Page:

   Operates on a file of mode Out_File or Append_File. *Outputs a line*
   *terminator if the current line is not terminated*, or if the current
   page is empty (that is, if the current column and line numbers are
   both equal to one). Then outputs a page terminator, which terminates
   the current page. Adds one to the current page number and sets the
   current column and line numbers to one.

Use Ada.Stream_IO, as already suggested, or GNAT.IO - of course the
latter isn't standardised nd its behaviour might change. 


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12  7:41   ` J-P. Rosen
@ 2016-08-12  7:46     ` Jerry
  0 siblings, 0 replies; 28+ messages in thread
From: Jerry @ 2016-08-12  7:46 UTC (permalink / raw)


On Friday, August 12, 2016 at 12:41:15 AM UTC-7, J-P. Rosen wrote:
> Le 12/08/2016 à 09:23, Dmitry A. Kazakov a écrit :

> More precisely, Put does not output a line terminator, but when your
> program terminates either Text_IO itself or the OS may output a line
> terminator "just in case".
> 
> -- 
> J-P. Rosen

Is this behavior implementation dependent?

Jerry


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

* Re: How to write "Hello" to a text file without a line terminator
       [not found]   ` <noka54$ci$1@dont-email.me>
@ 2016-08-12 13:44     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 28+ messages in thread
From: Dmitry A. Kazakov @ 2016-08-12 13:44 UTC (permalink / raw)


On 12/08/2016 12:58, G.B. wrote:
> On 12.08.16 09:23, Dmitry A. Kazakov wrote:
>> On 12/08/2016 06:05, Jerry wrote:
>>> How does one write "Hello" to a text file without a line terminator?
>>>
>>> Put("Hello");
>>>
>>> adds a line terminator after "Hello".
>>
>> No, it does not,
>
> Actually, it does in the case described,

Nope. Put does not do that. File close can do that, depending on the OS.

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


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12  7:44   ` Jerry
@ 2016-08-12 17:34     ` Jeffrey R. Carter
  2016-08-13  3:21       ` Jerry
  0 siblings, 1 reply; 28+ messages in thread
From: Jeffrey R. Carter @ 2016-08-12 17:34 UTC (permalink / raw)


On 08/12/2016 12:44 AM, Jerry wrote:
> 
> Both of these programs put a line terminator after Hello.
> 
> with Ada.Text_IO; use Ada.Text_IO;
> procedure test_ada_eol is
> begin
> Put("Hello");
> end test_ada_eol;
> 
> 
> with Ada.Text_IO; use Ada.Text_IO;
> procedure test_ada_eol_to_file is
>    Test_Ada_EOL_File : Ada.Text_IO.File_Type;
> begin
>    Create(Test_Ada_EOL_File, Out_File, "Test Ada EOL.txt");    
>    Put(Test_Ada_EOL_File, "Hello");
>    Close(Test_Ada_EOL_File);
> end test_ada_eol_to_file;

As Wright has pointed out, Close is defined to add a line terminator if the file
does not end with one. This explains the EOL for Test_Ada_Eol_To_File. In
Test_Ada_Eol, you have no call to Close. However, you'll note that File_Type is
defined as needing finalization [ARM A.10.1(86/2)]. While the effect of this
finalization is not defined, it's common to use it to close an open file. Every
Ada compiler I've used has done so. So this is probably the source of the EOL in
Test_Ada_Eol.

To obtain a file without a final EOL, you can use streams, as suggested, or
instantiate Ada.Sequential_IO for Character, which will require that you output
your Characters individually.

However, I don't know any portable way to write to standard output without
adding an EOL. Any output involving Ada.Text_IO.Standard_Output will invoke
Close when the file is finalized.

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

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-12 17:34     ` Jeffrey R. Carter
@ 2016-08-13  3:21       ` Jerry
  2016-08-13  4:23         ` Jeffrey R. Carter
  0 siblings, 1 reply; 28+ messages in thread
From: Jerry @ 2016-08-13  3:21 UTC (permalink / raw)


On Friday, August 12, 2016 at 10:34:19 AM UTC-7, Jeffrey R. Carter wrote:
> 
> To obtain a file without a final EOL, you can use streams, as suggested, or
> instantiate Ada.Sequential_IO for Character, which will require that you output
> your Characters individually.

Using Ada.Sequential_IO with Character works and seems easier than using Streams.

Using Ada.Sequential_IO instantiated for String puts out eight spaces before Hello or longer strings.
> 
> However, I don't know any portable way to write to standard output without
> adding an EOL. Any output involving Ada.Text_IO.Standard_Output will invoke
> Close when the file is finalized.
> 
That's OK for me, as I need to only write to an actual text file.

Thanks, everybody!

Jerry


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-13  3:21       ` Jerry
@ 2016-08-13  4:23         ` Jeffrey R. Carter
  2016-08-13  9:12           ` AdaMagica
  0 siblings, 1 reply; 28+ messages in thread
From: Jeffrey R. Carter @ 2016-08-13  4:23 UTC (permalink / raw)


On 08/12/2016 08:21 PM, Jerry wrote:
> 
> Using Ada.Sequential_IO instantiated for String puts out eight spaces before Hello or longer strings.

Are you sure they're spaces?

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


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-13  4:23         ` Jeffrey R. Carter
@ 2016-08-13  9:12           ` AdaMagica
  2016-08-13 18:03             ` Jeffrey R. Carter
  0 siblings, 1 reply; 28+ messages in thread
From: AdaMagica @ 2016-08-13  9:12 UTC (permalink / raw)


Am Samstag, 13. August 2016 06:23:16 UTC+2 schrieb Jeffrey R. Carter:
> On 08/12/2016 08:21 PM, Jerry wrote:
> > 
> > Using Ada.Sequential_IO instantiated for String puts out eight spaces before Hello or longer strings.
> 
> Are you sure they're spaces?

No, it's not spaces, it's the length of the string output: Since (on my machine), Integer'Size=32, it's four bytes.
Let'say, yout output
  Write (f, "abcdef");
You'll get (in bytes):
  6 0 0 0 97 98 99 100 101 102
And for a length of 256, you'll get:
  0 1 0 0 ...

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-13  9:12           ` AdaMagica
@ 2016-08-13 18:03             ` Jeffrey R. Carter
  2016-08-14  7:58               ` AdaMagica
  0 siblings, 1 reply; 28+ messages in thread
From: Jeffrey R. Carter @ 2016-08-13 18:03 UTC (permalink / raw)


On 08/13/2016 02:12 AM, AdaMagica wrote:
> 
> No, it's not spaces, it's the length of the string output: Since (on my machine), Integer'Size=32, it's four bytes.
> Let'say, yout output
>   Write (f, "abcdef");
> You'll get (in bytes):
>   6 0 0 0 97 98 99 100 101 102
> And for a length of 256, you'll get:
>   0 1 0 0 ...

I was thinking 2 4-byte bounds, but on my 64-bit machine with 32-bit Integer, I
get a 6 followed by 7 zeros:

with Ada.Sequential_IO;
with Ada.Text_IO;

procedure Str_Seq_IO is
   package Str_IO is new Ada.Sequential_IO (Element_Type => String);

   File : Str_IO.File_Type;
begin -- Str_Seq_IO
   Ada.Text_IO.Put_Line (Item => Integer'Image (Integer'Size) );
   Str_IO.Create (File => File, Mode => Str_IO.Out_File, Name => "junk");
   Str_IO.Write (File => File, Item => "abcdef");
   Str_IO.Close (File => File);
end Str_Seq_IO;

$ ./str_seq_io
 32
$ hd junk
00000000  06 00 00 00 00 00 00 00  61 62 63 64 65 66        |........abcdef|
0000000e

-- 
Jeff Carter
"Who wears beige to a bank robbery?"
Take the Money and Run
144


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-13 18:03             ` Jeffrey R. Carter
@ 2016-08-14  7:58               ` AdaMagica
  2016-08-14  8:30                 ` Simon Wright
  0 siblings, 1 reply; 28+ messages in thread
From: AdaMagica @ 2016-08-14  7:58 UTC (permalink / raw)


Am Samstag, 13. August 2016 20:03:51 UTC+2 schrieb Jeffrey R. Carter:
> $ ./str_seq_io
>  32
> $ hd junk
> 00000000  06 00 00 00 00 00 00 00  61 62 63 64 65 66        |........abcdef|
???? -- Letters 'A' through 'Z' are at positions 65 through 90 ????
> 0000000e

Obviously on your 64-bit machine, length is output in 64 bits, although Integer has only 32.

But what's 00000000 and 0000000e?


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  7:58               ` AdaMagica
@ 2016-08-14  8:30                 ` Simon Wright
  2016-08-14  8:54                   ` Dmitry A. Kazakov
                                     ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Simon Wright @ 2016-08-14  8:30 UTC (permalink / raw)


AdaMagica <christ-usch.grein@t-online.de> writes:

> Am Samstag, 13. August 2016 20:03:51 UTC+2 schrieb Jeffrey R. Carter:
>> $ ./str_seq_io
>>  32
>> $ hd junk
>> 00000000  06 00 00 00 00 00 00 00  61 62 63 64 65 66        |........abcdef|
> ???? -- Letters 'A' through 'Z' are at positions 65 through 90 ????

'hd' is (probably) Carter's alias for 'hexdump -C' - the values are in
hex. And, those are letters 'a' .. 'z', not 'A' .. 'Z'.

>> 0000000e
> [...]
> But what's 00000000 and 0000000e?

The (hex) offsets within the file.

> Obviously on your 64-bit machine, length is output in 64 bits,
> although Integer has only 32.

Come to think of it, what would the use case be for instantiating
Sequential (or Direct) IO with an unconstrained type? they both have
only procedural forms for Read, so how could you ever retrieve a value?

GNAT has

   package Ada.Sequential_IO is

      pragma Compile_Time_Warning
        (Element_Type'Has_Access_Values,
         "Element_Type for Sequential_IO instance has access values");

      pragma Compile_Time_Warning
        (Element_Type'Has_Tagged_Values,
         "Element_Type for Sequential_IO instance has tagged values");

so should we ask for GNAT to do similar with "not
Element_Type'Constrained"? (use of 'Constrained with a type is a GNAT
extension).


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  8:30                 ` Simon Wright
@ 2016-08-14  8:54                   ` Dmitry A. Kazakov
  2016-08-14  9:40                     ` Simon Wright
  2016-08-14 13:28                   ` AdaMagica
                                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 28+ messages in thread
From: Dmitry A. Kazakov @ 2016-08-14  8:54 UTC (permalink / raw)


On 2016-08-14 10:30, Simon Wright wrote:

> Come to think of it, what would the use case be for instantiating
> Sequential (or Direct) IO with an unconstrained type?

Direct_IO requires a constrained type.

> they both have
> only procedural forms for Read, so how could you ever retrieve a value?

Does it matter? It is not portable to use anyway.

All that needed is pragma Assert that Stream_Element'Size = 8 and 
Stream_Element_Array I/O.

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


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  8:54                   ` Dmitry A. Kazakov
@ 2016-08-14  9:40                     ` Simon Wright
  2016-08-14 10:17                       ` Dmitry A. Kazakov
  2016-08-15 23:35                       ` Randy Brukardt
  0 siblings, 2 replies; 28+ messages in thread
From: Simon Wright @ 2016-08-14  9:40 UTC (permalink / raw)


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

> On 2016-08-14 10:30, Simon Wright wrote:
>
>> Come to think of it, what would the use case be for instantiating
>> Sequential (or Direct) IO with an unconstrained type?
>
> Direct_IO requires a constrained type.

So it does. And Sequential_IO explicitly permists an unconstrained
type. Still,

>> they both have
>> only procedural forms for Read, so how could you ever retrieve a value?
>
> Does it matter? It is not portable to use anyway.

I am saying that (it seems to me that) it is impossible to read back
from Sequential_IO with an unconstrained type even on the same machine
with the same compiler.

> All that needed is pragma Assert that Stream_Element'Size = 8 and
> Stream_Element_Array I/O.

Ada.Streams.Stream_IO & String'Write is even simpler in 99.9% of cases.


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  9:40                     ` Simon Wright
@ 2016-08-14 10:17                       ` Dmitry A. Kazakov
  2016-08-14 11:28                         ` Simon Wright
  2016-08-15 23:35                       ` Randy Brukardt
  1 sibling, 1 reply; 28+ messages in thread
From: Dmitry A. Kazakov @ 2016-08-14 10:17 UTC (permalink / raw)


On 2016-08-14 11:40, Simon Wright wrote:

> I am saying that (it seems to me that) it is impossible to read back
> from Sequential_IO with an unconstrained type even on the same machine
> with the same compiler.

You can through S'Input. Read is just a wrapper for S'Read, it could 
have been omitted too.

And regarding the design it should have been:

package Ada.Streams is
    type Abstract_Root_Stream_Type is limited interface;
    type Root_Stream_Type is new Abstract_Root_Stream_Type with private;

...
package Ada.Streams.Stream_IO is
    type File_Type is new Abstract_Root_Stream_Type with private;

and no

function Stream (File : in File_Type) return Stream_Access;

>> All that needed is pragma Assert that Stream_Element'Size = 8 and
>> Stream_Element_Array I/O.
>
> Ada.Streams.Stream_IO & String'Write is even simpler in 99.9% of cases.

Yes, when String'Component_Size = Stream_Element_Size = 8.

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

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14 10:17                       ` Dmitry A. Kazakov
@ 2016-08-14 11:28                         ` Simon Wright
  2016-08-14 13:31                           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 28+ messages in thread
From: Simon Wright @ 2016-08-14 11:28 UTC (permalink / raw)


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

> On 2016-08-14 11:40, Simon Wright wrote:
>
>> I am saying that (it seems to me that) it is impossible to read back
>> from Sequential_IO with an unconstrained type even on the same machine
>> with the same compiler.
>
> You can through S'Input. Read is just a wrapper for S'Read, it could
> have been omitted too.

Sequential_IO (String) outputs the length in 8 bytes (on macOS, anyway);
String'Output outputs the first and last indices as 4 bytes each.  


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  8:30                 ` Simon Wright
  2016-08-14  8:54                   ` Dmitry A. Kazakov
@ 2016-08-14 13:28                   ` AdaMagica
  2016-08-14 13:54                     ` Simon Wright
  2016-08-14 17:05                     ` Jeffrey R. Carter
  2016-08-14 13:32                   ` AdaMagica
  2016-08-14 16:39                   ` Jeffrey R. Carter
  3 siblings, 2 replies; 28+ messages in thread
From: AdaMagica @ 2016-08-14 13:28 UTC (permalink / raw)


Am Sonntag, 14. August 2016 10:30:15 UTC+2 schrieb Simon Wright:
> Come to think of it, what would the use case be for instantiating
> Sequential (or Direct) IO with an unconstrained type? they both have
> only procedural forms for Read, so how could you ever retrieve a value?

No problem for a type like this (without the defaulted discriminant, you'll have indeed a problem, as for strings):

  type Disc is (A, B, C, D);
  type Rec (X: Disc := A) is record
    case X is
      when A => I: Integer;
      when B => F: Float;
      when C => B: Boolean;
      when D => null;
    end case;
  end record;

  package Req_Sequential_IO is new Ada.Sequential_IO (Rec);
  use Req_Sequential_IO;
  
  procedure Create is
    f:file_Type;
  begin
    create(f,out_file,"Rec");
    Write (f, (A, 42));
    Write (f, (C, False));
    Write (f, (X=>D));
    write (f, (B, -42.0));
    close(f);
  end Create;

  procedure Read is
    f:file_Type;
    R: Rec;
  begin
    open(f,in_file,"Rec");
    loop
      Read(f,R);
      exit when End_of_File(f);
    end loop;
    close(f);
  end Read;


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14 11:28                         ` Simon Wright
@ 2016-08-14 13:31                           ` Dmitry A. Kazakov
  0 siblings, 0 replies; 28+ messages in thread
From: Dmitry A. Kazakov @ 2016-08-14 13:31 UTC (permalink / raw)


On 2016-08-14 13:28, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> On 2016-08-14 11:40, Simon Wright wrote:
>>
>>> I am saying that (it seems to me that) it is impossible to read back
>>> from Sequential_IO with an unconstrained type even on the same machine
>>> with the same compiler.
>>
>> You can through S'Input. Read is just a wrapper for S'Read, it could
>> have been omitted too.
>
> Sequential_IO (String) outputs the length in 8 bytes (on macOS, anyway);
> String'Output outputs the first and last indices as 4 bytes each.

Onr my 64-bit Windows 10 box Sequential_IO (String) Write makes a 4 
bytes prefix (32-bit length, I guess). E.g. "abcd" it does 4, 0, 0, 0, 
'a', 'b', 'c', 'd'. I think it depends on whether the GNAT is targeted 
for 32- or 64-bit and not on the actual OS. What a mess!

All this is just wrong. It should have been 'a', 'b', 'c', 'd'. Though 
RM conveniently tells nothing about its semantics, the name and 
parameters profile suggests one of S'Write, no constraints read/written.

But honestly who would ever care? The package is clearly obsolete and 
under/ill-specified. Should never be used anywhere.

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

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  8:30                 ` Simon Wright
  2016-08-14  8:54                   ` Dmitry A. Kazakov
  2016-08-14 13:28                   ` AdaMagica
@ 2016-08-14 13:32                   ` AdaMagica
  2016-08-14 16:39                   ` Jeffrey R. Carter
  3 siblings, 0 replies; 28+ messages in thread
From: AdaMagica @ 2016-08-14 13:32 UTC (permalink / raw)


Am Sonntag, 14. August 2016 10:30:15 UTC+2 schrieb Simon Wright:
> Come to think of it, what would the use case be for instantiating
> Sequential (or Direct) IO with an unconstrained type? they both have
> only procedural forms for Read, so how could you ever retrieve a value?

Direct_IO needs fixed sizes, so cannot use unconstrained types.


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14 13:28                   ` AdaMagica
@ 2016-08-14 13:54                     ` Simon Wright
  2016-08-14 17:05                     ` Jeffrey R. Carter
  1 sibling, 0 replies; 28+ messages in thread
From: Simon Wright @ 2016-08-14 13:54 UTC (permalink / raw)


AdaMagica <christ-usch.grein@t-online.de> writes:

> Am Sonntag, 14. August 2016 10:30:15 UTC+2 schrieb Simon Wright:
>> Come to think of it, what would the use case be for instantiating
>> Sequential (or Direct) IO with an unconstrained type? they both have
>> only procedural forms for Read, so how could you ever retrieve a value?
>
> No problem for a type like this (without the defaulted discriminant, you'll have indeed a problem, as for strings):
>
>   type Disc is (A, B, C, D);
>   type Rec (X: Disc := A) is record
>     case X is
>       when A => I: Integer;
>       when B => F: Float;
>       when C => B: Boolean;
>       when D => null;
>     end case;
>   end record;

OK, got it.

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  8:30                 ` Simon Wright
                                     ` (2 preceding siblings ...)
  2016-08-14 13:32                   ` AdaMagica
@ 2016-08-14 16:39                   ` Jeffrey R. Carter
  3 siblings, 0 replies; 28+ messages in thread
From: Jeffrey R. Carter @ 2016-08-14 16:39 UTC (permalink / raw)


On 08/14/2016 01:30 AM, Simon Wright wrote:
> AdaMagica <christ-usch.grein@t-online.de> writes:
> 
>> Am Samstag, 13. August 2016 20:03:51 UTC+2 schrieb Jeffrey R. Carter:
>>> $ ./str_seq_io
>>>  32
>>> $ hd junk
>>> 00000000  06 00 00 00 00 00 00 00  61 62 63 64 65 66        |........abcdef|
>> ???? -- Letters 'A' through 'Z' are at positions 65 through 90 ????
> 
> 'hd' is (probably) Carter's alias for 'hexdump -C' - the values are in
> hex. And, those are letters 'a' .. 'z', not 'A' .. 'Z'.

Close. "man hd" gives (Linux Mint 18)

HEXDUMP(1)                BSD General Commands Manual               HEXDUMP(1)

NAME
     hexdump, hd — ASCII, decimal, hexadecimal, octal dump

SYNOPSIS
     hexdump [-bcCdovx] [-e format_string] [-f format_file] [-n length]
             [-s skip] file ...
     hd [-bcdovx] [-e format_string] [-f format_file] [-n length] [-s skip]
             file ...

...

     -C      Canonical hex+ASCII display.  Display the input offset in hexa‐
             decimal, followed by sixteen space-separated, two column, hexa‐
             decimal bytes, followed by the same sixteen bytes in %_p format
             enclosed in ``|'' characters.

             Calling the command hd implies this option.

And 16#61# = 10#97# = Character'Pos ('a').

Sorry for confusing AdaMagica.

> Come to think of it, what would the use case be for instantiating
> Sequential (or Direct) IO with an unconstrained type? they both have
> only procedural forms for Read, so how could you ever retrieve a value?

The unknown-discriminants notation [(<>)] indicates that indefinite types may be
used. String is both indefinite and unconstrained, but a variant record with a
defaulted discriminant is definite and unconstrained. I don't see much use for
Sequential_IO with an indefinite type. On reading, the objects read into would
have to match the objects written.

-- 
Jeff Carter
"Frankie Wolf, wanted by Federal authorities for
dancing with a mailman."
Take the Money and Run
143

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14 13:28                   ` AdaMagica
  2016-08-14 13:54                     ` Simon Wright
@ 2016-08-14 17:05                     ` Jeffrey R. Carter
  2016-08-14 18:26                       ` AdaMagica
  1 sibling, 1 reply; 28+ messages in thread
From: Jeffrey R. Carter @ 2016-08-14 17:05 UTC (permalink / raw)


On 08/14/2016 06:28 AM, AdaMagica wrote:
> 
> No problem for a type like this (without the defaulted discriminant, you'll have indeed a problem, as for strings):
> 
>   type Disc is (A, B, C, D);
>   type Rec (X: Disc := A) is record
>     case X is
>       when A => I: Integer;
>       when B => F: Float;
>       when C => B: Boolean;
>       when D => null;
>     end case;
>   end record;

This type is definite, unlike String, which is indefinite. Both Sequential_IO
and Direct_IO can have unconstrained elements, but Sequential_IO allows an
indefinite subtype for the elements, while Direct_IO requires a definite
subtype. The definition of (in)definite subtypes is given in ARM 3.3(23/3): "A
subtype is an indefinite subtype if it is an unconstrained array subtype, or if
it has unknown discriminants or unconstrained discriminants without defaults
(see 3.7); otherwise, the subtype is a definite subtype (all elementary subtypes
are definite subtypes)."

In practice, a subtype S is definite if you can declare an object of the subtype
without adding any additional information:

V : S:

and indefinite otherwise.

-- 
Jeff Carter
"Frankie Wolf, wanted by Federal authorities for
dancing with a mailman."
Take the Money and Run
143


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14 17:05                     ` Jeffrey R. Carter
@ 2016-08-14 18:26                       ` AdaMagica
  2016-08-14 19:19                         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 28+ messages in thread
From: AdaMagica @ 2016-08-14 18:26 UTC (permalink / raw)


Am Sonntag, 14. August 2016 19:05:16 UTC+2 schrieb Jeffrey R. Carter:
> In practice, a subtype S is definite if you can declare an object of the subtype
> without adding any additional information:
> 
> V : S:
> 
> and indefinite otherwise.

You're right, I was confused with respect to unconstrained vs. indefinit. The latter is quite impossible to read in general, except when you know beforehand what to read.


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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14 18:26                       ` AdaMagica
@ 2016-08-14 19:19                         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 28+ messages in thread
From: Dmitry A. Kazakov @ 2016-08-14 19:19 UTC (permalink / raw)


On 2016-08-14 20:26, AdaMagica wrote:
> Am Sonntag, 14. August 2016 19:05:16 UTC+2 schrieb Jeffrey R. Carter:
>> In practice, a subtype S is definite if you can declare an object of the subtype
>> without adding any additional information:
>>
>> V : S:
>>
>> and indefinite otherwise.
>
> You're right, I was confused with respect to unconstrained vs.
> indefinit. The latter is quite impossible to read in general, except
> when you know beforehand what to read.

There is no difference in that regard. You need to know the constraints 
in order to read an instance. The real difference is whether 
discriminant is a constraint or a part of the value.

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

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

* Re: How to write "Hello" to a text file without a line terminator
  2016-08-14  9:40                     ` Simon Wright
  2016-08-14 10:17                       ` Dmitry A. Kazakov
@ 2016-08-15 23:35                       ` Randy Brukardt
  1 sibling, 0 replies; 28+ messages in thread
From: Randy Brukardt @ 2016-08-15 23:35 UTC (permalink / raw)


"Simon Wright" <simon@pushface.org> wrote in message 
news:lyr39r1yeo.fsf@pushface.org...
...
> I am saying that (it seems to me that) it is impossible to read back
> from Sequential_IO with an unconstrained type even on the same machine
> with the same compiler.

No problem for an unconstrained record type with defaults. I agree it 
wouldn't be useful for an array.

                              Randy.



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

end of thread, other threads:[~2016-08-15 23:35 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-12  4:05 How to write "Hello" to a text file without a line terminator Jerry
2016-08-12  6:41 ` G.B.
2016-08-12  7:23 ` Dmitry A. Kazakov
2016-08-12  7:41   ` J-P. Rosen
2016-08-12  7:46     ` Jerry
2016-08-12  7:44   ` Jerry
2016-08-12 17:34     ` Jeffrey R. Carter
2016-08-13  3:21       ` Jerry
2016-08-13  4:23         ` Jeffrey R. Carter
2016-08-13  9:12           ` AdaMagica
2016-08-13 18:03             ` Jeffrey R. Carter
2016-08-14  7:58               ` AdaMagica
2016-08-14  8:30                 ` Simon Wright
2016-08-14  8:54                   ` Dmitry A. Kazakov
2016-08-14  9:40                     ` Simon Wright
2016-08-14 10:17                       ` Dmitry A. Kazakov
2016-08-14 11:28                         ` Simon Wright
2016-08-14 13:31                           ` Dmitry A. Kazakov
2016-08-15 23:35                       ` Randy Brukardt
2016-08-14 13:28                   ` AdaMagica
2016-08-14 13:54                     ` Simon Wright
2016-08-14 17:05                     ` Jeffrey R. Carter
2016-08-14 18:26                       ` AdaMagica
2016-08-14 19:19                         ` Dmitry A. Kazakov
2016-08-14 13:32                   ` AdaMagica
2016-08-14 16:39                   ` Jeffrey R. Carter
2016-08-12  7:46   ` Simon Wright
     [not found]   ` <noka54$ci$1@dont-email.me>
2016-08-12 13:44     ` Dmitry A. Kazakov

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