279 points · by jsfcoding · 4y ago · 67 comments
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.
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.
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.
The interesting thing is that 1000000000's of people use SQL every day and not so many Prolog....
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