Comment by bwestergard
3 days ago
Are there any particularly excellent examples of prolog implemented as a library you could point us to?
3 days ago
Are there any particularly excellent examples of prolog implemented as a library you could point us to?
As an example of a use case, "Gerrit Code Review"[1] is written in Java and uses prolog for the submit rules.[2]
I haven't looked into the implementation. But taking a brief glance now, it looks interesting. They appear to be translating Prolog to Java via a WAM representation[3]. The compiler (prolog-cafe) is written in prolog and bootstrapped into Java via swi-prolog.
I don't know why compilation is necessary, it seems like an interpreter would be fast enough for that use case, but I'd love to take it apart and see how it works.
[1]: https://www.gerritcodereview.com/ [2]: https://gerrit-documentation.storage.googleapis.com/Document... [3]: https://gerrit.googlesource.com/prolog-cafe/+/refs/heads/mas...
Not exactly prolog, but logic programming implemented as a library/DSL: https://minikanren.org/
If it's a DSL then it's "writing a new language" and you're just calling from a native API, no?
Embedded DSLs are libraries. They are the epitome of the advice to write a library. It just so happens that the library abstractions could map to a language if you wanted to add parsing and all of the other machinery.
Clojure's core.logic is based on minikanren, so that fits the bill.
My time to shine! https://eugeneasahara.com/2024/08/12/playing-with-prolog-pro...
...ie:
...the point being there's sometimes some sort of "logic calculation that you wish could be some sort of regex", and I always think of prolog as "regexes for logic".
One time I wished I could use prolog was trying to figure the best match between video file, format, bitrate, browser, playback plugin... or if you've seen https://pcpartpicker.com/list/ ...being able to "just" encode all the constraints, and say something like:
...this is a terribly syntactically incorrect example, but you could imagine that this would be horrific code to maintain in python (and sqrt(horrific) to maintain in prolog), but _that's_ the benefit! You can take a well-defined portion and kindof sqrt(...) the maintenance cost, at the expense of 1.5x'ing the number of programming languages you need to expect people to know.
not prolog but logical programming in python: https://sites.google.com/site/pydatalog/
not OP, but for clojure : https://github.com/bobschrag/clolog