Skip to content Skip to footer
C Plus Prolog by mpweiher

C Plus Prolog by mpweiher

10 Comments

  • Post Author
    tombert
    Posted March 13, 2025 at 11:06 pm

    I really need to learn Prolog. It looks interesting and powerful, but it's different enough form most languages that I'd need to actually sit down and learn it and how to write useful stuff with it.

    At a superficial level, it looks a bit like Z3, which I do have some experience with, but I suspect that there's a lot of intricacies to Prolog that don't apply to Z3.

  • Post Author
    rhelz
    Posted March 13, 2025 at 11:10 pm

    This is the most creative idea I've seen in a long time.

    It is also the smoothest way of "declaring an imperative" I've ever seen.

    It is also the most amazing use of the parser which is built-in to prolog (no, not the DCG's, the other parser, the railroad/operator precedence parser).

    I wish it had been discovered around 1981. The world might be very different.

  • Post Author
    ysabelbristol
    Posted March 13, 2025 at 11:45 pm

    [dead]

  • Post Author
    elteto
    Posted March 13, 2025 at 11:51 pm

    > I call it, “C Plus Prolog”, or “C+P” for short.

    Missed the chance to call it CPP.

  • Post Author
    tannhaeuser
    Posted March 13, 2025 at 11:58 pm

    If you like this stuff, consider how to "implement" JSON in Prolog:

        :- op(400, yfx, :).
        ?- JSON = {
          a: 1, b: "a string",
          c: { d: "a compound" }
        },
        JSON = { a: X, b: Y, c: { d: Z }}
    

    Basically, you don't ;) all we did here is declaring ':' as an infix operator. The next lines bind/unify a term to the var JSON, and the last line is again unification in action (basically destructuring on steroids), binding the vars X, Y, and Z to the respective value 1, "a string", and "a compound" from the previously bound JSON var.

    You can paste this snippet into [1] and execute it right in your browser to check that indeed X, Y, and Z are bound as described if you wish.

    Not that it matters that much. Prolog is really for indeterministically searching a large/infinite space such as in planning (and yes it can be used for theorem proving and program verification as well). It's always fun to see newcomers trying to implement pointless low-level stuff such as list primitives when coming from a functional programming background or even getters/setters.

    [1]: https://quantumprolog.sgml.net/browser-demo/browser-demo.htm…

  • Post Author
    Karrot_Kream
    Posted March 14, 2025 at 12:06 am

    This looks like it's using Prolog to be a rewriting engine into C? It reminds me a bit of M4 but seems like something better suited to something like Maude [1]?

    [1]: https://maude.cs.illinois.edu/wiki/Maude_Overview

  • Post Author
    c-smile
    Posted March 14, 2025 at 1:03 am

    Interesting timing…

    I've just made something similar but with JS: C modules in JS.

        import * as CModule from "./module.c";
    

    C module gets compiled to native code on load. I think that clear separation of execution models is a good thing.

    https://sciter.com/c-modules-in-sciter/

    https://sciter.com/here-we-go/

  • Post Author
    xonix
    Posted March 14, 2025 at 1:10 am

    Long time ago I was obsessed with Prolog. I found that if you bend it enough you could implement imperative code (a-la JavaScript) evaluation, still being valid Prolog:

    https://github.com/xonixx/prolog-experiments/blob/main/Prolo…

    This was super funny, but obviously absolutely useless

  • Post Author
    coliveira
    Posted March 14, 2025 at 3:31 am

    The main advantage of Prolog is that it forces you to think in different ways to solve problems. The main weakness of Prolog is that it forces you to think in different ways to solve problems. Especially because most existing libraries are written in procedural style, so they don't work well with prolog. In the end you'll have some difficulty to integrate with existing code.

  • Post Author
    sinuhe69
    Posted March 14, 2025 at 5:10 am

    Is that not what Picat is all about? Imperative + Declarative Constraint Programming

    [0] http://picat-lang.org/

Leave a comment

In the Shadows of Innovation”

© 2025 HackTech.info. All Rights Reserved.

Sign Up to Our Newsletter

Be the first to know the latest updates

Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.