News for hackers. Stuff that matters.
Re:Adventure in Prolog Tutorial (2016) by carapace on Sunday August 25, 2019 @11:33AM (#20793504)
You know how when someone quits smoking and then, sometimes, they start to go around telling everyone else how great it is and how OMG! they should quit smoking too, and generally being a kind of smug and annoying about it?

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."

Re:Adventure in Prolog Tutorial (2016) by ljm on Sunday August 25, 2019 @01:21PM (#20794139)
I really want to build a thing or two with it, but my problem is that I’m too impatient to actually learn it first.

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.

Re:Adventure in Prolog Tutorial (2016) by criddell on Sunday August 25, 2019 @02:43PM (#20794688)
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?

Re:Adventure in Prolog Tutorial (2016) by carapace on Sunday August 25, 2019 @05:42PM (#20795783)
I 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/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

Re:Adventure in Prolog Tutorial (2016) by richard_shelton on Sunday August 25, 2019 @06:43PM (#20796098)
About 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.
Re:Adventure in Prolog Tutorial (2016) by carapace on Sunday August 25, 2019 @06:51PM (#20796148)
Cheers!

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!

Re:Adventure in Prolog Tutorial (2016) by 6thaccount2 on Sunday August 25, 2019 @11:00PM (#20797143)
I see a lot of Python and not Prolog.
Re:Adventure in Prolog Tutorial (2016) by carapace on Monday August 26, 2019 @12:18AM (#20797435)
all the Prolog code is under ./thun

https://hg.sr.ht/~sforman/Thun/browse/default/thun

Re:Adventure in Prolog Tutorial (2016) by LukeEF on Monday August 26, 2019 @06:28AM (#20798623)
Working in a prolog first startup, this 'conversion' seems to be a regular enough experience. New core engineering recruits take a while, but then become evangelists!
Re:Adventure in Prolog Tutorial (2016) by carapace on Monday August 26, 2019 @01:01PM (#20801522)
Prolog-first startup, eh? Lucky duck! Are you hiring? I already know Prolog...

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.

Re:Adventure in Prolog Tutorial (2016) by davelee on Sunday August 25, 2019 @01:31PM (#20794229)
I've had this experience earlier this year. It's great, and I too mention it when I can. For me, it's often a nicer alternative in cases I might otherwise consider SQL in some way. My only complaint is aggregate functions are harder to use.
Re:Adventure in Prolog Tutorial (2016) by tunesmith on Sunday August 25, 2019 @03:50PM (#20795084)
I love the idea of prolog, but I'm stumped when I try to imagine integrating it into other web-based projects. Is there a way? Like for instance having a regular javascript frontend, and a JVM based backend like with spring or play, integrating logic programming and prolog somehow?

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...

Re:Adventure in Prolog Tutorial (2016) by rscho on Sunday August 25, 2019 @07:20PM (#20796296)
Re:Adventure in Prolog Tutorial (2016) by carapace on Sunday August 25, 2019 @05:48PM (#20795819)
You are in luck my friend!

Tau Prolog: A Prolog interpreter in JavaScript

http://tau-prolog.org/

> 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.

Re:Adventure in Prolog Tutorial (2016) by ianandrich on Monday August 26, 2019 @12:54PM (#20801452)
SWI Prolog also has the ability to provide a simple endpoint for querying prolog dynamically provided by the Pengines library.

https://github.com/Anniepoo/JavaPengine

Querying is straightforward. It's simply another service in your web stack if you go this route.