Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

The only thing cheaper than hardware is talk.


devel / comp.lang.prolog / Towards OS Polyglott Prolog Systems

SubjectAuthor
* Towards OS Polyglott Prolog SystemsMostowski Collapse
`* Towards OS Polyglott Prolog SystemsMostowski Collapse
 `* Towards OS Polyglott Prolog SystemsMostowski Collapse
  `* Towards OS Polyglott Prolog SystemsMostowski Collapse
   `* Towards OS Polyglott Prolog SystemsAleksy Grabowski
    `* Towards OS Polyglott Prolog SystemsMostowski Collapse
     `* Towards OS Polyglott Prolog SystemsMostowski Collapse
      `- Towards OS Polyglott Prolog SystemsMostowski Collapse

1
Towards OS Polyglott Prolog Systems

<a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2412&group=comp.lang.prolog#2412

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a05:620a:2947:b0:6a3:a317:fa08 with SMTP id n7-20020a05620a294700b006a3a317fa08mr4096594qkp.746.1653387565050;
Tue, 24 May 2022 03:19:25 -0700 (PDT)
X-Received: by 2002:a0d:ff07:0:b0:2fe:d4ab:8652 with SMTP id
p7-20020a0dff07000000b002fed4ab8652mr25930479ywf.379.1653387564842; Tue, 24
May 2022 03:19:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Tue, 24 May 2022 03:19:24 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
Subject: Towards OS Polyglott Prolog Systems
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Tue, 24 May 2022 10:19:25 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mostowski Collapse - Tue, 24 May 2022 10:19 UTC

I noticed that in my new Dogelog Player the absolute_file_name/2
predicate might either return one of the two:

/* WSL */
?- absolute_file_name('baz.p', X).
X = '/mnt/c/foo/bar/baz.p'

/* Windows 10 */
?- absolute_file_name('baz.p', X).
X = 'C:\\foo\\bar\\baz.p'

So what to do? Normalize it and always use '/' and eliminate '\\' ?
This is what I did for formerly Jekejeke Prolog.

How do everything 100% in Prolog?

Re: Towards OS Polyglott Prolog Systems

<c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2413&group=comp.lang.prolog#2413

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a05:6214:d4d:b0:462:4986:f9bd with SMTP id 13-20020a0562140d4d00b004624986f9bdmr4711719qvr.70.1653387754991;
Tue, 24 May 2022 03:22:34 -0700 (PDT)
X-Received: by 2002:a05:6902:110e:b0:644:daff:1e6f with SMTP id
o14-20020a056902110e00b00644daff1e6fmr26798094ybu.569.1653387754827; Tue, 24
May 2022 03:22:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!peer03.ams4!peer.am4.highwinds-media.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.prolog
Date: Tue, 24 May 2022 03:22:34 -0700 (PDT)
In-Reply-To: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
References: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>
Subject: Re: Towards OS Polyglott Prolog Systems
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Tue, 24 May 2022 10:22:34 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2476
 by: Mostowski Collapse - Tue, 24 May 2022 10:22 UTC

Here comes last_sub_atom/5 to the rescue. The proposal is simple.
sub_atom/5 search forward, last_sub_atom/5 searches backward:

Here from ISO core standard:

?- sub_atom('baaab', X, Y, Z, 'aa').
X = 1, Y = 2, Z = 2;
X = 2, Y = 2, Z = 1;
fail.

?- sub_atom('abracadabra', X, Y, Z, 'abra').
X = 0, Y = 4, Z = 7;
X = 7, Y = 4, Z = 0.

And here the analogue searching backward:

?- last_sub_atom('baaab', X, Y, Z, 'aa').
X = 2, Y = 2, Z = 1;
X = 1, Y = 2, Z = 2;
fail.

?- last_sub_atom('abracadabra', X, Y, Z, 'abra').
X = 7, Y = 4, Z = 0;
X = 0, Y = 4, Z = 7.

I introduced this some years ago in formerly Jekejeke Prolog.
And since this week its also available in Dogelog Player.

Mostowski Collapse schrieb am Dienstag, 24. Mai 2022 um 12:19:25 UTC+2:
> I noticed that in my new Dogelog Player the absolute_file_name/2
> predicate might either return one of the two:
>
> /* WSL */
> ?- absolute_file_name('baz.p', X).
> X = '/mnt/c/foo/bar/baz.p'
>
> /* Windows 10 */
> ?- absolute_file_name('baz.p', X).
> X = 'C:\\foo\\bar\\baz.p'
>
> So what to do? Normalize it and always use '/' and eliminate '\\' ?
> This is what I did for formerly Jekejeke Prolog.
>
> How do everything 100% in Prolog?

Re: Towards OS Polyglott Prolog Systems

<b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2414&group=comp.lang.prolog#2414

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a05:620a:371b:b0:6a3:86f7:568b with SMTP id de27-20020a05620a371b00b006a386f7568bmr6106072qkb.690.1653388036622;
Tue, 24 May 2022 03:27:16 -0700 (PDT)
X-Received: by 2002:a25:2c4a:0:b0:64d:ff5d:f42b with SMTP id
s71-20020a252c4a000000b0064dff5df42bmr25896503ybs.418.1653388036468; Tue, 24
May 2022 03:27:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Tue, 24 May 2022 03:27:16 -0700 (PDT)
In-Reply-To: <c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
References: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com> <c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>
Subject: Re: Towards OS Polyglott Prolog Systems
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Tue, 24 May 2022 10:27:16 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mostowski Collapse - Tue, 24 May 2022 10:27 UTC

Here is a use case for last_sub_atom/5. Its useful to make an OS polyglott
Prolog system, at least polyglott among Unix, Windows and Mac. You
can get rid of Logtalks internal_os_path/2, which I think is a little

design flaw in my old Prolog system, which my new Prolog system tries
to avoid. One can do the following like here, maybe there are also other
agorithms based on last_sub_atom/5, but this is easiest to understand:

sys_file_parent(Path, Dir) :-
(last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
(last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
Pos is max(Pos1, Pos2), Pos \== -1, !,
Pos3 is Pos+1,
sub_atom(Path, 0, Pos3, _, Dir).
sys_file_parent(_, '').

sys_file_name(Path, Name) :-
(last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
(last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
Pos is max(Pos1, Pos2), Pos \== -1, !,
Pos3 is Pos+1,
atom_length(Path, Len),
Len2 is Len-Pos3,
sub_atom(Path, Pos3, Len2, _, Name).
sys_file_name(Path, Path).

Maybe regex could do the same. But can regex search backwards?
You would need a kind of greedy regex pattern, that nevertheless
has an alternative in it. And a regex library is more heavier, than some

last_sub_atom/5 which is still relative lightweight to provide, only
a variant of sub_atom/5.

Mostowski Collapse schrieb am Dienstag, 24. Mai 2022 um 12:22:35 UTC+2:
> Here comes last_sub_atom/5 to the rescue. The proposal is simple.
> sub_atom/5 search forward, last_sub_atom/5 searches backward:
>
> Here from ISO core standard:
>
> ?- sub_atom('baaab', X, Y, Z, 'aa').
> X = 1, Y = 2, Z = 2;
> X = 2, Y = 2, Z = 1;
> fail.
>
> ?- sub_atom('abracadabra', X, Y, Z, 'abra').
> X = 0, Y = 4, Z = 7;
> X = 7, Y = 4, Z = 0.
>
> And here the analogue searching backward:
>
> ?- last_sub_atom('baaab', X, Y, Z, 'aa').
> X = 2, Y = 2, Z = 1;
> X = 1, Y = 2, Z = 2;
> fail.
>
> ?- last_sub_atom('abracadabra', X, Y, Z, 'abra').
> X = 7, Y = 4, Z = 0;
> X = 0, Y = 4, Z = 7.
>
> I introduced this some years ago in formerly Jekejeke Prolog.
> And since this week its also available in Dogelog Player.
> Mostowski Collapse schrieb am Dienstag, 24. Mai 2022 um 12:19:25 UTC+2:
> > I noticed that in my new Dogelog Player the absolute_file_name/2
> > predicate might either return one of the two:
> >
> > /* WSL */
> > ?- absolute_file_name('baz.p', X).
> > X = '/mnt/c/foo/bar/baz.p'
> >
> > /* Windows 10 */
> > ?- absolute_file_name('baz.p', X).
> > X = 'C:\\foo\\bar\\baz.p'
> >
> > So what to do? Normalize it and always use '/' and eliminate '\\' ?
> > This is what I did for formerly Jekejeke Prolog.
> >
> > How do everything 100% in Prolog?

Re: Towards OS Polyglott Prolog Systems

<t6ict3$v2u2$1@solani.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2415&group=comp.lang.prolog#2415

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mostowski Collapse)
Newsgroups: comp.lang.prolog
Subject: Re: Towards OS Polyglott Prolog Systems
Date: Tue, 24 May 2022 12:43:47 +0200
Message-ID: <t6ict3$v2u2$1@solani.org>
References: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
<c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>
<b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 24 May 2022 10:43:47 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1018818"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Firefox/68.0 SeaMonkey/2.53.12
Cancel-Lock: sha1:Ns8Fh0QWYw1v/gW6Lqid+Nf6Qa8=
In-Reply-To: <b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>
X-User-ID: eJwFwYEBACAEBMCVKv9kHML+I3RH0a3PoFRwOH2yxW08PMqiLlPSnCpgIcfBELls3C6gnPawzlukHYn9AV6pFRo=
 by: Mostowski Collapse - Tue, 24 May 2022 10:43 UTC

Here are some example runs:

?- sys_file_parent('/mnt/c/foo/bar/baz.p', X).
X = '/mnt/c/foo/bar/'.

?- sys_file_name('C:/foo/bar/baz.p', X).
X = 'baz.p'.

?- sys_file_parent('C:\\foo\\bar\\baz.p', X).
X = 'C:\\foo\\bar\\'.

?- sys_file_name('C:\\foo\\bar\\baz.p', X).
X = 'baz.p'.

Its not the same as decompose_file_name/3 from Logtalk,
which is possibly also not OS polyglott. Its not the same
since it leaves the directory delemiter, either '/' or '\\'

at the end of the parent intact. So the reverse function
of this decomposition is simply atom_concat/3:

?- atom_concat('/mnt/c/foo/bar/', 'baz.p', X).
X = '/mnt/c/foo/bar/baz.p'.

?- atom_concat('C:\\foo\\bar\\', 'baz.p', X).
X = 'C:\\foo\\bar\\baz.p'.

Mostowski Collapse schrieb:
> Here is a use case for last_sub_atom/5. Its useful to make an OS polyglott
> Prolog system, at least polyglott among Unix, Windows and Mac. You
> can get rid of Logtalks internal_os_path/2, which I think is a little
>
> design flaw in my old Prolog system, which my new Prolog system tries
> to avoid. One can do the following like here, maybe there are also other
> agorithms based on last_sub_atom/5, but this is easiest to understand:
>
> sys_file_parent(Path, Dir) :-
> (last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
> (last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
> Pos is max(Pos1, Pos2), Pos \== -1, !,
> Pos3 is Pos+1,
> sub_atom(Path, 0, Pos3, _, Dir).
> sys_file_parent(_, '').
>
> sys_file_name(Path, Name) :-
> (last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
> (last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
> Pos is max(Pos1, Pos2), Pos \== -1, !,
> Pos3 is Pos+1,
> atom_length(Path, Len),
> Len2 is Len-Pos3,
> sub_atom(Path, Pos3, Len2, _, Name).
> sys_file_name(Path, Path).
>
> Maybe regex could do the same. But can regex search backwards?
> You would need a kind of greedy regex pattern, that nevertheless
> has an alternative in it. And a regex library is more heavier, than some
>
> last_sub_atom/5 which is still relative lightweight to provide, only
> a variant of sub_atom/5.

Re: Towards OS Polyglott Prolog Systems

<t6jc2b$gk$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2416&group=comp.lang.prolog#2416

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: hurufu@gmail.com (Aleksy Grabowski)
Newsgroups: comp.lang.prolog
Subject: Re: Towards OS Polyglott Prolog Systems
Date: Tue, 24 May 2022 21:35:39 +0200
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <t6jc2b$gk$1@dont-email.me>
References: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
<c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>
<b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>
<t6ict3$v2u2$1@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 24 May 2022 19:35:39 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="516c85b72db366b06562b2ad8402e7fe";
logging-data="532"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Bb0TNfk2NfOArqzmoE/ta"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:101.0) Gecko/20100101
Thunderbird/101.0
Cancel-Lock: sha1:36WpGnJIObhmQGztMT+qoZQfyI0=
In-Reply-To: <t6ict3$v2u2$1@solani.org>
Content-Language: en-US
 by: Aleksy Grabowski - Tue, 24 May 2022 19:35 UTC

Hello,

Why you didn't decide to use more classic dirname and basename? Meaning
would've been immediately obvious for any experienced programmer.

Best Regards,
Alex

On 5/24/22 12:43, Mostowski Collapse wrote:
> Here are some example runs:
>
> ?- sys_file_parent('/mnt/c/foo/bar/baz.p', X).
> X = '/mnt/c/foo/bar/'.
>
> ?- sys_file_name('C:/foo/bar/baz.p', X).
> X = 'baz.p'.
>
> ?- sys_file_parent('C:\\foo\\bar\\baz.p', X).
> X = 'C:\\foo\\bar\\'.
>
> ?- sys_file_name('C:\\foo\\bar\\baz.p', X).
> X = 'baz.p'.
>
> Its not the same as decompose_file_name/3 from Logtalk,
> which is possibly also not OS polyglott. Its not the same
> since it leaves the directory delemiter, either '/' or '\\'
>
> at the end of the parent intact. So the reverse function
> of this decomposition is simply atom_concat/3:
>
> ?- atom_concat('/mnt/c/foo/bar/', 'baz.p', X).
> X = '/mnt/c/foo/bar/baz.p'.
>
> ?- atom_concat('C:\\foo\\bar\\', 'baz.p', X).
> X = 'C:\\foo\\bar\\baz.p'.
>
> Mostowski Collapse schrieb:
>> Here is a use case for last_sub_atom/5. Its useful to make an OS
>> polyglott
>> Prolog system, at least polyglott among Unix, Windows and Mac. You
>> can get rid of Logtalks internal_os_path/2, which I think is a little
>>
>> design flaw in my old Prolog system, which my new Prolog system tries
>> to avoid. One can do the following like here, maybe there are also other
>> agorithms based on last_sub_atom/5, but this is easiest to understand:
>>
>> sys_file_parent(Path, Dir) :-
>>     (last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
>>     (last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
>>     Pos is max(Pos1, Pos2), Pos \== -1, !,
>>     Pos3 is Pos+1,
>>     sub_atom(Path, 0, Pos3, _, Dir).
>> sys_file_parent(_, '').
>>
>> sys_file_name(Path, Name) :-
>>     (last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
>>     (last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
>>     Pos is max(Pos1, Pos2), Pos \== -1, !,
>>     Pos3 is Pos+1,
>>     atom_length(Path, Len),
>>     Len2 is Len-Pos3,
>>     sub_atom(Path, Pos3, Len2, _, Name).
>> sys_file_name(Path, Path).
>>
>> Maybe regex could do the same. But can regex search backwards?
>> You would need a kind of greedy regex pattern, that nevertheless
>> has an alternative in it. And a regex library is more heavier, than some
>>
>> last_sub_atom/5 which is still relative lightweight to provide, only
>> a variant of sub_atom/5.

Re: Towards OS Polyglott Prolog Systems

<t6m74j$13kqg$1@solani.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2417&group=comp.lang.prolog#2417

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mostowski Collapse)
Newsgroups: comp.lang.prolog
Subject: Re: Towards OS Polyglott Prolog Systems
Date: Wed, 25 May 2022 23:29:57 +0200
Message-ID: <t6m74j$13kqg$1@solani.org>
References: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
<c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>
<b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>
<t6ict3$v2u2$1@solani.org> <t6jc2b$gk$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 25 May 2022 21:29:55 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1168208"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Firefox/68.0 SeaMonkey/2.53.12
Cancel-Lock: sha1:wRra/K+a1LYvnu4pfyllxjBfgdM=
X-User-ID: eJwFwYEBwCAIA7CXFNsC5zDQ/09YwqOtdogCH98d7HRc6FAVM7oruxscW9/uYHbVSr82Bg+FuSXT6xQR+AFM/BS9
In-Reply-To: <t6jc2b$gk$1@dont-email.me>
 by: Mostowski Collapse - Wed, 25 May 2022 21:29 UTC

Its different from dirname. The predicate sys_file_parent/2
gives a slashified directory:

?- sys_file_parent('/mnt/c/foo/bar/baz.p', X).
X = '/mnt/c/foo/bar/'.

Whareas the usual dirname would give it without slash.

?- file_directory_name('/mnt/c/foo/bar/baz.p', X).
X = '/mnt/c/foo/bar'.

file_directory_name/2 exits already in SWI-Prolog. But
it is not OS Polyglott:

?- file_directory_name('C:\\foo\\bar\\baz.p', X).
X = ('.').

Aleksy Grabowski schrieb:
> Hello,
>
> Why you didn't decide to use more classic dirname and basename? Meaning
> would've been immediately obvious for any experienced programmer.
>
> Best Regards,
> Alex
>
> On 5/24/22 12:43, Mostowski Collapse wrote:
>> Here are some example runs:
>>
>> ?- sys_file_parent('/mnt/c/foo/bar/baz.p', X).
>> X = '/mnt/c/foo/bar/'.
>>
>> ?- sys_file_name('C:/foo/bar/baz.p', X).
>> X = 'baz.p'.
>>
>> ?- sys_file_parent('C:\\foo\\bar\\baz.p', X).
>> X = 'C:\\foo\\bar\\'.
>>
>> ?- sys_file_name('C:\\foo\\bar\\baz.p', X).
>> X = 'baz.p'.
>>
>> Its not the same as decompose_file_name/3 from Logtalk,
>> which is possibly also not OS polyglott. Its not the same
>> since it leaves the directory delemiter, either '/' or '\\'
>>
>> at the end of the parent intact. So the reverse function
>> of this decomposition is simply atom_concat/3:
>>
>> ?- atom_concat('/mnt/c/foo/bar/', 'baz.p', X).
>> X = '/mnt/c/foo/bar/baz.p'.
>>
>> ?- atom_concat('C:\\foo\\bar\\', 'baz.p', X).
>> X = 'C:\\foo\\bar\\baz.p'.
>>
>> Mostowski Collapse schrieb:
>>> Here is a use case for last_sub_atom/5. Its useful to make an OS
>>> polyglott
>>> Prolog system, at least polyglott among Unix, Windows and Mac. You
>>> can get rid of Logtalks internal_os_path/2, which I think is a little
>>>
>>> design flaw in my old Prolog system, which my new Prolog system tries
>>> to avoid. One can do the following like here, maybe there are also other
>>> agorithms based on last_sub_atom/5, but this is easiest to understand:
>>>
>>> sys_file_parent(Path, Dir) :-
>>>     (last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
>>>     (last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
>>>     Pos is max(Pos1, Pos2), Pos \== -1, !,
>>>     Pos3 is Pos+1,
>>>     sub_atom(Path, 0, Pos3, _, Dir).
>>> sys_file_parent(_, '').
>>>
>>> sys_file_name(Path, Name) :-
>>>     (last_sub_atom(Path, Pos1, _, _, '/') -> true; Pos1 = -1),
>>>     (last_sub_atom(Path, Pos2, _, _, '\\') -> true; Pos2 = -1),
>>>     Pos is max(Pos1, Pos2), Pos \== -1, !,
>>>     Pos3 is Pos+1,
>>>     atom_length(Path, Len),
>>>     Len2 is Len-Pos3,
>>>     sub_atom(Path, Pos3, Len2, _, Name).
>>> sys_file_name(Path, Path).
>>>
>>> Maybe regex could do the same. But can regex search backwards?
>>> You would need a kind of greedy regex pattern, that nevertheless
>>> has an alternative in it. And a regex library is more heavier, than some
>>>
>>> last_sub_atom/5 which is still relative lightweight to provide, only
>>> a variant of sub_atom/5.
>
>

Re: Towards OS Polyglott Prolog Systems

<5b48fdd9-83e8-46dc-8bd4-97e4a176ecc4n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2419&group=comp.lang.prolog#2419

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a05:622a:613:b0:2f3:f918:280a with SMTP id z19-20020a05622a061300b002f3f918280amr43445652qta.216.1653897257576;
Mon, 30 May 2022 00:54:17 -0700 (PDT)
X-Received: by 2002:a25:6b12:0:b0:65c:d2b1:edb3 with SMTP id
g18-20020a256b12000000b0065cd2b1edb3mr4246928ybc.97.1653897257397; Mon, 30
May 2022 00:54:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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.prolog
Date: Mon, 30 May 2022 00:54:17 -0700 (PDT)
In-Reply-To: <t6m74j$13kqg$1@solani.org>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
References: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
<c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com> <b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>
<t6ict3$v2u2$1@solani.org> <t6jc2b$gk$1@dont-email.me> <t6m74j$13kqg$1@solani.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5b48fdd9-83e8-46dc-8bd4-97e4a176ecc4n@googlegroups.com>
Subject: Re: Towards OS Polyglott Prolog Systems
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Mon, 30 May 2022 07:54:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2525
 by: Mostowski Collapse - Mon, 30 May 2022 07:54 UTC

Question of the day:

> Look-ahead might not be a bad idea?

Rather an pretty bad idea without any benefit, since
the intended use case of non-det last_sub_atom/5, is
det lastIndexOf(_), namely like here, slightly optimized

version now with only one clause:

sys_file_name(Path, Name) :-
atom_length(Path, Len),
(last_sub_atom(Path, _, _, Pos1, '/') -> true; Pos1 = Len),
(last_sub_atom(Path, _, _, Pos2, '\\') -> true; Pos2 = Len),
Pos is min(Pos1, Pos2),
sub_atom(Path, _, Pos, 0, Name).

So there is a (->)/2, which cuts away last_sub_atom/5. So if
you do some extra work in last_sub_atom/5, you will:

- Not eliminate the choice point. For example if the file
name is "foo/bar/baz.p", the look ahead will find another
“/”, and you will get a choice point.

- Only generate overhead. Since you will internally search
the first “/” from left, and then the second “/” from left.

The only thing that removes the choice point is the
local cut in (->)/2. And one way to avoid some extra work
is to not have look-ahead.

Re: Towards OS Polyglott Prolog Systems

<t71tgp$182jl$1@solani.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=2420&group=comp.lang.prolog#2420

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mostowski Collapse)
Newsgroups: comp.lang.prolog
Subject: Re: Towards OS Polyglott Prolog Systems
Date: Mon, 30 May 2022 09:59:24 +0200
Message-ID: <t71tgp$182jl$1@solani.org>
References: <a44de1c0-be6a-40a1-ae3c-475999c47e37n@googlegroups.com>
<c8e316e1-ec6d-4552-bf74-4ef427377c11n@googlegroups.com>
<b9b91236-b503-4abc-8557-2d53ad230b92n@googlegroups.com>
<t6ict3$v2u2$1@solani.org> <t6jc2b$gk$1@dont-email.me>
<t6m74j$13kqg$1@solani.org>
<5b48fdd9-83e8-46dc-8bd4-97e4a176ecc4n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 May 2022 07:59:21 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1313397"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Firefox/68.0 SeaMonkey/2.53.12
Cancel-Lock: sha1:WifNjg4jYXevnPst3+a1240QKz8=
X-User-ID: eJwFwYkRADAEBMCWGM5TDkH/JWQXYmzP1WCKw1HOyqYMKMCazW9OOjPZRY2A7A16HUXuVXVHLRdzQ5uwD0bxFaU=
In-Reply-To: <5b48fdd9-83e8-46dc-8bd4-97e4a176ecc4n@googlegroups.com>
 by: Mostowski Collapse - Mon, 30 May 2022 07:59 UTC

BTW, its utterly trivial to implement last_sub_atom/5.
Just copy paste the implementation of sub_atom/5, and
change ++ into --, <= text.length into \>= 0, etc...

Extremly straight forward. Costs you less than a day.

Mostowski Collapse schrieb:
> Question of the day:
>
>> Look-ahead might not be a bad idea?
>
> Rather an pretty bad idea without any benefit, since
> the intended use case of non-det last_sub_atom/5, is
> det lastIndexOf(_), namely like here, slightly optimized
>
> version now with only one clause:
>
> sys_file_name(Path, Name) :-
> atom_length(Path, Len),
> (last_sub_atom(Path, _, _, Pos1, '/') -> true; Pos1 = Len),
> (last_sub_atom(Path, _, _, Pos2, '\\') -> true; Pos2 = Len),
> Pos is min(Pos1, Pos2),
> sub_atom(Path, _, Pos, 0, Name).
>
> So there is a (->)/2, which cuts away last_sub_atom/5. So if
> you do some extra work in last_sub_atom/5, you will:
>
> - Not eliminate the choice point. For example if the file
> name is "foo/bar/baz.p", the look ahead will find another
> “/”, and you will get a choice point.
>
> - Only generate overhead. Since you will internally search
> the first “/” from left, and then the second “/” from left.
>
> The only thing that removes the choice point is the
> local cut in (->)/2. And one way to avoid some extra work
> is to not have look-ahead.
>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor