Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.prolog > #14944

The C# Span and new code instructions (Was: VIP4711: Variadic Predicates and Array Patterns)

From Mild Shock <janburse@fastmail.fm>
Newsgroups comp.lang.prolog
Subject The C# Span and new code instructions (Was: VIP4711: Variadic Predicates and Array Patterns)
Date 2025-10-27 14:57 +0100
Message-ID <10dntnj$1mk99$1@solani.org> (permalink)
References <107cdlv$3ok9q$1@solani.org> <10dnsoe$1mjhc$1@solani.org>

Show all headers | View raw


Hi,

Currently I have a dozen solutions on a back
of a envelope but cannot decide what to implement.
I am also examing my native call/n implementation,

which is in Java to learn what was used and whether
we can abstract some new code instructions, and
marveling at the C# Span struct:

- Prolog compound creation:
   The call/n implementation differes from
   other Prolog compound creations in that
   new Object[] is called with a computed arity.
   The arity formula for spread replacement is:

arity(F(...A, ...B)) = arity(A) + arity(B)

- Prolog compound population
   The call/n implementation differs from
   other Prolog compound creations in that
   System.arraycopy() is called with computed
   destination indexes:

dst(...A) = 0
dst(...B) = arity(A)

- Prolog compound matching
   The call/n implementation doesn't do much.
   It it knows that ...A is from the compound
   F(...) and that ...B is from the compound
   call(...), so a rest pattern is a pair of compound
   and source indexes, the used in System.arraycopy().

src(...A) = 0
src(...B) = 1

Interstingly C# has institutionalized a lightweight
struct Span, according All About Span: Exploring a
New .NET Mainstay By Stephen Toub | January 2018.

So I was thinking of converting a span ...X into
two Prolog variables X1 and X2, where X1 points to
the parent compound and X2 is the offset.

But if we only allow a single rest pattern, in the spirit
of LPA Prolog, X2 will be a constant that the Prolog
compiler knows from the given rest pattern.

So its still only one Prolog logical variable!

Bye

Mild Shock schrieb:
> Hi,
> 
> Now I wish I had a Prolog system at hand that
> could do what one could see in an old version of
> LPA Prolog, and even going beyond. Namely:
> 
> print(X | Y) :- write(X), maplist(write, Y).
> 
> So basically the list head and tail matching for
> Prolog compounds. It has an additional challenge,
> how does the Prolog predicate catalogue look
> 
> like. There is now a variadic predicate. But on
> 2nd though and looking at Java Script, which has
> a prefix operator (...)/1 which can be used for:
> 
> - **Rest Patterns:**
>    One can define function print(X, ...Y) which
>    is pretty much the same as the above.
> 
> - **Spread Replacement:**
>    But one can also invoke print(Z, ...V, ...W) which
>    goes beyond a head tail inside a unify read.
> 
> What would be a benefit? For example call/n could
> be the variadic definition, showing a further feature,
> namely Prolog variables at functor positions:
> 
> call(F(...A), ...B) :- F(...A, ...B).
> 
> Bye
> 
> Mild Shock schrieb:
>> Hi,
>>
>> Functional requirement:
>>
>> ?- Y = g(_,_), X = f(Y,C,D,Y), term_singletons(X, L),
>>     L == [C,D].
>>
>> ?- Y = g(A,X,B), X = f(Y,C,D), term_singletons(X, L),
>>     L == [A,B,C,D].
>>
>> Non-Functional requirement:
>>
>> ?- member(N,[5,10,15]), time(singletons(N)), fail; true.
>> % Zeit 1 ms, GC 0 ms, Lips 4046000, Uhr 11.08.2025 01:36
>> % Zeit 3 ms, GC 0 ms, Lips 1352000, Uhr 11.08.2025 01:36
>> % Zeit 3 ms, GC 0 ms, Lips 1355333, Uhr 11.08.2025 01:36
>> true.
>>
>> Can your Prolog system do that?
>>
>> P.S.: Benchmark was:
>>
>> singletons(N) :-
>>     hydra2(N,Y),
>>     between(1,1000,_), term_singletons(Y,_), fail; true.
>>
>> hydra2(0, _) :- !.
>> hydra2(N, s(X,X)) :-
>>     M is N-1,
>>     hydra2(M, X).
>>
>> Bye
> 

