• Re: Side Note, Why not DSLs? (Re: Chicken and egg, with curry?)

    From Mild Shock@janburse@fastmail.fm to comp.lang.prolog on Fri Jan 3 22:12:14 2025
    From Newsgroup: comp.lang.prolog

    Ok I see its repeating my posts to comp.lang.prolog,
    because the sci.logic post has a shitty header!

    Fuck Fuck Fuck Julio what are you doing Fuck Fuck Fuck

    Mild Shock schrieb:
    Hi,

    Just a side note, don't let you get distracted.
    A side node about the chicken/egg problem, i.e.
    without the curry:

    - a) Eggs came first, for example Turtles had eggs
         Turtles are part of an ancient reptilian
         lineage ca 300 million years ago

    - b) Chickens came after Turtles
         Chickens, on the other hand, are much younger
         in comparison, evolved from theropod dinosaurs
         around 150 million years ago

    Not sure whether this helps. But I think it could help
    nevertheless:

    - i) Logic Programming is the Egg

    - ii) From the Egg Turtles or Chickens can hatch,
        its very easy to program functionally or
        procdurally in Prolog. Just add small DSLs:

    https://en.wikipedia.org/wiki/Domain-specific_language

    here is an example of a DSL for array manipulation,
    and an implementation of Floyd Warshall algorithm:

    :- op(100, yf, []).
    :- op(800, fx, new).
    :- op(800, fx, let).
    :- op(800, fx, if).

    warshall(N, D) :-
       new D[N,N],
       (between(1,N,U), between(1,N,V), let D[U,V] = 999, fail; true),
       (edge(U,V,W), let D[U,V] = W, fail; true),
       (vertex(V), let D[V,V] = 0, fail; true),
       (between(1,N,K),
           between(1,N,I),
              between(1,N,J),
                  let H = D[I,K] + D[K,J],
                  (if D[I,J] > H -> let D[I,J] = H; true),
                  fail; true).

    The definition of the DSL needs only one extension
    of Prolog, i.e. nb_setarg/3 (SWI-Prolog) respectively
    change_arg/3 (Dogelog Player):

    new D[N,M] :-
       functor(D, '', N),
       D =.. [_|L],
       new2(L, M).

    new2([], _).
    new2([X|L], N) :-
       functor(X, '', N),
       new2(L, N).

    let V = E :- var(V), !,
       let2(E,V).
    let D[R,C] = E :-
       let2(E,V),
       arg(R, D, H),
       nb_setarg(C, H, V).

    let2(D[R,C], V) :- !,
       arg(R, D, H),
       arg(C, H, V).
    let2(E+F, R) :- !,
       let2(E, V),
       let2(F, W),
       R is V+W.
    let2(V, V).

    if E > F :-
       let2(E, V),
       let2(F, W),
       V > W.

    Idiot Prolog systems like Scryer Prolog or Trealla Prolog
    refuse to provide such imperative gadgets, which are quite
    useful. If you interpret the DSL, its already bleeing fast,

    much faster than a pure implementation:

    ?- time((between(1,1000,_), graph(G),
       floyd_warshall(4, G, M), fail; true)).
    % 3,803,998 inferences, 0.156 CPU in 0.183 seconds (85% CPU, 24345587 Lips) true.

    ?- time((between(1,1000,_), warshall(4,D), fail; true)).
    % 1,046,998 inferences, 0.062 CPU in 0.062 seconds (100% CPU, 16751968
    Lips)
    true.

    If you compile the DSL, you can again an itch more speed:

    /* DSL compiled */
    ?- time((between(1,1000,_), warshall(4,D), fail; true)).
    % 336,998 inferences, 0.000 CPU in 0.020 seconds (0% CPU, Infinite Lips) true.

    Bye

    Julio Di Egidio schrieb:
    On 03/01/2025 21:04, Julio Di Egidio wrote:
    Partial and tentative:

    ```
       Functional = Closures/applications, Reduction/canonicity
         /    |
    Logical  |   = Predicates/queries, Resolution/subsumption
         \    |
       Imperative = Procedures/invocations, Execution/...
    ```

    And there are two views of that triangle: Logical is the top of the
    *ideal* such triangle, along the lines of a universe with Prop on
    top, which we can reason with; Imperative is the bottom of a
    *concrete* such triangle, the bootstrap as well as the final point of
    application of any concrete system.

    And Logical is the constructive (structural) type-theory founding the
    Functional, where Functional exists for expressivity and modularity
    (what else?), plus can be compiled back/down to machine language...

    Right?

    BTW, there are deficiencies of standard Prolog that are indeed very
    annoying, to the point that some invoke for the other way round:

    HANSEI / Re-thinking Prolog
    <https://okmij.org/ftp/kakuritu/logic-programming.html#vs-prolog>

    But, besides that I would not put logic in terms of "guessing", I'd
    propose we just need a Prolog that doesn't have the self-inflicted
    quirks: a strengthened resolution with declarative determinism and
    indexing, and a strengthened semantics, of variables and/vs open
    terms, with a partial order of terms by subsumption, and unifiability
    as comparability (a purely structural type system definitionally),
    i.e. where a variable is the most general term...  Or something like
    that.

    No?

    -Julio



    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Julio Di Egidio@julio@diegidio.name to comp.lang.prolog on Fri Jan 3 22:14:34 2025
    From Newsgroup: comp.lang.prolog

    On 03/01/2025 22:12, Mild Shock wrote:
    Ok I see its repeating my posts to comp.lang.prolog,
    because the sci.logic post has a shitty header!

    Fuck Fuck Fuck Julio what are you doing Fuck Fuck Fuck

    I set the follow-up to comp.lang.prolog, the specifics of Prolog are not relevant to the general discussion.

    Pity you don't know how Usenet works. And that e.g. one can simply
    delete locally the spurious messages, so it's no big deal really...

    -Julio

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Mild Shock@janburse@fastmail.fm to comp.lang.prolog on Fri Jan 3 22:50:11 2025
    From Newsgroup: comp.lang.prolog

    Hi,

    Well you don't need always types. JavaScript
    has also no types. And there is a trend to
    have gradual types. Make them kind of optional

    and arive at TypeScript. If I am not mistaken,
    you can omit Types in TypeScript here and then,
    and simply get JavaScript. You can still prove things

    about, just assume that you have an "any" type. What
    other benefit do you think have types? For example
    the Floyd Warshall algorithm in DSL works without

    any declared types although it has a manifest type
    of matrice somehow. Also many Program transformations,
    such as the compilation of the DSL doesn't need types.

    Here you see the compilation of the DSL,

    I just turned the helper predicate into expansion rules:

    goal_expansion(let V = E,
    let2(E,V)) :- var(V), !.
    goal_expansion(let D[R,C] = E,
    (let2(E,V),
    arg(R, D, H),
    nb_setarg(C, H, V))).

    goal_expansion(let2(V, V), true) :- var(V), !.
    goal_expansion(let2(D[R,C], V),
    (arg(R, D, H),
    arg(C, H, V))) :- !.
    goal_expansion(let2(E+F, R),
    (let2(E, V),
    let2(F, W),
    R is V+W)) :- !.
    goal_expansion(let2(V, V), true).

    goal_expansion(if E > F,
    (let2(E, V),
    let2(F, W),
    V > W)).

    Sadly I don't have yet goal expansion in Dogelog Player. But
    SWI-Prolog has it. I might introduce it in the next release
    provided I find an ultra simple solution. Or an inline directive.

    Bye

    The SWI-Prolog thread was this:

    https://swi-prolog.discourse.group/t/floyd-warshall-algorithm-in-prolog/8685

    Julio Di Egidio schrieb:
    On 03/01/2025 22:12, Mild Shock wrote:
    Ok I see its repeating my posts to comp.lang.prolog,
    because the sci.logic post has a shitty header!

    Fuck Fuck Fuck Julio what are you doing Fuck Fuck Fuck

    I set the follow-up to comp.lang.prolog, the specifics of Prolog are not relevant to the general discussion.

    Pity you don't know how Usenet works.  And that e.g. one can simply
    delete locally the spurious messages, so it's no big deal really...

    -Julio


    --- Synchronet 3.20a-Linux NewsLink 1.114