The Power of Prolog
metalevel.at
metalevel.at
Lately I've encountered more offline/batch processing problems and I am planning to work on some reimplementations of my solutions in our usual languages using Prolog (as soon as I have some free time, so none too soon).
It hits right at the core of the appeal (these kind of solvers need to be designed, if you grow them organically you get the if statement from hell) and also the challenges (not many managers would run with the idea of "the users will be doing something that looks a lot like writing code").
Engineers are always looking for technologies to hop onto. Prolog is niche for a reason: I don’t think Prolog scales. In some ways it is too flexible and powerful.
I still avoid it, because yeah, once you solve that problem and avoid those thousands of lines, you are stuck. If you try make the rest of your system in Prolog, it will become a non-viable mess before you even finish it.
That said, I think the main thing that Prolog is missing is easy integration with other languages. If I could define some environment in Haskell, pack it with some Prolog predicate and get a list back, I would use it all the time.
Basically, Prolog is declarative programming. You can attach properties to your data and then define relations between the data based on whether they have that property (or not). Something along the lines of: X is grandfather of Y if X is man and X has child Z which has child Y.
The above statement is very simple to write, a couple of lines. This will perform depth first search (or breadth first with some longer algirithm) using your data. As a result, Prolog can provide all such matches of all your data, or just the grandchildren of X, or both grandfathers of Y, etc.
Anyway, what you are really getting is just a good implementation of the search through the relations based on constraints. The main reason Prolog is used is because other languages just don't provide a good library for constraint based search through your data.
Can you illuminate why the language being a constraint solver tells you why it didn't catch on?
As I said, I have never seen one integrated with any language (oh, well, now I have seen Flix).
I've been spending a ton of time with the language and its implementation through my day job, and I recently spoke about its use as a DSL for embedded knowledge bases: https://www.youtube.com/watch?v=lYLkaOq7WbU
Javascript: http://tau-prolog.org/
Java: https://apice.unibo.it/xwiki/bin/view/Tuprolog/ (also SWI, Ciao and Sicstus have Java bridges)
Go: https://github.com/ichiban/prolog
Common Lisp: https://www.cliki.net/Prolog
Racket: https://docs.racket-lang.org/racklog/
Guile: https://gitlab.com/gule-log/guile-log
Erlang: https://github.com/rvirding/erlog
Also SWI and Ciao have a pretty straight forward FFI for C.
https://github.com/tau-prolog/tau-prolog/blob/master/RELEASE...
this looks handy https://github.com/tau-prolog/tau-prolog/issues/295
Sounds like there is a use case for abstraction? Category theory maybe?
Prolog III is considered the origin of constraint logic programming: http://www.prolog-heritage.org/en/ph30.html
That said, I used it for a simple game AI at university. My AI was the best of the class and it was something like 30 LOC. I remember thinking I would have spend 5x more time writing the same thing in C instead of 1 hour (plus some tests and play session)
I do have some ideas for some apps I'd like to tackle at some point. Those primarily consist of interacting with system constraints.
https://news.ycombinator.com/item?id=22804079 - April 8, 2020 (82 comments)
https://news.ycombinator.com/item?id=17121028 - May 21, 2018 (158 comments)
https://news.ycombinator.com/item?id=14045987 - April 5, 2017 (161 comments)
But on the other hand, it can be really faffy to figure out why your recursive list printer is failing halfway through and restarting three items back...
I think people who don't need to use Prolog think of Prolog in a very idealized way, kind of how they think of other "principled" languages like Lisp or Rust. Many years ago, I took a course at Johns Hopkins called Computational Models of Cognition. It was taught partly in SWI-Prolog. We used Prolog as a simple DSL to write little logical programs. It was different, and fun, and kind of confusing.
But as soon as you want to take Prolog beyond elementary classroom use, you will find that it is a language like many others, and needs to expose a world of little QOL details that go beyond the elegant simplicity of term unification, like argument mode modifiers and continuations and such.
The way they get those numbers might seem irrelevant, or even unrealistic, yet that doens't change how many companies select the golden languages for their cogs.
The interesting thing is that 1000000000's of people use SQL every day and not so many Prolog....
Trying not to sound contentious, but I've often thought that SQL (DDLs/DMLs/DQLs) would be a really good way to interact with systems beyond just databases/datastores. And the general tone of this topic has been about how Prolog can solve/simplify so many problems/issues. Relating some Prolog to some SQL might help me (and others) see this light that everyone seems to be talking about.
There has recently been a lot of working examples of SQL being used beyond databases; IaSQL (Infrastructure-as-SQL), KSQL (streaming SQL), so on.
How can I embed a prolog program in a python long running API server? Same but in Go? JVM?
These days SWI-Prolog even has a library for Redis.
The rete algorithm was supposed to be a solution but has anyone applied rete to a prolog implementation yet?
But! I'm forever grateful for the things learning prolog did to my brain