• More best kept secrets of Prolog: Pattern Matching

    From Mostowski Collapse@21:1/5 to All on Thu Sep 2 17:24:41 2021
    Everybody loves pattern matching. Languages
    like Python, release 3.10, even provide it
    now. There is now a match/case statement

    in Python. But Prolog users will scratch their
    head. Will my if-then-else be as fast as a
    imperative switch jump table lookup?

    Dogelog runtime has stepped up its game
    concerning pattern matching. It now provides
    ECLiPSe Prolog disjunction and if-then-else

    indexing. Take this example:

    ?- [user].
    foo(X,Y) :- X=baz, Y=2; X=bar -> Y=1.

    SWI-Prolog leaves a choice point, so no
    clause indexing used:

    /* SWI-Prolog 8.3.26 */
    ?- foo(baz,Z).
    Z = 2 ; %%% Spurious Choice Point
    false.

    Dogelog doesn't leave a choice point, since
    it can index the disjunction and if-then-else:

    /* Dogelog Runtime 0.9.3 */
    ?- foo(baz,Z).
    Z = 2. %%% No Choice Point

    See also:

    Preview: Dogelog disjunction and if-then-else indexing. (Jekejeke) https://twitter.com/dogelogch/status/1433446729974796293

    Preview: Dogelog disjunction and if-then-else indexing. (Jekejeke) https://www.facebook.com/groups/dogelog

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to burs...@gmail.com on Fri Sep 3 03:57:11 2021
    On Thursday, 2 September 2021 at 17:24:43 UTC+2, burs...@gmail.com wrote: <snip>
    Dogelog runtime has stepped up its game
    concerning pattern matching. It now provides
    ECLiPSe Prolog disjunction and if-then-else

    indexing. Take this example:

    ?- [user].
    foo(X,Y) :- X=baz, Y=2; X=bar -> Y=1.

    SWI-Prolog leaves a choice point, so no
    clause indexing used:

    /* SWI-Prolog 8.3.26 */
    ?- foo(baz,Z).
    Z = 2 ; %%% Spurious Choice Point
    false.

    Dogelog doesn't leave a choice point, since
    it can index the disjunction and if-then-else:

    I think it's unfair to call it spurious, it's you who are doing something extra-ordinary.

    And something that may not always be desirable: that optimisation disallows the easy/clean way to keep the choice point should one want to, which is with code as above vs using constants directly as head arguments. (And as seen in the example below.)

    Use cases for precise control of language features? Didactics and research spring to mind, and even more should certified software, also scenarios like coordinating concurrency, etc., there may be more. Anyway, clause indexing changes the semantics of
    programs. Just consider this:

    ```
    % SWI-Prolog 8.2.0

    ?- retractall(f(_)).
    true.
    ?- assertz(f(X) :- X = 1), assertz(f(X) :- X = 2).
    true.
    ?- X = 1, call_cleanup(f(X), Det=yes).
    X = 1 ;
    false.

    ?- retractall(f(_)).
    true.
    ?- assertz(f(1)), assertz(f(2)).
    true.
    ?- X = 1, call_cleanup(f(X), Det=yes).
    X = 1,
    Det = yes.

    ```

    Along that line, I'd rather wish we could attribute predicates to have control on indexing (maybe just an extension to meta_predicate/1, it's simply an indexing option per argument, whether to index it or not, or even, in more sophisticated
    implementations, up to which nested level to index: 0 for the head, 1 for the body, 2 for a body goal's body, etc. In that scheme, your current implementation is like indexing on all arguments at level 1), sure possibly with reasonable defaults: then it'
    d be all good, including the extra-ordinary...

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Julio Di Egidio on Fri Sep 3 05:05:47 2021
    On Friday, 3 September 2021 at 12:57:12 UTC+2, Julio Di Egidio wrote:
    On Thursday, 2 September 2021 at 17:24:43 UTC+2, burs...@gmail.com wrote:

    In that scheme, your current implementation is like indexing on all arguments at level 1

    ...with special provision for goals matching 'if', where you go down into the premise... (If that's in fact what you do.)

    If's are special, but all if's (well, I am not actually sure about the soft-cuts) boil down to cuts, and I don't think cuts add substantial complication to the scheme I have drafted: I should think more about it, but my first guess is that cuts could
    simply be ignored.

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Fri Sep 3 06:27:34 2021
    What is novel in the Dogelog runtime, you somehow have
    full control on how the index key is computed. Since Dogelog
    runtime itself is written in Prolog itself, assertz/1 and ensure_loaded/1

    are also written in Prolog itself. It was not clear that some of
    the index key computation can in fact be "out sourced" into
    Prolog itself. But somehow I managed to do that, for the simple

    scenario of first argument indexing. Currently the index key
    computation for a clause is seen here:

    - index_clause(R, O):
    The predicate succeeds in O with the indexing value of the clause with head R.
    - index_static(R, L, O):
    The predicate succeeds in O with the indexing value of the clause with head R and body L.

    https://gist.github.com/jburse/d10ac03547a9d59b858c2ef2342e488b#file-index-pl

    You find it also on GitHub in compile.p:

    https://github.com/jburse/dogelog-moon/tree/main/devel/transpiler

    index_clause/2 is the classical first argument index key.
    index_static/3 implements a very simple clause body index key.
    As you see it has an additional parameter, you need to

    pass the body as well, since it is clause **body** indexing.

    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 15:18:48 UTC+2:
    Try SWI-Prolog 8.3.xx something, this test case:

    f(X) :- X = 1.
    f(X) :- X = 2.

    ?- f(1).
    %%% what do you see here, with devel SWI-Prolog?

    Will not anymore leave a spurious choice point.
    I had this in Jekejeke Prolog. It got then adopted by
    SWI-Prolog. And I added it to Dogelog runtime this week.

    Jekejeke Prolog: (Inofficial future DNS pages.jekejeke.ch, not yet announce) Body Indexing http://pages.jekejeke.ch/doctab/doclet/en/docs/05_run/02_reference/07_theories/01_kernel/06_sharing.html

    SWI-Prolog:
    Indexing for body code
    https://www.swi-prolog.org/pldoc/man?section=indexbody

    Dogelog runtime:
    Preview: Dogelog Runtime does clause body indexing. (Jekejeke) https://twitter.com/dogelogch/status/1433235977955430400

    Having clause body indexing is prerequesite to having
    disjunction and if-then-else indexing in Dogelog runtime.
    So possibly you find clause body indexing also

    in ECLiPSe Prolog which has disjunction and if-then-else indexing. ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 12:57:12 UTC+2:
    ```
    % SWI-Prolog 8.2.0

    ?- retractall(f(_)).
    true.
    ?- assertz(f(X) :- X = 1), assertz(f(X) :- X = 2).
    true.
    ?- X = 1, call_cleanup(f(X), Det=yes).
    X = 1 ;
    false.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to ju...@diegidio.name on Fri Sep 3 06:18:47 2021
    Try SWI-Prolog 8.3.xx something, this test case:

    f(X) :- X = 1.
    f(X) :- X = 2.

    ?- f(1).
    %%% what do you see here, with devel SWI-Prolog?

    Will not anymore leave a spurious choice point.
    I had this in Jekejeke Prolog. It got then adopted by
    SWI-Prolog. And I added it to Dogelog runtime this week.

    Jekejeke Prolog: (Inofficial future DNS pages.jekejeke.ch, not yet announce) Body Indexing http://pages.jekejeke.ch/doctab/doclet/en/docs/05_run/02_reference/07_theories/01_kernel/06_sharing.html

    SWI-Prolog:
    Indexing for body code
    https://www.swi-prolog.org/pldoc/man?section=indexbody

    Dogelog runtime:
    Preview: Dogelog Runtime does clause body indexing. (Jekejeke) https://twitter.com/dogelogch/status/1433235977955430400

    Having clause body indexing is prerequesite to having
    disjunction and if-then-else indexing in Dogelog runtime.
    So possibly you find clause body indexing also

    in ECLiPSe Prolog which has disjunction and if-then-else indexing.

    ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 12:57:12 UTC+2:
    ```
    % SWI-Prolog 8.2.0

    ?- retractall(f(_)).
    true.
    ?- assertz(f(X) :- X = 1), assertz(f(X) :- X = 2).
    true.
    ?- X = 1, call_cleanup(f(X), Det=yes).
    X = 1 ;
    false.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Fri Sep 3 06:33:30 2021
    But I rather refrain from doing something with meta_predicate/1,
    to have manual control over indexes. Some current wish of mine
    is to bring a) just-in-time indexing to Dogelog runtime and

    b) multi-argument indexing to Dogelog runtime. a) and b) do
    both exist in Jekejeke Prolog, the question is currently how to
    bring it to Dogelog runtime. I have opened a couple of GitHub

    tickets for Dogelog runtime, to take notes of some ideas to do it.

    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 15:27:36 UTC+2:
    What is novel in the Dogelog runtime, you somehow have
    full control on how the index key is computed. Since Dogelog
    runtime itself is written in Prolog itself, assertz/1 and ensure_loaded/1

    are also written in Prolog itself. It was not clear that some of
    the index key computation can in fact be "out sourced" into
    Prolog itself. But somehow I managed to do that, for the simple

    scenario of first argument indexing. Currently the index key
    computation for a clause is seen here:

    - index_clause(R, O):
    The predicate succeeds in O with the indexing value of the clause with head R.
    - index_static(R, L, O):
    The predicate succeeds in O with the indexing value of the clause with head R and body L.

    https://gist.github.com/jburse/d10ac03547a9d59b858c2ef2342e488b#file-index-pl

    You find it also on GitHub in compile.p:

    https://github.com/jburse/dogelog-moon/tree/main/devel/transpiler

    index_clause/2 is the classical first argument index key.
    index_static/3 implements a very simple clause body index key.
    As you see it has an additional parameter, you need to

    pass the body as well, since it is clause **body** indexing.
    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 15:18:48 UTC+2:
    Try SWI-Prolog 8.3.xx something, this test case:

    f(X) :- X = 1.
    f(X) :- X = 2.

    ?- f(1).
    %%% what do you see here, with devel SWI-Prolog?

    Will not anymore leave a spurious choice point.
    I had this in Jekejeke Prolog. It got then adopted by
    SWI-Prolog. And I added it to Dogelog runtime this week.

    Jekejeke Prolog: (Inofficial future DNS pages.jekejeke.ch, not yet announce)
    Body Indexing http://pages.jekejeke.ch/doctab/doclet/en/docs/05_run/02_reference/07_theories/01_kernel/06_sharing.html

    SWI-Prolog:
    Indexing for body code https://www.swi-prolog.org/pldoc/man?section=indexbody

    Dogelog runtime:
    Preview: Dogelog Runtime does clause body indexing. (Jekejeke) https://twitter.com/dogelogch/status/1433235977955430400

    Having clause body indexing is prerequesite to having
    disjunction and if-then-else indexing in Dogelog runtime.
    So possibly you find clause body indexing also

    in ECLiPSe Prolog which has disjunction and if-then-else indexing. ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 12:57:12 UTC+2:
    ```
    % SWI-Prolog 8.2.0

    ?- retractall(f(_)).
    true.
    ?- assertz(f(X) :- X = 1), assertz(f(X) :- X = 2).
    true.
    ?- X = 1, call_cleanup(f(X), Det=yes).
    X = 1 ;
    false.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Julio Di Egidio on Fri Sep 3 07:34:18 2021
    On Friday, 3 September 2021 at 12:57:12 UTC+2, Julio Di Egidio wrote:
    On Thursday, 2 September 2021 at 17:24:43 UTC+2, burs...@gmail.com wrote:
    <snip>
    Dogelog doesn't leave a choice point, since
    it can index the disjunction and if-then-else:
    I think it's unfair to call it spurious, it's you who are doing something extra-ordinary.

    And something that may not always be desirable: that optimisation disallows the easy/clean way to keep the choice point should one want to, which is with code as above vs using constants directly as head arguments. (And as seen in the example below.)

    Use cases for precise control of language features? Didactics and research spring to mind, and even more should certified software, also scenarios like coordinating concurrency, etc., there may be more. Anyway, clause indexing changes the semantics of
    programs. Just consider this:

    ```
    % SWI-Prolog 8.2.0

    ?- retractall(f(_)).
    true.
    ?- assertz(f(X) :- X = 1), assertz(f(X) :- X = 2).
    true.
    ?- X = 1, call_cleanup(f(X), Det=yes).
    X = 1 ;
    false.

    ?- retractall(f(_)).
    true.
    ?- assertz(f(1)), assertz(f(2)).
    true.
    ?- X = 1, call_cleanup(f(X), Det=yes).
    X = 1,
    Det = yes.

    ```

    Along that line, I'd rather wish we could attribute predicates to have control on indexing (maybe just an extension to meta_predicate/1, it's simply an indexing option per argument, whether to index it or not, or even, in more sophisticated
    implementations, up to which nested level to index: 0 for the head, 1 for the body, 2 for a body goal's body, etc. In that scheme, your current implementation is like indexing on all arguments at level 1), sure possibly with reasonable defaults: then it'
    d be all good, including the extra-ordinary...

    Or, just max depth for max speed-up and we rather set whether to simulate "pure" determinism on that argument or not...?

    Anyway, I'd argue the use case is quite important, even strategic re the state of Prolog (and this is about Prolog itself, not -say- constraint programming or some other thing). Moreover, given that you are right now getting into (re)building this part
    for Dogelog, this might actually be the perfect moment to ponder if something better and more uniform than the obvious could be done, in fact for even less effort.

    I am partly speculating as I haven't seen the source code. If things are relatively clean/properly structured, this more "experimental" stuff could even be done in parallel (and with no particular hurry), while the main branch keeps using the usual
    implementations, to eventually possibly be swept in...

    Are you open to collaborations, up to pull requests, for Dogelog?

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Fri Sep 3 08:58:31 2021
    Issues can be raised here on GitHub:

    Issue Tracking: Dogelog Runtime
    https://github.com/jburse/dogelog-moon/issues

    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 17:49:28 UTC+2:
    It was always open source:

    Open Source: Dogelog Runtime https://github.com/jburse/dogelog-moon/tree/main/devel

    User Manual: Dogelog Runtime https://github.com/jburse/dogelog-moon/tree/main/manual
    ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 16:34:19 UTC+2:
    I am partly speculating as I haven't seen the source code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to ju...@diegidio.name on Fri Sep 3 08:49:27 2021
    It was always open source:

    Open Source: Dogelog Runtime https://github.com/jburse/dogelog-moon/tree/main/devel

    User Manual: Dogelog Runtime https://github.com/jburse/dogelog-moon/tree/main/manual

    ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 16:34:19 UTC+2:
    I am partly speculating as I haven't seen the source code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to burs...@gmail.com on Fri Sep 3 09:26:42 2021
    On Friday, 3 September 2021 at 17:49:28 UTC+2, burs...@gmail.com wrote:

    It was always open source:

    That's not what I was asking, open source isn't the same as open project...

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to ju...@diegidio.name on Fri Sep 3 11:14:15 2021
    You can raise an issue here when you think there
    is something wrong with Dogelog license:

    Issue Tracking: Dogelog Runtime
    https://github.com/jburse/dogelog-moon/issues

    Basically it has an elongated open source license.
    This means it has a copyright license that makes
    the source code available with a product, but it

    also covers usage in a lunar environment, or
    even in the milky way. Thats why its full name is:

    Dogelog Runtime, Prolog to the Moon

    ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 18:26:43 UTC+2:
    On Friday, 3 September 2021 at 17:49:28 UTC+2, burs...@gmail.com wrote:

    It was always open source:
    That's not what I was asking, open source isn't the same as open project...

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to All on Fri Sep 3 20:59:48 2021
    BTW: Julio, if you want to implement your
    own Dogelog, give it a try. You only need
    this paper here (basis for Dogelog):

    A portable Prolog compiler
    Conference: Logic Programming Workshop - Albufeira, Portugal
    William Clocksin - January 1983 https://www.researchgate.net/publication/273888197

    Dogelog Runtime, Prolog to the Moon https://qiita.com/j4n_bur53/items/17f86429745426bd14fd

    And the ISO core standard. Its probably
    better to start from scratch than to fork
    something if you have some ideas.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Fri Sep 3 11:24:58 2021
    Dogelog, stupid meme Prolog, total waste of time,

    dogecoin.avi
    https://www.youtube.com/watch?v=H3oiThw2R

    LoL

    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 20:14:16 UTC+2:
    You can raise an issue here when you think there
    is something wrong with Dogelog license:
    Issue Tracking: Dogelog Runtime
    https://github.com/jburse/dogelog-moon/issues
    Basically it has an elongated open source license.
    This means it has a copyright license that makes
    the source code available with a product, but it

    also covers usage in a lunar environment, or
    even in the milky way. Thats why its full name is:

    Dogelog Runtime, Prolog to the Moon
    ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 18:26:43 UTC+2:
    On Friday, 3 September 2021 at 17:49:28 UTC+2, burs...@gmail.com wrote:

    It was always open source:
    That's not what I was asking, open source isn't the same as open project...

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Fri Sep 3 11:43:02 2021
    Corr.:

    dogecoin.avi
    https://www.youtube.com/watch?v=H3oiThw2RxE

    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 20:24:59 UTC+2:
    Dogelog, stupid meme Prolog, total waste of time,

    dogecoin.avi
    https://www.youtube.com/watch?v=H3oiThw2R

    LoL
    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 20:14:16 UTC+2:
    You can raise an issue here when you think there
    is something wrong with Dogelog license:
    Issue Tracking: Dogelog Runtime https://github.com/jburse/dogelog-moon/issues
    Basically it has an elongated open source license.
    This means it has a copyright license that makes
    the source code available with a product, but it

    also covers usage in a lunar environment, or
    even in the milky way. Thats why its full name is:

    Dogelog Runtime, Prolog to the Moon
    ju...@diegidio.name schrieb am Freitag, 3. September 2021 um 18:26:43 UTC+2:
    On Friday, 3 September 2021 at 17:49:28 UTC+2, burs...@gmail.com wrote:

    It was always open source:
    That's not what I was asking, open source isn't the same as open project...

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Sat Sep 4 02:29:07 2021
    But since Dogelog runtime has change_arg/3, unlike
    Jekejeke Prolog, some new hardships is on the horizon.
    change_arg/3 can also create cycles not only unification.

    Namely we find:

    ?- X = f(X).
    X = f(X).

    ?- X = f(0), change_arg(1,X,X).
    X = f(X).

    The current Dogelog runtime garbage collection can
    deal with the first kind of cycle. But it cannot yet deal with
    the second kind of cycle.

    Mostowski Collapse schrieb am Samstag, 4. September 2021 um 11:24:58 UTC+2:
    I still find it rewarding to work on Dogelog runtime.
    Now spinning the idea of introducing occurs check
    flag. Since the Albufeira instruction set has first_var/1

    and var/1 instructions, we could take the route that
    we followed some months ago with Jekejeke Prolog
    and optimize away some occurs checks.

    But we will possibly not able to realize the dynamic
    freshness check as is now ultimately used in Jekejeke Prolog,
    since we do not have reference counting.
    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 20:59:53 UTC+2:
    BTW: Julio, if you want to implement your
    own Dogelog, give it a try. You only need
    this paper here (basis for Dogelog):

    A portable Prolog compiler
    Conference: Logic Programming Workshop - Albufeira, Portugal
    William Clocksin - January 1983 https://www.researchgate.net/publication/273888197
    Dogelog Runtime, Prolog to the Moon https://qiita.com/j4n_bur53/items/17f86429745426bd14fd

    And the ISO core standard. Its probably
    better to start from scratch than to fork
    something if you have some ideas.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Sat Sep 4 02:24:56 2021
    I still find it rewarding to work on Dogelog runtime.
    Now spinning the idea of introducing occurs check
    flag. Since the Albufeira instruction set has first_var/1

    and var/1 instructions, we could take the route that
    we followed some months ago with Jekejeke Prolog
    and optimize away some occurs checks.

    But we will possibly not able to realize the dynamic
    freshness check as is now ultimately used in Jekejeke Prolog,
    since we do not have reference counting.

    Mostowski Collapse schrieb am Freitag, 3. September 2021 um 20:59:53 UTC+2:
    BTW: Julio, if you want to implement your
    own Dogelog, give it a try. You only need
    this paper here (basis for Dogelog):

    A portable Prolog compiler
    Conference: Logic Programming Workshop - Albufeira, Portugal
    William Clocksin - January 1983 https://www.researchgate.net/publication/273888197
    Dogelog Runtime, Prolog to the Moon https://qiita.com/j4n_bur53/items/17f86429745426bd14fd

    And the ISO core standard. Its probably
    better to start from scratch than to fork
    something if you have some ideas.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to All on Thu Sep 9 05:04:10 2021
    There are obviously some advantage of doing Prolog parts
    in Prolog itself. I am not promoting some frivolous translator
    like Logtalk. But things that are used during runtime, either
    for compilation or interpretation.

    The advantages of doing Prolog parts in Prolog itself:

    Portability: If you write in Prolog you can port to other C (or
    some other host language). For example you are usually
    not dependent on 32-bit versus 64-bit.
    Conciseness: If you write in Prolog you can profit from a
    nice rule format, it makes it usually easy to handle different
    cases. (Situation has a little changed since more and more
    languages provide pattern matching)
    Prolog Stack: If you write in Prolog you can profit from the
    Prolog stack. You don’t need to have head aches for stack
    overflow in case of very large term input.

    On the drawbacks one might see:

    Lower Level Term Views: When you do things in Prolog you
    might be deprieved from some lower functions, like
    same_term/2 etc… In C (or some other host language) terms
    look usually different and you have a more direct handle.
    Additional Lower Level Interfaces: When you do things in
    Prolog you might arrive at points where you need nevertheless
    interface with some lower level data structure. This might
    blow up your Prolog code a little or ask for new built-ins.
    Slight Performance Penality: Even if you have a very good
    Prolog system, there might be a slight performance penality
    when doing things in Prolog instead of C (or some other host
    language). Or you have a surprise that it is faster!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mostowski Collapse@21:1/5 to Mostowski Collapse on Thu Sep 9 05:06:27 2021
    I am currently riding the frivolous doing it in Prolog train in
    my experimental system. And had some intersting break through,
    which could be also used for Dict indexing. In Dogelog runtime
    I do now compute the clause index key in Prolog itself:

    index_value_arg(_, A, just(F)) :- nonvar(A), !, functor(A, F, _). index_value_arg([B = C|L], A, O) :- A == B, !, index_value_arg(L, C, O). index_value_arg([C = B|L], A, O) :- A == B, !, index_value_arg(L, C, O). index_value_arg([_ = _|L], A, O) :- !, index_value_arg(L, A, O). index_value_arg(_, _, nothing).

    Currently there is a limitation, the clause stores only one computed
    index key value and its not just in time and its not multi-argument only
    first argument. But the approach allows already eliminate this choice
    point, which SWI-Prolog does more complicated:

    foo(X,Y) :- Y = 1, bar = X.
    foo(X,Y) :- Y = 2, baz = X.

    ?- foo(bar,Z).
    Z = 1.

    Fumbling with index_value_arg/3 could also bring indexing of
    Dicts to a Prolog system. But to have just-in-time or multi-argument
    indexing poses more architectual challenges. I have not yet solved in
    my new experimental system. In Jekejeke Prolog they were solved
    on Java level and not in Prolog.

    But having a function index_value_arg/3 is the same approach
    as in DDL SQL computed index:

    Indexes on Computed Columns https://docs.microsoft.com/en-us/sql/relational-databases/indexes/indexes-on-computed-columns

    Mostowski Collapse schrieb am Donnerstag, 9. September 2021 um 14:04:11 UTC+2:
    There are obviously some advantage of doing Prolog parts
    in Prolog itself. I am not promoting some frivolous translator
    like Logtalk. But things that are used during runtime, either
    for compilation or interpretation.

    The advantages of doing Prolog parts in Prolog itself:

    Portability: If you write in Prolog you can port to other C (or
    some other host language). For example you are usually
    not dependent on 32-bit versus 64-bit.
    Conciseness: If you write in Prolog you can profit from a
    nice rule format, it makes it usually easy to handle different
    cases. (Situation has a little changed since more and more
    languages provide pattern matching)
    Prolog Stack: If you write in Prolog you can profit from the
    Prolog stack. You don’t need to have head aches for stack
    overflow in case of very large term input.

    On the drawbacks one might see:

    Lower Level Term Views: When you do things in Prolog you
    might be deprieved from some lower functions, like
    same_term/2 etc… In C (or some other host language) terms
    look usually different and you have a more direct handle.
    Additional Lower Level Interfaces: When you do things in
    Prolog you might arrive at points where you need nevertheless
    interface with some lower level data structure. This might
    blow up your Prolog code a little or ask for new built-ins.
    Slight Performance Penality: Even if you have a very good
    Prolog system, there might be a slight performance penality
    when doing things in Prolog instead of C (or some other host
    language). Or you have a surprise that it is faster!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)