Back to comp.lang.prolog | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

VIP0909: VibeCore Improvement Proposal [term_singletons] Mild Shock <janburse@fastmail.fm> - 2025-08-11 11:38 +0200
  Dushnik–Miller theorem [1940] (Was: VIP0909: VibeCore Improvement Proposal [term_singletons]) Mild Shock <janburse@fastmail.fm> - 2025-08-11 14:31 +0200
    Moore-Naish Algorithm in Prolog (Was: Dushnik–Miller theorem [1940]) Mild Shock <janburse@fastmail.fm> - 2025-08-11 14:44 +0200
      Who was Seiiti Huzita (1958) ? (Was: Moore-Naish Algorithm in Prolog) Mild Shock <janburse@fastmail.fm> - 2025-08-11 14:50 +0200
  What are the constraints of program sharing (Was: Cheap hybrid binary algorithms) Mild Shock <janburse@fastmail.fm> - 2025-09-27 19:34 +0200
  VIP0909: VibeCore Improvement Proposal [Jaffar's Algorithm] Mild Shock <janburse@fastmail.fm> - 2025-09-27 19:26 +0200
    Cheap hybrid binary algorithms (Was: VIP0909: VibeCore Improvement Proposal [Jaffar's Algorithm]) Mild Shock <janburse@fastmail.fm> - 2025-09-27 19:28 +0200
  VIP4711: Variadic Predicates and Array Patterns (Was: VIP0909: VibeCore Improvement Proposal [term_singletons]) Mild Shock <janburse@fastmail.fm> - 2025-10-27 14:40 +0100
    The C# Span and new code instructions (Was: VIP4711: Variadic Predicates and Array Patterns) Mild Shock <janburse@fastmail.fm> - 2025-10-27 14:57 +0100
      Superintelligence or community? [The Almend Paradox] (Re: The C# Span and new code instructions) Mild Shock <janburse@fastmail.fm> - 2025-10-27 15:16 +0100
        No more Almend Paradox [China has enough] (Was: Superintelligence or community? [The Almend Paradox]) Mild Shock <janburse@fastmail.fm> - 2025-10-28 13:54 +0100
        No more Almend Paradox [China has enough] (Was: Superintelligence or community? [The Almend Paradox]) Mild Shock <janburse@fastmail.fm> - 2025-10-28 13:57 +0100
          Communities betrayed by GitHub [The Matrix is booting] (Was: No more Almend Paradox [China has enough]) Mild Shock <janburse@fastmail.fm> - 2025-10-28 21:06 +0100
  Dogzilla: Arrow Functions can be Super Dicts (Was: VIP0909: VibeCore Improvement Proposal [term_singletons]) Mild Shock <janburse@fastmail.fm> - 2025-11-02 15:50 +0100
    Dogzilla: Compilation gives First Argument Indexing (Was: Dogzilla: Arrow Functions can be Super Dicts) Mild Shock <janburse@fastmail.fm> - 2025-11-02 15:58 +0100
      Dogzilla: History of Dicts in Theorem Provers (Was: Dogzilla: Compilation gives First Argument Indexing) Mild Shock <janburse@fastmail.fm> - 2025-11-02 16:28 +0100
      Dogzilla: From Bryan Ford to Lars Hupel (Compilation gives First Argument Indexing) Mild Shock <janburse@fastmail.fm> - 2025-11-02 16:41 +0100
        Dogzilla: Set-Like via Clark Completion (Was: Dogzilla: From Bryan Ford to Lars Hupel) Mild Shock <janburse@fastmail.fm> - 2025-11-02 19:47 +0100
  AOT Compiled Inner if-then-else (Was: VIP0909: VibeCore Improvement Proposal [term_singletons]) Mild Shock <janburse@fastmail.fm> - 2025-11-05 20:23 +0100
    Credits to Hiord: A Type-Free Higher-Order (2004) (Was: AOT Compiled Inner if-then-else) Mild Shock <janburse@fastmail.fm> - 2025-11-05 21:19 +0100

csiph-web