3 ms·
I wrote some Prolog 25 years ago in school. As I recall we did a bunch of pattern matching stuff with it and at the time it never made much of an impression on
by criddell 7y ago
I wrote some Prolog 25 years ago in school. As I recall we did a bunch of pattern matching stuff with it and at the time it never made much of an impression on me. I had similar experiences with CAML, SML, and COBOL.
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?
- carapace 7y agoI was exposed to Prolog about 20 years ago. A friend of mine tried to teach it to me but it didn't "click". Looking back, I'm totally puzzled by that, I cannot explain why. 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/603ed919bc814ccee10c1b3df6142fec 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#L95 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-prolog/junk/partev.pl 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 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.pl 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 http://joypy.osdn.io/notebooks/Types.html
- richard_shelton 7y agoAbout Warren's article. I just returned it back, sorry for the inconvenience :) By the way, you may find basically the same description of the compiler in The Art of Prolog book.
- carapace 7y agoCheers! 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!
- 6thaccount2 7y agoI see a lot of Python and not Prolog.
- carapace 7y agoall the Prolog code is under ./thun https://hg.sr.ht/~sforman/Thun/browse/default/thun https://hg.sr.ht/~sforman/Thun/browse/default/thun