
The Art of Prolog, Second Edition - agumonkey
https://mitpress.mit.edu/books/art-prolog-second-edition
======
norswap
I'm plugging my own Prolog tutorial: [http://norswap.com/prolog-served-
dry/](http://norswap.com/prolog-served-dry/)

Might be useful for the folks who want to learn how the language ticks but
don't have the time to go through a whole book.

That being said, the book is pretty great! I recommend it.

------
pstuart
Clearly the universe wants me to learn Prolog, as HN seems to be putting it on
the front page almost every day. Challenge accepted.

~~~
ggggtez
As long as you know that Prolog is just a fancy wrapper around a brute force
search, then sure.

~~~
jodrellblank
"Hey! I just found out - that tool isn't magic, it's JUST CODE!"

What a con, I'll be sure to avoid anything like that in future.

~~~
jodrellblank
Can't edit or delete at this point, so I'll note that I see this is against
the "no snark" rule, and what I wanted to do was link to the c2.com wiki page
"JustIsaDangerousWord" \- a page that's now offline - about how a sentence
gets better if you remove the word "just".

"Prolog is just a brute force search" -> "Prolog is a brute force search"

and then reference the Gary Larson comic ( [https://pics.me.me/the-far-side-
by-gary-larson-3-23-hey-wait...](https://pics.me.me/the-far-side-by-gary-
larson-3-23-hey-wait-a-2526411.png) ) where the cow suddenly realises what
they've been eating is /grass/.

All libraries are "just" some code which does something so you don't have to.
Even if Prolog is "just a brute force search", well in the same kind of way,
regex is "just" a state machine brute-force matching against a string. It's
still a useful tool.

------
jayd16
I ask this seriously. Does it make more practical sense to learn a modern
business rule engine (like JBOSS BRMS) than to learn Prolog?

~~~
overlords
Rules engines are about forward chaining (fan-out of all implications) whereas
prolog is backward chaining (querying an implication).

CHR (constraint handling rules) is a forward chaining system built into most
prologs that has prolog like syntax, and so is a replacement for business
rules engines.

So the choice of what to use is based on that (if you want forward chaining -
business rules, or CHR of prolog), if you want backward chaining (similar to
SQL) then prolog.

Prolog is more elegant than the business rules engines, and also has extra
features (constraint programming with finite domains for example), that
business rules don't have.

So in short, prolog is more comprehensive and more elegant but requires more
expertise, busines rules are for "untrained" people to get working with
relatively quickly.

~~~
segmondy
Building a forward chaining rule in Prolog is trivial. Here's an example in 25
lines

[https://www.cse.unsw.edu.au/~billw/cs9414/notes/kr/rules/for...](https://www.cse.unsw.edu.au/~billw/cs9414/notes/kr/rules/forward.pro)

Allows for rules such as

    
    
      iF
        problem_in_kitchen and no_water_from_outside
      then
        leak_in_kitchen.

------
nafizh
Mandatory plugin for learning lisp.

'Paradigms of Artificial Intelligence Programming' by Peter Norvig[0]. The
book teaches both LISP and classic AI.

[0] [https://github.com/norvig/paip-lisp](https://github.com/norvig/paip-lisp)

~~~
dreamcompiler
Which among other things teaches you how to write a Prolog compiler in Lisp.

~~~
agumonkey
Aight, tonight's reading. Thanks.

------
gambler
I learned the basics of Prolog, really liked the idea, but found it rather
impractical for complex problems. IMO, there needs to be a stronger separation
between rule descriptions and search algorithm description/manipulation. I
want to be able to specify an infinitely recursive rule, but avoid falling
down the rabbit hole while running queries. Cuts could also be moved into this
"search algorithm description".

~~~
tom_mellior
One approach to taking existing Prolog code and executing it with different
semantics (like a different search algorithm, but also tracing, debugging,
etc.) is through metainterpreters. These are Prolog programs that interpret
Prolog programs; you can write one in a few dozen lines. You can find several
examples at
[https://www.metalevel.at/acomip/](https://www.metalevel.at/acomip/),
including one in the "Changing the search strategy" section that does what you
want.

The drawback of metainterpretation is that it is, well, an interpreter layered
on top of (on many systems) another interpreter. If you need your Prolog code
to be really really "fast", then this approach may be "too slow". (Quotes
because people love complaining about the speed of computation even in many
situations where it really does not matter.)

A different approach is to use code generation. Prolog programs are
collections of Prolog terms; once you have written the abstract computation
you want, you can write a program that takes that code, mangles it into a
different form, then compiles that new form just as if you had written it by
hand.

So in summary, the separation you ask for is not there, but you have much more
powerful tools than most other languages to implement it yourself quite
easily.

------
CMCDragonkai
Is there a production database where I can encode facts and logical policies
in prolog style syntax then perform inference via the database?

~~~
segmondy
Yes, your production database is a text file really.

You can encode your facts in prolog style syntax and save it in a file and
that's your database. You load it, and then ask your questions at the REPL.

If you wanted data that multiple people can change, you can actually connect
prolog to an SQL database, then using query apply prolog rules and ask
questions about your data.

------
Tistel
I had heard about prolog for years, but, it was not taught at the university I
went to. But, as other have mentioned, I have always wondered about it,
hearing whispers here and there. The recent resurgance of interest came from
working with Erlang. Erlangs syntax is from Prolog (because it was prototyped
in Prolog first) I am reading the basic intro text:
[https://www.amazon.ca/Programming-Prolog-Using-ISO-
Standard/...](https://www.amazon.ca/Programming-Prolog-Using-ISO-
Standard/dp/3540006788/ref=sr_1_1?ie=UTF8&qid=1539208185&sr=8-1&keywords=prolog).
which is nice. All I can say is, its very strange and interesting.

~~~
jlarocco
Although prototyped in Prolog, Erlang borrowed heavily from an obscure
language called Strand.

[https://en.wikipedia.org/wiki/Strand_(programming_language)](https://en.wikipedia.org/wiki/Strand_\(programming_language\))

[https://www.amazon.com/Strand-New-Concepts-Parallel-
Programm...](https://www.amazon.com/Strand-New-Concepts-Parallel-
Programming/dp/013850587X)

I have a copy of the book, and the code samples are _really_ similar to
Erlang.

------
keithnz
Is there any good resources for the internals of prolog / writing a prolog
interpreter?

~~~
Tistel
Peter Norvig (of google fame) describes how to write a prolog like language in
Common Lisp: [https://www.amazon.ca/Paradigms-Artificial-Intelligence-
Prog...](https://www.amazon.ca/Paradigms-Artificial-Intelligence-Programming-
Studies/dp/1558601910/ref=sr_1_4?ie=UTF8&qid=1539204305&sr=8-4&keywords=Peter+norvig)

~~~
jimbokun
And also happens to be one of the best books ever written on computer
programming.

~~~
Tistel
yeah, dude is beast.

------
yazr
1986 Art of Prolog..

Can someone say which (who?) are the "Prolog for the 21st century" and the
"Lisp of the 21st century" ?!

~~~
radiator
Hmmm... perhaps Prolog and Lisp?

~~~
protomyth
Like in The Reasoned Schemer? [https://mitpress.mit.edu/books/reasoned-
schemer](https://mitpress.mit.edu/books/reasoned-schemer)

------
agumonkey
note the 1st edition is also up there [https://mitpress.mit.edu/books/art-
prolog](https://mitpress.mit.edu/books/art-prolog)

and both in open access~

------
zura
I'd put it on a par with SICP. A very enjoyable reading.

------
tmaly
I still have my copy on my desk, this and a few other Prolog books I found
very useful when I first started trying to grok the language.

~~~
linsomniac
The original Art of Programming I read when I was ~16, and I found to be
extremely influential in how I thought of programs and data and their
interrelation.

------
overcast
A link to a bookstore summary page about a programming book makes front page
HN?

~~~
Jtsummers
It was discussed some yesterday, and the ebook is free.

~~~
overcast
So this a duplicate topic, and it's just a link to a free ebook? Slow day on
HN I guess.

~~~
Jtsummers
Related topic that the poster thought deserved its own link. Prior discussion
was yesterday.

[https://news.ycombinator.com/item?id=18178215](https://news.ycombinator.com/item?id=18178215)

