Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I can basically +1 the sentiment here. Used Prolog during my three university AI classes (basically "AI A Modern Approach" front to back + Prolog programming) and it was a mind bending experience. I always have to warm up before my brain can think Prolog again. I also wrote horrible prology spaghetti code in my other language during the Prolog semesters :D

Biggest downside "back in the day" was interop with other things was tricky. Either you embedded a Prolog in a JVM or something like that (usually with less features) or you relied on some sort of C binding. My takeaway was it's great so solve certain tasks (especially CSP) but not for solving tasks with a user interface in the mix (or file system access or any miriad of other things).

"Back then" SWI was also lagging behind and we used some proprietary solution which I'm generally not a fan of when it comes to programming languages/environement (Sicstus iirc.). Last time I checked SWI has caught up with the prorietary stuff and would be my go to now though.

The Prolog exam was also the one I was most afraid of during university because it consisted of a 60 Minute live coding section (solve three tasks of increasing difficulty) followed by an oral exam. My prep experience was that often times it just takes some reasoning and sitting there before the magic moment comes and the Prolog solution pops up in my brain...not exactly what you want in a timed exam situation. Thankfully I aced it by spending 40 minutes on the easiest task and solving the other two in a matter of minutes. The follow up course was a lot of fun (implement a game playing agent and compete against other teams in a tournament).

"The Art of Prolog" and "The Craft of Prolog" were also two of the better programming books I have read in my life.



> "The Art of Prolog" and "The Craft of Prolog" were also two of the better programming books I have read in my life.

IMHO, The Art of Prolog is along with Concepts, Techniques, and Models of Computer Programming, Paradigms of AI Programming, and Structure and Interpretation of Computer Programs the canon of dynamically typed programming. The Craft of Prolog is also exceptional but has some chapters that are too specific to programming in old Prolog systems and thus outdated.

Lots of Prolog ideas live in answer set programming and Datalog. The latter is fantastic to build state-of-the-art static analyzers [1].

[1] https://arxiv.org/abs/2012.10086


For anyone interested in “The Art of Prolog”, which seems to be quite expensive as a print book, there is an Open Access version available as a PDF at MIT Press: https://mitpress.mit.edu/9780262691635/the-art-of-prolog/

I might be buying the book if I really like it to support the authors, but it’s great that they made it available for everyone.


Seems to be a few copies on ebay for ~$30.

I got my copy back in the (gasp) '80s from the neighborhood B. Dalton's or something, and it totally changed the way I thought about the roles of code and data. It's one of the handful of books that have survived all my library downsizing, along with The Tao of Programming, the bible, the dragon book...


Re old Prolog systems, lots of them are described here: https://www.softwarepreservation.org/projects/prolog/


> it was a mind bending experience

Still remember the expressions of the undergrads walking out of our first Prolog lecture. Equal parts shell-shocked and worried.

There's a thought: I wonder how the chatbots handle Prolog. Have they seen enough of it? Can they "reason" in that way?


In Prolog you can write "pure logical" programs or you can use cuts and some other mechanisms to write imperative programs in it.

The methods for writing imperative programs in Prolog are really clever but they are also awkward. (For instance "success" is often represented as a logical false and "failure" as a logical true)

I think there has been an explosion of interest in a pure logical dialect of Prolog called Datalog

https://en.wikipedia.org/wiki/Datalog

when I first got interested in the semantic web I thought "OWL sucks" and thought Datalog was an interesting alternative, although it was invented in 1986 there was very little literature on it. I got dragged kicking and screaming away from the semantic web multiple times and when I got back to it again recently I found that the opinion "OWL sucks, use Datalog instead" has gotten widespread and now there are a lot of Datalog implementations and a huge literature. (Oddly, I met somebody who taught me the true meaning of OWL and how to do interesting things with it.)

If you think that materialized views, CTEs and such are a ugly and disorganized mess in SQL you might like datalog a lot. (Of course if you think triggers are a disorganized mess you might like production rules but I haven't quite seen a production rules-based database that really works.)


>> (For instance "success" is often represented as a logical false and "failure" as a logical true)

I'm confused by this. false/0 (or fail/0, equivalently) is used to force a clause to fail. Frex:

  p(X,Y):- false.
Will always fail, not succeed. So what do you mean?


Not OP. He might be referring to the looping or enumeration pattern: evaluate some clause to get the first solution, “fail” to trigger backtracking and to get the next solution, etc. At the very end after printing all solutions, the program returns “No” because there are no solutions left.


Maybe, but that's known as a "failure-driven loop", in Prolog parlance, so it's still not clear to me how "success is represented as a logical false".

Also, "false/0" is extra logical.


Why? Its just DFS the language.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: