
A Short Introduction to Prolog - aerique
http://coliveira.net/software/a-short-introduction-to-prolog/
======
danieldk
Good follow-up literature:

\- Learn Prolog Now! by Patrick Blackburn, Johan Bos, and Kristina Striegnitz
provides an introduction to Prolog:

<http://www.learnprolognow.org/>

\- Prolog and Natural-Language Analysis by Fernando C. N. Pereira and Stuart
M. Shieber provides an introduction to Prolog, and applies it to natural
language processing. The book is more difficult than Learn Prolog Now!, but if
you enjoy SICP, you will enjoy this book.

<http://www.mtome.com/Publications/PNLA/pnla-digital.html>

\- The Craft of Prolog by Richard O'Keefe is a must to learn writing correct
efficient Prolog code. Many eye-openers.

[http://www.amazon.com/Craft-Prolog-Logic-
Programming/dp/0262...](http://www.amazon.com/Craft-Prolog-Logic-
Programming/dp/0262150395)

\- Warren's Abstract Machine: A Tutorial Reconstruction by Hassan Ait-Kaci is
a thorough overview of David Warren's abstract machine for executing of Prolog
code. Since modern Prolog implementations are often based on WAM, it helps in
understanding how to design efficient Prolog programs.

<http://wambook.sourceforge.net/>

~~~
JadeNB
The Craft of Prolog is a beautiful book; it's one of those SICP-style books
that doesn't just teach you a programming language, but changes your way of
thinking about programming. I am also amused by the sly (and not-so-sly) digs
that O'Keefe gets in at, well, everyone else who writes Prolog.

~~~
br1
It's more down to earth than SICP. O'Keefe is like Michael Abrash in Graphics
Programming Black Book.

------
swannodette
After learning a bit of Prolog and seeing its beauty you may wonder how to
leverage the paradigm in your own work. Lispers in particular have pondered
this for nearly 3 decades - Peter Norvig's Paradigms of Artificial
Intelligence famously includes a Prolog interpreter/compiler.

The Reasoned Schemer also continues in this tradition. I used that as my
introduction into the beauty of Prolog and created core.logic -
<https://github.com/clojure/core.logic>

If you're interested in being able to mix functional, object-oriented, and
logic programming techniques in a single practical language - I think Clojure
is a great place to start (yes, yes, Mozart/Oz is good too ;).

~~~
kunley
On your last sentence: well, dataflow variables plus backtracing are crucial
things in Prolog; Mozart/Oz has dataflow vars right away and backtracing can
be called on demand.

How exactly would you do this in Closure? I'm a big fan of this platform, but
can't see how to easily apply above-mentioned techniques. Dataflow library in
clojure-contrib seems to have very narrow scope AFAIR.

------
barik
I'll also chime in and say that Prolog is an interesting language to
experiment with even if you don't use it for anything else later. It is said
that there are some languages that change the way that you think about
programming -- Prolog is definitely one of these.

It is one of the few languages where the majority of the work is done through
pattern matching (unification), rather than explicit algorithms.

~~~
JadeNB
> It is said that there are some languages that change the way that you think
> about programming

These are also sometimes called 'Perlis languages'. LtU has a nice thread at
<http://lambda-the-ultimate.org/node/3464> about other examples.

------
chipmunkninja
Haha, in University, on a project with a friend, we ended up re-writing cpp
(the C-compiler preprocessor) in Prolog. We got an A- and "I'm not sure why
you'd do this … " on the project.

Good times, good times.

------
datadon
I did a university module in Prolog (for programming intelligent systems).
Although I have not used it since, I always remember it fondly. It is a
totally different paradigm to the Pythons/Rubies/Cs/Javas and really quite
refreshing when you get in to it.

Unfortunately I now struggle to think of a use for it on a day to day basis.

~~~
ses
I think Prolog still has a place in modern software development. It provides a
natural way of carrying out a backwards chaining depth first search through a
state space (good for game AI, planning and scheduling etc). Also constraint
solving is a very useful feature built into most logic programming languages
now.

Prolog pureists argue that the whole of Prolog can be used for applications,
but I tend to take a different approach that integration of Prolog with other
languages can help you to do the things its really good and you can get the
best out of multiple languages.

That's why I developed a (now open source) platform for integrating Prolog
with other applications via web services... see <http://kms.intelligent-
architectures.co.uk/>

~~~
jethroalias97
I'm a logic fan so I like prolog a lot, though for many people admittedly its
greatest attribute will be expanding the way you think about programming.

However for some problems you might want to go right to constraint programming
as you mentioned if you need speed and ease of modeling. I like MiniZinc for
many problems, or if you're interested you could try my constraint programming
language (<http://sabrlang.org>) which is based on spatial and temporal logic.

------
andrewcooke
so can you define something like

    
    
      transitive(X) :- [ X(A,C) :- X(A,B), X(B,C) ]
    

(which generalises the decendent example)? more generally, i guess i am asking
whether those horn clause things are first class.

~~~
_delirium
Unfortunately, no. The names of predicates---functors in Prolog-speak---have
to be symbols, not variables, and Horn clauses themselves aren't first-class
either.

You can do it via metaprogramming; a functor can be converted to a list [name,
param1, param2, ...], and then you can write normal Prolog operations on the
list that bind variables and such, and then convert back. This page shows how
to use that to build a higher-order _map_ function:
<http://en.wikibooks.org/wiki/Prolog/Higher_Order_Programming>

Here's a paper on other approaches; I'm not sure if any of the higher-order
Prolog approaches ever caught on, though:
<http://www.cs.umbc.edu/courses/771/papers/mu_96_02.pdf>

~~~
JadeNB
There are also Prolog-derived languages that support higher-order programming
'natively', such as Teyjus (<http://teyjus.cs.umn.edu>) and Curry
(<http://www-ps.informatik.uni-kiel.de/currywiki>).

~~~
olliesaunders
Do you use either of these personally? Would you recommend them?

~~~
JadeNB
I had a terrible time getting Teyjus up and running. I played around with
Curry a while ago (using PAKCS (<http://www.informatik.uni-kiel.de/~pakcs>),
if I recall correctly), but didn't explore enough to say anything about it.

------
cHalgan
The reason why prolog is important to learn and play with it is to understand
and learn concept of declarative programming as programming paradigm.

That is very important skill when designing system because you learn how to
define what the system should accomplish, rather than describing how to go
about accomplishing it.

------
ranman
This is a great follow up article as well:
<http://www.amzi.com/AdventureInProlog/>

Create a text adventure game in Prolog. A great class project. See if you can
get them to add networking to it and you can make a MUD!

------
metaobject
Ok, let's get it out of the way right now: no.

