Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

And on the seventh day, He exited from append mode.


devel / comp.lang.ada / String view of file

SubjectAuthor
* String view of fileJesper Quorning
+- Re: String view of fileG.B.
+* Re: String view of fileJeffrey R.Carter
|`* Re: String view of fileNiklas Holsti
| `* Re: String view of fileJeffrey R.Carter
|  `- Re: String view of fileNiklas Holsti
+- Re: String view of fileDmitry A. Kazakov
+- Re: String view of fileMarius Amado-Alves
+- Re: String view of fileQunying
+- Re: String view of fileGautier write-only address
`* Re: String view of fileJesper Quorning
 +- Re: String view of fileStephen Leake
 `* Re: String view of fileJeffrey R.Carter
  `- Re: String view of fileDmitry A. Kazakov

1
String view of file

<d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9047&group=comp.lang.ada#9047

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ae9:dc01:0:b0:6fa:aee9:9d40 with SMTP id q1-20020ae9dc01000000b006faaee99d40mr15479033qkf.194.1669019401262;
Mon, 21 Nov 2022 00:30:01 -0800 (PST)
X-Received: by 2002:a05:6214:11a6:b0:4bb:9163:8406 with SMTP id
u6-20020a05621411a600b004bb91638406mr3737528qvv.58.1669019401112; Mon, 21 Nov
2022 00:30:01 -0800 (PST)
Path: i2pn2.org!i2pn.org!news.swapon.de!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 21 Nov 2022 00:30:00 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=194.255.97.108; posting-account=hMbstgoAAAAIa4kxFYtvUVUHbE1RcZzT
NNTP-Posting-Host: 194.255.97.108
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Subject: String view of file
From: jesper.quorning@gmail.com (Jesper Quorning)
Injection-Date: Mon, 21 Nov 2022 08:30:01 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1488
 by: Jesper Quorning - Mon, 21 Nov 2022 08:30 UTC

I like to ask about

Is it possible to write something like this with ADA

```Ada
package my_rw_file is new file
(name => "whatever"
,mode => read_write
,implementation => standard -- or portable or fast
);
package as_string is new. xxx(from => my_rw_file);

-- parse (as_string);
package data is new parse (as_string, format => markdown); -- or whatever
```

Sorry, im new to ada

Jesper Q

Re: String view of file

<tlfsqd$3q843$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9051&group=comp.lang.ada#9051

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: bauhaus@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Mon, 21 Nov 2022 14:01:01 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <tlfsqd$3q843$2@dont-email.me>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Reply-To: nonlegitur@notmyhomepage.de
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Nov 2022 13:01:01 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="93133ae138dfc002920a9deef8052436";
logging-data="4006019"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+66op0PnO5uSTeSF7x3HWs40ONiP/qLhA="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.5.0
Cancel-Lock: sha1:cPrHAWjXPXjsnGvt35kyg8bOHpM=
In-Reply-To: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Content-Language: en-US
 by: G.B. - Mon, 21 Nov 2022 13:01 UTC

On 21.11.22 09:30, Jesper Quorning wrote:
> I like to ask about
>
> Is it possible to write something like this with ADA
>
> ```Ada
> package my_rw_file is new file
> (name => "whatever"
> ,mode => read_write
> ,implementation => standard -- or portable or fast
> );
> package as_string is new. xxx(from => my_rw_file);
>
> -- parse (as_string);
> package data is new parse (as_string, format => markdown); -- or whatever
> ```

Do you mean, gobble up a file into a string
and then parse that? Yes, that's possible
in a number of ways.

Re: String view of file

<tlfvjv$3q8j4$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9052&group=comp.lang.ada#9052

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Mon, 21 Nov 2022 14:48:47 +0100
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <tlfvjv$3q8j4$1@dont-email.me>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Nov 2022 13:48:48 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="656c6272d9b5e625a532946caa503524";
logging-data="4006500"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UsaqU5lSQCHdFDfyb3DtP0MalyOvWtHw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:AxDxf1p3tsgjEMOA4KzlfooeuYE=
In-Reply-To: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Mon, 21 Nov 2022 13:48 UTC

