Adventure in Prolog Tutorial (2016)
amzi.com
amzi.com
[1] https://github.com/triska/the-power-of-prolog/
[2] https://book.simply-logical.space/
[3] https://github.com/klaussinani/awesome-prolog
I had a kind of Prolog "conversion" experience last summer...
You guys! Prolog is so great! OMG! You should really try it! I'm seriously you guys.
In all seriousness, Prolog is a simple, powerful, elegant language, with a rich history replete with amazing research and tools. "An elegant weapon... for a more civilized age."
I imagine you could build a pretty effective scheduling/booking system with it, for example, and without knowing better I would think that it’s less complicated than what you have to do to build that kind of thing imperatively.
At the same time, I like declarative code and it makes me think of SQL. I’m pretty glad I picked that up before ORMs gave people a reason not to learn it. I would likely have that same impatience to learn SQL now, had I not.
Scheme, C, and Pascal were the languages that clicked and had me writing stuff just for fun.
What was it about Prolog that turned you into a fan?
Three things made me a fan:
First, Markus Triska's "The Power of Prolog" came up here on HN, and I managed to learn enough make a nice solution to the Zebra Puzzle: https://gist.github.com/calroc/603ed919bc814ccee10c1b3df6142... That got Prolog back on my radar.
Second, I had just written a type-inferencer for a stack-based language called Joy[1], and had kind of realized that what I was doing whas Prolog-shaped. So I re-implemented the interpreter and inferencer both in Prolog and discovered that they were the same code. (So I deleted one copy.) https://hg.sr.ht/~sforman/Thun/browse/default/thun/thun.pl#L...
Joy-in-Prolog is ridiculously elegant. It's almost perverse.
And then you can do messed-up things like partial evaluation: https://hg.sr.ht/~sforman/Thun/browse/default/thun/gnu-prolo...
Then, third, "Logic Programming and Compiler Writing" by David Warren went by here on HN, almost exactly a year ago https://news.ycombinator.com/item?id=17674859 (It's a 404 now but you can find it elsewhere.) I found out that there's a wealth of research to draw on, and that it's really easy to make compilers and other tools in Prolog.
It's so easy that, if you have to write a compiler from scratch it would be faster to learn Prolog and then use it to write your compiler than to (learn to) write a compiler in an imperative language you already knew!
I was already interested in compiling Joy, and here was a short, broad path to the metal. (Here's my crude and incomplete first attempt: https://hg.sr.ht/~sforman/Thun/browse/default/thun/compiler.... )
Taken all together, I realized that something like half of my professional career was wasted simply due to ignoring Prolog for twenty years, and that everything I want to do going forward is both faster and easier in Prolog. (I have embedded Joy in it and can compile it...)
[1] I wrote it up, "The Blissful Elegance of Typing Joy" http://joypy.osdn.io/notebooks/Types.html
It's funny, I picked up a copy of The Art of Prolog for a dollar at a library sale a couple of years earlier, and had even skimmed the ToC, but somehow the penny dropped only when I saw that paper. D'oh!
Or more generally, now that you know prolog, what kind of real-life things do you find it useful for? I mean I've seen all the tutorials of it solving sudoku and logic puzzles, but...
Tau Prolog: A Prolog interpreter in JavaScript
> Tau Prolog is a Prolog interpreter fully implemented in JavaScript. While most online interpreters are remote servers with an installed version of the interpreter which receive code, execute it and return the results, Tau Prolog is fully implemented on JavaScript and the code is analysed and parsed on the client side.
> Tau Prolog is not just an implementation of the logic programming resolution mechanism, but a complete Prolog interpreter. Furthermore, the implementation of this interpreter has been directed by the ISO Prolog Standard.
As for what I find it useful for, see the sibling comment for details.
https://www.swi-prolog.org/pldoc/doc_for?object=section(%27p...
https://pengines.swi-prolog.org/docs/index.html
SWI prolog has all you need, and more!
Shameless plug for smalltalkers (hobbyist work in progress): https://github.com/Rscho314/pengines_smalltalk
https://github.com/Anniepoo/JavaPengine
Querying is straightforward. It's simply another service in your web stack if you go this route.
Like I said above the thing that puzzles me is why I didn't grok Prolog twenty years ago when my friend was spoon-feeding it to me so patiently. I had to bang my head against the wall right up to the very last minute, when I had pretty much implemented a crude unification program.
I just wish I had the kinds of problems where Prolog would be performant enough.
I also think that everyone should build a theorem prover at some point, it's definitely an exercise in humilty
> We describe a program, PRESS, (PRolog Equation Solving System) for solving symbolic, transcendental, non-differential equations in one or more variables. PRESS solves autonomously, i.e. without guidance from the user. The methods used for solving equations are described, together with the service facilities. The principal technique, metal-level inference, appears to be relevant to the broader field of symbolic and algebraic manipulation.
https://www.sciencedirect.com/science/article/pii/S074771718...
I really enjoy using Prolog, but the number of cases where I would choose to use it is pretty limited.
Watch this space!
- - - -
You're releasing TerminusDB under the GPL! Bless your hearts! I can't wait to see it!
- - - -
Did you know that the Applied Category Theory folks (https://www.appliedcategorytheory.org/) have something they call CQL, Categorical Query Language, https://www.categoricaldata.net/ ? They have a book out that talks about it, "Seven Sketches in Compositionality:An Invitation to Applied Category Theory", specifically Chapter 3 "Databases: Categories, functors, and universal constructions" https://math.mit.edu/~dspivak/teaching/sp18/7Sketches.pdf
-------
Haven't seen CQL - must take a look and share with Terminus team member ('terminator' naturally!) who wrote our query language, WOQL (web object query language). Prolog as the basis for a query language is v powerful. We get: queries returning graphs, recursion as a core feature, composable sub-queries and irregular expressions & cycles.
There is a standardization push in graph query at the moment so I have all this stuff in the front of my mind! Trying to write a 'graph query manifesto' at the moment.
----------
On earlier comment - we are absolutely hiring, especially folks interested in prolog!
Excellent! I've heard that Behavioral Economics is also inspired by psychohistory.
If you're also looking to the future you might want to get in touch with the Long Now Foundation.
In re: CQL the underlying CT treatment of DBs is the "secret sauce". I haven't investigated WOQL in depth yet (I looked at the source in https://github.com/terminusdb/terminusdb) but I agree with you that Prolog is superlative for a query language.
I was joking about hiring, but if you put some issues in github it's not inconceivable you might get a PR someday. I don't want to make any promises.
As I mentioned above, I'm working on Joy-in-Prolog, and I'm right at the point where I'm thinking about how to represent data (as in DBs) using Category Theory along with the standard meta-data in "Data Model Patterns: A Metadata Map" by David C. Hay.
Novice: Adventure in Prolog Learn Prolog Now Logic Programming with Prolog
Med - Advanced: Clause and Effect The Art of Prolog The Craft of Prolog Wam Book The Practice of Prolog Prolog Programming for AI - Brakto
Deep Dive: Expert Systems in Prolog Natural Language Processing for Prolog Programmers Intelligent Image Processing in Prolog Representing Knowledge In Prolog
There are hundreds of books! The real gems are to be found in papers, look into published papers, you will find amazing topics on Meta Programming, Machine Learning, Compiler Construction, DCG, etc. Don't discount books by age, even if they were published in the 80s! The best books are from the 80's-90's.
A few sites https://www.metalevel.at/ https://www.cpp.edu/~jrfisher/www/prolog_tutorial/contents.h...
Use SWI-Prolog - https://www.swi-prolog.org/