On 2022-11-21 09:30, Jesper Quorning wrote:
>
> Is it possible to write something like this with ADA

"Ada" is a woman's name, not an acronymn.

> package my_rw_file is new file
> (name => "whatever"
> ,mode => read_write
> ,implementation => standard -- or portable or fast
> );
> package as_string is new. xxx(from => my_rw_file);
>
> -- parse (as_string);
> package data is new parse (as_string, format => markdown); -- or whatever

If I presume that the '.' in the declaration of As_String is a typo, what you
have here is a sequence of related generic pkg instantiations, so you can write
this in Ada if you have the corresponding generic pkgs. I have no idea what the
result would provide.

If you want to read the arbitrary contents of a file into a String, that's
easily done:

with Ada.Directories;

package String_A_File is
use type Ada.Directories.File_Size;

function File_As_String (Name : in String) return String with
Pre => Ada.Directories.Exists (Name) and then
Ada.Directories.Size (Name) <=
Ada.Directories.File_Size (Integer'Last),
Post => File_As_String'Result'First = 1 and
File_As_String'Result'Last =
Integer (Ada.Directories.Size (Name) );
end String_A_File;

with Ada.Sequential_IO;

package body String_A_File is
function File_As_String (Name : in String) return String is
subtype FAS is String (1 .. Integer (Ada.Directories.Size (Name) ) );

package FAS_IO is new Ada.Sequential_IO (Element_Type => FAS);

File : FAS_IO.File_Type;
Result : FAS;
begin -- File_As_String
FAS_IO.Open (File => File, Mode => FAS_IO.In_File, Name => Name);
FAS_IO.Read (File => File, Item => Result;
FAS_IO.Close (File => File);

return Result;
end File_As_String;
end String_A_File;

This presumes that Result will fit on the stack. If that's likely to be a
problem, then you will need to use Unbounded_String and read the file Character
by Character.

--
Jeff Carter
"I have a very small head and I had
better learn to live with it ..."
Edsger Dijkstra
158

Re: String view of file

<tlg4sn$9es$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9053&group=comp.lang.ada#9053

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!qYcU9JfyUhY8OJVCu5UZdA.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Mon, 21 Nov 2022 16:18:48 +0100
Organization: Aioe.org NNTP Server
Message-ID: <tlg4sn$9es$1@gioia.aioe.org>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="9692"; posting-host="qYcU9JfyUhY8OJVCu5UZdA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.5.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Mon, 21 Nov 2022 15:18 UTC

On 2022-11-21 09:30, Jesper Quorning wrote:

> Is it possible to write something like this with ADA
>
> ```Ada
> package my_rw_file is new file
> (name => "whatever"
> ,mode => read_write
> ,implementation => standard -- or portable or fast
> );
> package as_string is new. xxx(from => my_rw_file);
>
> -- parse (as_string);
> package data is new parse (as_string, format => markdown); -- or whatever

It is difficult to guess what you want to achieve. What it looks to me
is a design opposite to the customary approach:

abstract code source (generic and/or tagged)
/ | \
/ | \
string text_file stream

Since string and file cannot be derived, in a tagged case some mix-in is
used.

The parser from simple-components has multi-line and single-line
sources. A single-line source can be set on a string. Multi-line source
is for files and streams.

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

Re: String view of file

<ju1l5eFhfo4U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9054&group=comp.lang.ada#9054

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!news.mb-net.net!open-news-network.org!news.mind.de!bolzen.all.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Mon, 21 Nov 2022 17:52:14 +0200
Organization: Tidorum Ltd
Lines: 70
Message-ID: <ju1l5eFhfo4U1@mid.individual.net>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
<tlfvjv$3q8j4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net UrD2FniMJDFXwpyVlJqKMA3GuQPzf5EvfhpWNAfEa69QiZfLG4
Cancel-Lock: sha1:dD4nMTodxvvHkMQLGVNJD51Cxds=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.4.1
Content-Language: en-US
In-Reply-To: <tlfvjv$3q8j4$1@dont-email.me>
 by: Niklas Holsti - Mon, 21 Nov 2022 15:52 UTC

On 2022-11-21 15:48, Jeffrey R.Carter wrote:
> On 2022-11-21 09:30, Jesper Quorning wrote:
>>
>> Is it possible to write something like this with ADA
>
> "Ada" is a woman's name, not an acronymn.
>
>> package my_rw_file is new file
>>    (name => "whatever"
>>     ,mode => read_write
>>     ,implementation => standard -- or portable or fast
>>    );
>> package as_string is new. xxx(from => my_rw_file);
>>
>> -- parse (as_string);
>> package data is new parse (as_string, format => markdown); -- or whatever
>
> If I presume that the '.' in the declaration of As_String is a typo,
> what you have here is a sequence of related generic pkg instantiations,
> so you can write this in Ada if you have the corresponding generic pkgs.
> I have no idea what the result would provide.
>
> If you want to read the arbitrary contents of a file into a String,
> that's easily done:
>
> with Ada.Directories;
>
> package String_A_File is
>    use type Ada.Directories.File_Size;
>
>    function File_As_String (Name : in String) return String with
>       Pre  => Ada.Directories.Exists (Name) and then
>               Ada.Directories.Size (Name) <=
>               Ada.Directories.File_Size (Integer'Last),
>       Post => File_As_String'Result'First = 1 and
>               File_As_String'Result'Last =
>               Integer (Ada.Directories.Size (Name) );
> end String_A_File;
>
> with Ada.Sequential_IO;
>
> package body String_A_File is
>    function File_As_String (Name : in String) return String is
>       subtype FAS is String (1 .. Integer (Ada.Directories.Size (Name)
> ) );
>
>       package FAS_IO is new Ada.Sequential_IO (Element_Type => FAS);
>
>       File   : FAS_IO.File_Type;
>       Result : FAS;
>    begin -- File_As_String
>       FAS_IO.Open (File => File, Mode => FAS_IO.In_File, Name => Name);
>       FAS_IO.Read (File => File, Item => Result;
>       FAS_IO.Close (File => File);
>
>       return Result;
>    end File_As_String;
> end String_A_File;
>
> This presumes that Result will fit on the stack. If that's likely to be
> a problem, then you will need to use Unbounded_String and read the file
> Character by Character.

For the OP's benefit (Jeffrey of course knows this): an alternative to
Unbounded_String is to allocate the Result string on the heap, and
return an access to the heap string. With that method, you can still
read the entire string with one call of FAS_IO.Read instead of Character
by Character.

Re: String view of file

<c83ee058-0977-45bf-9155-ffcf213fe198n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9055&group=comp.lang.ada#9055

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:8801:0:b0:6f8:4c19:659d with SMTP id k1-20020a378801000000b006f84c19659dmr3036585qkd.375.1669047065419;
Mon, 21 Nov 2022 08:11:05 -0800 (PST)
X-Received: by 2002:a05:622a:5a08:b0:3a5:7548:b41e with SMTP id
fy8-20020a05622a5a0800b003a57548b41emr18360520qtb.0.1669047065143; Mon, 21
Nov 2022 08:11:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 21 Nov 2022 08:11:05 -0800 (PST)
In-Reply-To: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=149.90.69.202; posting-account=3cDqWgoAAAAZXc8D3pDqwa77IryJ2nnY
NNTP-Posting-Host: 149.90.69.202
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c83ee058-0977-45bf-9155-ffcf213fe198n@googlegroups.com>
Subject: Re: String view of file
From: amado.alves@gmail.com (Marius Amado-Alves)
Injection-Date: Mon, 21 Nov 2022 16:11:05 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1225
 by: Marius Amado-Alves - Mon, 21 Nov 2022 16:11 UTC

Use Ada.Sequential_IO (Character), load to an Unbounded_String, save from a String or Unbounded_String.

Re: String view of file

<tlg9qg$3q8j4$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9056&group=comp.lang.ada#9056

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Mon, 21 Nov 2022 17:42:56 +0100
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <tlg9qg$3q8j4$2@dont-email.me>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
<tlfvjv$3q8j4$1@dont-email.me> <ju1l5eFhfo4U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 21 Nov 2022 16:42:57 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="656c6272d9b5e625a532946caa503524";
logging-data="4006500"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Llxdi4Cp4PgljYYc+E4NgXsljcmf5U38="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:BbJaWoz0Lt2GW9YM9Dk3ZtrQmCs=
Content-Language: en-US
In-Reply-To: <ju1l5eFhfo4U1@mid.individual.net>
 by: Jeffrey R.Carter - Mon, 21 Nov 2022 16:42 UTC

On 2022-11-21 16:52, Niklas Holsti wrote:
>
> For the OP's benefit (Jeffrey of course knows this): an alternative to
> Unbounded_String is to allocate the Result string on the heap, and return an
> access to the heap string. With that method, you can still read the entire
> string with one call of FAS_IO.Read instead of Character by Character.

I know it, and I deliberately reject it. Having access types in a pkg spec is
poor design. Delegating the associated memory management and all its
opportunities for error to the pkg client is very poor design.

If access types are used, they should be hidden and encapsulated with their
memory management. This makes it easier to get the memory management correct.
Since this is what using Unbounded_String does for you, I think it's better to
use it than to expend extra effort doing something similar.

--
Jeff Carter
"I have a very small head and I had
better learn to live with it ..."
Edsger Dijkstra
158

Re: String view of file

<ju1qr8Fhfo4U2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9057&group=comp.lang.ada#9057

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Mon, 21 Nov 2022 19:29:12 +0200
Organization: Tidorum Ltd
Lines: 19
Message-ID: <ju1qr8Fhfo4U2@mid.individual.net>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
<tlfvjv$3q8j4$1@dont-email.me> <ju1l5eFhfo4U1@mid.individual.net>
<tlg9qg$3q8j4$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net HYtzPAdNuuC+wGqTyp2DrQEHRBe7RWkFZxucfNzOLkQTskPhtW
Cancel-Lock: sha1:HUznoCNQM3OrzGNkNXUYrs01+8I=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.4.1
Content-Language: en-US
In-Reply-To: <tlg9qg$3q8j4$2@dont-email.me>
 by: Niklas Holsti - Mon, 21 Nov 2022 17:29 UTC

On 2022-11-21 18:42, Jeffrey R.Carter wrote:
> On 2022-11-21 16:52, Niklas Holsti wrote:
>>
>> For the OP's benefit (Jeffrey of course knows this): an alternative to
>> Unbounded_String is to allocate the Result string on the heap, and
>> return an access to the heap string. With that method, you can still
>> read the entire string with one call of FAS_IO.Read instead of
>> Character by Character.
>
> I know it, and I deliberately reject it. Having access types in a pkg
> spec is poor design. Delegating the associated memory management and all
> its opportunities for error to the pkg client is very poor design.

I agree in general, but there are design trade-offs that depend on
issues not made clear in the original question, such as the size of the
file and the performance requirements. So I thought that the OP should
know of the heap alternative, even if it has some poorer properties too.

Re: String view of file

<377733a1-b8ad-4497-9599-128ff8751bf0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9058&group=comp.lang.ada#9058

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:41d0:0:b0:39c:b702:8ec with SMTP id o16-20020ac841d0000000b0039cb70208ecmr17946332qtm.253.1669051789996;
Mon, 21 Nov 2022 09:29:49 -0800 (PST)
X-Received: by 2002:a05:620a:100f:b0:6fa:17e5:b62b with SMTP id
z15-20020a05620a100f00b006fa17e5b62bmr17402186qkj.676.1669051789675; Mon, 21
Nov 2022 09:29:49 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 21 Nov 2022 09:29:49 -0800 (PST)
In-Reply-To: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:569:5851:8a00:734d:b5e6:1d31:fef8;
posting-account=5q5YygoAAACq51EZyUjcDXZ0T5AqLVPG
NNTP-Posting-Host: 2001:569:5851:8a00:734d:b5e6:1d31:fef8
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <377733a1-b8ad-4497-9599-128ff8751bf0n@googlegroups.com>
Subject: Re: String view of file
From: zhu.qunying@gmail.com (Qunying)
Injection-Date: Mon, 21 Nov 2022 17:29:49 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1287
 by: Qunying - Mon, 21 Nov 2022 17:29 UTC

If you are using gnat with gnatcoll, then you may try its mmap facility, https://docs.adacore.com/gnatcoll-docs/mmap.html

Re: String view of file

<0db7e79c-b912-414f-86b7-474d76f5ba04n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9059&group=comp.lang.ada#9059

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:8807:0:b0:6f9:47f5:8ce9 with SMTP id k7-20020a378807000000b006f947f58ce9mr18413958qkd.578.1669067019709;
Mon, 21 Nov 2022 13:43:39 -0800 (PST)
X-Received: by 2002:ae9:d846:0:b0:6ec:5332:6ebd with SMTP id
u67-20020ae9d846000000b006ec53326ebdmr18527021qkf.0.1669067019542; Mon, 21
Nov 2022 13:43:39 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 21 Nov 2022 13:43:39 -0800 (PST)
In-Reply-To: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a02:1210:282b:1d00:3411:587c:44a0:3742;
posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG
NNTP-Posting-Host: 2a02:1210:282b:1d00:3411:587c:44a0:3742
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0db7e79c-b912-414f-86b7-474d76f5ba04n@googlegroups.com>
Subject: Re: String view of file
From: gautier_niouzes@hotmail.com (Gautier write-only address)
Injection-Date: Mon, 21 Nov 2022 21:43:39 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1361
 by: Gautier write-only a - Mon, 21 Nov 2022 21:43 UTC

You may be interested by this:
https://github.com/zertovitch/zip-ada/blob/master/zip_lib/zip_streams.ads#L148
It can be actually used out of the context of Zip archives.

Re: String view of file

<10f5dfec-32fb-4333-a9b6-2ee71c1871c0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9167&group=comp.lang.ada#9167

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:908:b0:6fc:c237:be0e with SMTP id v8-20020a05620a090800b006fcc237be0emr1261169qkv.213.1672616219408;
Sun, 01 Jan 2023 15:36:59 -0800 (PST)
X-Received: by 2002:ac8:6eca:0:b0:3a9:68ba:4c10 with SMTP id
f10-20020ac86eca000000b003a968ba4c10mr1292890qtv.676.1672616219182; Sun, 01
Jan 2023 15:36:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sun, 1 Jan 2023 15:36:59 -0800 (PST)
In-Reply-To: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=194.255.97.108; posting-account=hMbstgoAAAAIa4kxFYtvUVUHbE1RcZzT
NNTP-Posting-Host: 194.255.97.108
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <10f5dfec-32fb-4333-a9b6-2ee71c1871c0n@googlegroups.com>
Subject: Re: String view of file
From: jesper.quorning@gmail.com (Jesper Quorning)
Injection-Date: Sun, 01 Jan 2023 23:36:59 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 25
 by: Jesper Quorning - Sun, 1 Jan 2023 23:36 UTC

The original post was a bit of a mess, and I am not quite new to Ada. But I lack some skills regarding software construction and software engineering.

What I want goes something like this:
- Zero copy access to a (read-only) file.
- Get lines of file one by one as a stream of lines.
- Use a package instance as file representation.
- Stretch goal: Multiple implementations of File Instance (Standard, Fast, Compatible ..)

Refined version:
```Ada
package File
is new File_Instance
(Filename => "whatever",
Implementation => Standard);
---
for Line of File.As_Line_Stream loop
Parse (Line);
end loop;
```

I think Dewar has written something about string view of some data. I saw some tricky tricks in the GNAT.Snobol implementation. Links to papers anyone?

Sorry for the late follow-up.

/Jesper

Re: String view of file

<86h6x8pxx4.fsf@stephe-leake.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9168&group=comp.lang.ada#9168

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!gy7opw3oYmwPg+L8gXeD2w.user.46.165.242.75.POSTED!not-for-mail
From: stephen_leake@stephe-leake.org (Stephen Leake)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Mon, 02 Jan 2023 10:57:11 -0800
Organization: Aioe.org NNTP Server
Message-ID: <86h6x8pxx4.fsf@stephe-leake.org>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
<10f5dfec-32fb-4333-a9b6-2ee71c1871c0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="56535"; posting-host="gy7opw3oYmwPg+L8gXeD2w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:yN5V1Vbzh70OEdheWu+oKciE+P8=
 by: Stephen Leake - Mon, 2 Jan 2023 18:57 UTC

Jesper Quorning <jesper.quorning@gmail.com> writes:

> The original post was a bit of a mess, and I am not quite new to Ada. But I lack some skills regarding software construction and software engineering.
>
> What I want goes something like this:
> - Zero copy access to a (read-only) file.

You can use gnatcoll mmap to get a memory-mapped view of a file. To get
a zero-copy string, you'll have to find the line boundaries yourself,
and use unchecked-conversion on a string pointer, or an address clause
on a local variable.

> - Get lines of file one by one as a stream of lines.

'stream' has a specific meaning in Ada; better say "collection of lines"
here.

You can define an iterator for your File type.

- Use a package instance as file representation.

Why do you want to do this? The alternative is to define your own File
type, and provide an Open; then you can reuse that package for multiple
files. Closer to Ada standard practice for files.

- Stretch goal: Multiple implementations of File Instance (Standard, Fast, Compatible ..)

If you want to choose the implementation at compile time, you can use
separate bodies in implementation-specific directories, and choose the
directory in the project file.

If you want to chose the implementation at run time, you have to make
File a dispatching type. Then you pick the implementation via the
package name:

My_File : Files.Implementation_1.File;

> for Line of File.As_Line_Stream loop
> Parse (Line);
> end loop;

You probably know that you can get close to this in standard Ada, at the
cost of a copy:

while not End_of_file (File) loop
declare
Line : get_line (file);
begin
Parse (line);
end;
end loop;

An really aggressive optimizing compiler could get rid of the local
variable Line to avoid the copy, but it's not very likely.

This violates your requirement, but it could easily be that the copy is
very cheap; have you measured it in your actual application, and is
eliminating it worth the bother?

--
-- Stephe

Re: String view of file

<tp1lke$25ueb$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9174&group=comp.lang.ada#9174

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Tue, 3 Jan 2023 17:37:34 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <tp1lke$25ueb$1@dont-email.me>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
<10f5dfec-32fb-4333-a9b6-2ee71c1871c0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 3 Jan 2023 16:37:34 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4d05206906be75a48743a83be2bd051f";
logging-data="2292171"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19m1N+mUBFrJp8HLAZDEeeJ/Z6weMuLLNM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:I/x1Yyyn8p6e8djJfTgVAsdkZtM=
In-Reply-To: <10f5dfec-32fb-4333-a9b6-2ee71c1871c0n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Tue, 3 Jan 2023 16:37 UTC

On 2023-01-02 00:36, Jesper Quorning wrote:
>
> - Zero copy access to a (read-only) file.

So far as I know, any access to a file involves copying information from the
external medium into memory, so this may be impossible.

--
Jeff Carter
"Any noun can be verbed."
Alan Perlis
"Verbing weirds language."
Calvin and Hobbes
206

Re: String view of file

<tp1n3u$r3s$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9175&group=comp.lang.ada#9175

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!qYcU9JfyUhY8OJVCu5UZdA.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: String view of file
Date: Tue, 3 Jan 2023 18:02:54 +0100
Organization: Aioe.org NNTP Server
Message-ID: <tp1n3u$r3s$1@gioia.aioe.org>
References: <d1d4d819-8da2-4442-8bf9-a00c7ab6b4a5n@googlegroups.com>
<10f5dfec-32fb-4333-a9b6-2ee71c1871c0n@googlegroups.com>
<tp1lke$25ueb$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="27772"; posting-host="qYcU9JfyUhY8OJVCu5UZdA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Tue, 3 Jan 2023 17:02 UTC

On 2023-01-03 17:37, Jeffrey R.Carter wrote:
> On 2023-01-02 00:36, Jesper Quorning wrote:
>>
>> - Zero copy access to a (read-only) file.
>
> So far as I know, any access to a file involves copying information from
> the external medium into memory, so this may be impossible.

.... in many cases copying drastically improves performance, e.g.
caching, read ahead techniques etc.

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


devel / comp.lang.ada / String view of file

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor