LEARN PROLOG - FREE!
Explore logic programming and Artificial Intelligence
with a free Prolog system….
Also: Read our Beginner's
Prolog Tutorial
or skip straight to our reviews of free
Prologs
“Prolog
is a conversational language… if you ask
the right kind of questions, Prolog will work out
the answers….”
(from Programming
In Prolog by Clocksin and Mellish) |
Depending on your point of view, Prolog is either
one of the most exciting and innovative computer languages
ever invented or it is a programming dead-end, over-burdened
with ‘concept’ at the expense of practicality.
The ideas behind the language are revolutionary: whereas
in other languages, the programmer must specify precisely
how every problem in a program is to be solved, in Prolog
it is only necessary to specify the problem itself and
then allow the program to find one or more solutions.
A Dialogue
With Prolog...
Here is a simple example of how to ask Prolog
to find an answer to a question. In the top window
I have written a set of Prolog facts:
1) John
is a thief.
2) Mary likes food and Mary likes
wine.
Then
a conditional assertion is made - namely,
that John likes something, X, if that something
likes wine. Finally, another assertion is made
- that someone, X, may steal something, Y,
if someone X is a thief and X likes Y.
In order to find out who may steal what, Prolog
has to examine all the facts and assertions in
this program. Here is the question I have entered
at the prompt in the bottom window:
may_steal(john,X).
This is how Prolog goes about finding an answer.
First it instantiates the variable, X, to the value
john.
It tests whether john is
a thief and finds this to be true (this fact is
plainly stated in the code). Then it calls likes(john,
Y). No match is
made with the two first likes() facts
since, in both of these, the first argument specifies mary,
so calling them with the variable X which is instantiated
to the name john means that no match
can be made.
Now Prolog looks at the final entry for likes().
Here the value of the first argument is john so
this time a match is made. Then it is stated that
john likes X if X likes wine. Prolog doesn’t
yet know if this state of affairs can ever arise.
In order to find out, it has to examine the likes() facts once again. This time, it is looking for
a definite match with second argument, wine, in
which case it will instantiate the first argument,
X, to whatever value it finds. A match is made
with the fact about mary:
likes(mary,wine).
So now the second argument, X here…
likes(john X) :- likes(X,wine).
…is instantiated to the value mary. This
causes the second argument, Y, to be instantiated
in the may_steal() assertion - which, you will
recall, has just called likes(X,Y)…
may_steal(X,Y) :- thief(X), likes(X,Y).
…resulting in Prolog giving us the surprising
information that john may steal mary! Ah well,
Prolog can only make intelligent deductions if
we give it intelligent information!
This examples is taken
from chapter 1 on Clocksin and Mellish’s
famous book, Programming In Prolog. The Prolog
system shown above is SWI-Prolog with the SWI-Prolog-Editor.
|
The Fascination of Prolog
For a while, back the ‘70s, it seemed to some
people that Prolog would, in time, make conventional ‘procedural’ computer
languages redundant. After all, why put the effort into
hard-coding every last twist and turn of programming
logic in a language such as C when Prolog can do all
the hard graft for you? Moreover, unlike C programs,
Prolog programs can be modified by the programmer at
runtime and can even modify themselves (adding new facts
and rules to an existing program). The potential of self-modifying
programs based on the principles of formal logic seemed
almost incalculable.
Could it be that Prolog would provide the means of
modelling the human reasoning process, its programs capable
of ‘learning from experience’ - resulting,
one day, in the creation true artificial intelligence
- a genuine ‘thinking machine’?
For many years there was much excited muttering about
a ‘fifth generation computer’ project, based
on Prolog, being undertaken in Japan. I’m not entirely
sure what the project was expected to achieve but I rather
think that many people were hoping for something similar
to the Deep Thought computer in The Hitchhiker’s
Guide To The Galaxy.
For a brief history of the rise and fall of
the Japanese super computer, see Japan-101 |
Well, sadly, the Japanese version of Deep Thought
never did see the light of day. And while C and C++
programmers went out into the big wide world and wrote
fast (and highly profitable) applications in their
resolutely old-fashioned programming languages, Prolog
programmers increasingly retreated into the groves
of academe wherein to contemplate the beauties of their
beloved language which should by now (if there were
any justice in the world), have superseded C….
Now, whether you are procedural programmer (of the
C, C++, Java, Delphi or Basic variety) or a logic programmer
(of the Prolog persuasion), you must surely agree on
one thing: Prolog is different - very different - from
most other languages. Its differences are what make it
both fascinating to its adherents and impenetrable to
newcomers.
Beyond Prolog Traditional
Prolog is not the only ‘logic
programming language’. There is even a P# for
.NET “which facilitates interoperation
between a concurrent superset of the Prolog programming
language and C#”.
Meanwhile, another language, called Oz, implements
logic and functional and object orientated programming.
The Oz language forms the core of the Mozart Programming
system which is freely available for Windows, Linux,
OSX and other platforms.
|
In my opinion, Prolog is one of the most innovative
and intriguing of all computer languages. It gives you
the seductive ability to write programs in the form
of ‘road
maps’ of
facts connected together by ideas and propositions. The
programmer can then navigate this map, this network of
possibilities, looking for one or many solutions to simple
or complex problems. Programming in Prolog really is
a voyage of discovery. How much more exciting can programming
get….?
Maybe Prolog was just ahead of its time? Rather like
Smalltalk, which introduced graphical environments and
object orientation before most people had computers capable
of running the system, Prolog was aiming to move people
into a new generation of programming before the existing
generation had got much beyond the toddler stage.
Maybe Prolog itself now needs to move forward? Currently
many implementations of the language address themselves
principally to the research community rather than to
commercial developers. The most commercially-orientated
system - the one that most completely addresses itself
to compiler efficiency and developer productivity - is
PDC’s Visual Prolog. But instead of embracing this
as the ‘way forward’, some Prolog programmers
have criticised it as a backward step, believing that
it sacrifices many of the beauties of traditional Prolog.
Well, here’s your chance to draw your own conclusions.
There are several good Prolog interpreters and compilers
available for free. These include everything from the
novel Visual Prolog compiler to more ‘traditional’ systems
such as SWI-Prolog.
Is Prolog’s time still to come? You decide….
FREE
PROLOGS
First, download a Prolog development
system...
|
SWI-Prolog
http://www.swi-prolog.org/
Here
SWI-Prolog is hosted within the SWI-Prolog-Editor. With
its multi-window environment, syntax colour coding and
other handy features such as a quick-find list of predicates,
this add-on editor considerably enhances the usability
of SWI-Prolog.
SWI-Prolog is very much a ‘traditional’ Prolog.
Its default user interface takes the form of a window
containing a commandline in which queries are entered
alongside a ?- prompt. It has a large set
of built-in predicates comprising a superset of the Edinburgh
Prolog standard and these are well documented in a comprehensive
help system. It is cross-platform; versions are available
for Windows, Unix/Linux and Mac OS X. The software is
completely free and its continued development is supported
by voluntary donations.
While SWI-Prolog is quite a powerful system, its default
development environment is pretty primitive. There are
no interface design tools. Indeed, the author of SWI-Prolog
appears to be curiously averse to visual design tools
(see ‘Why
GUI Builders Are Evil’).
GUI applications can be built, however, using a graphics
toolkit. It does have a moderately capable graphic debugger
but there is no built-in editor. Fortunately, this deficiency
can be rectified using the add-on SWI-Prolog
Editor for
Windows
or the cross-platform J-Prolog
editor written in Java
.
Overall this is a comprehensive Prolog system with
a fairly active community of users and a decent number
of useful add-ons.
Visual Prolog
http://www.visual-prolog.com/
Visual Prolog has all the tools you would expect to design,
code and debug a Windows application
I love Visual Prolog. I first came across it - or rather,
its DOS-based predecessor, at a time when it was marketed
by Borland under the name Turbo Prolog. The Windows system
continues to be developed by its creators, PDC (the Prolog
Development Center). Many of the other Prolog systems
reviewed here skimp on important little details such
as a decent editor, form designer or debugger. Not Visual
Prolog. This has a complete, tightly integrated IDE with
all the features you would expect of a modern, commercial-quality
programming system.
Judged purely in terms of its environment and support
tools, there is can be little doubt that Visual Prolog
is by far the most powerful and complete of all the free
Prolog programming systems. The commercial release might
reasonably lay a similar claim when compared with its
commercial rivals. But….
Ah yes, there is a ‘but’. Visual Prolog
is not ‘traditional Prolog’. While its syntax
owes much to the ‘Edinburgh’ standard, both
the language and the environment are significantly different
from the versions of Prolog which feature in most text
books. For one thing, Visual Prolog is a typed language.
It requires that named code blocks (predicates) be predeclared
and the arguments to them be given specific data types.
The downside of this is that Visual Prolog is, in some
senses, less flexible than traditional Prolog. It does
not do on-the-fly querying, nor can it do meta programming
(in which data can be interpreted as code - say by passing
a predicate name as an argument and then calling the
actual predicate). There are good reasons for this. Visual
Prolog is a compiler, not an interpreter. It is designed
for the development of fast standalone applications.
Its strong typing is aimed at compiler efficiency and
good error trapping (however, version
7 of Visual Prolog,
currently in alpha, introduces 'parametric polymorphism'
or generics which, to some extent, gets around
some problems associated with strong typing).
Some Prolog purists feel that this is not a sufficient
reason for omitting some of the most powerful (or anyway, ‘interesting’)
aspects of Prolog. On the other hand, it could be argued
that, while traditional Prolog may have all kinds of
intellectually interesting features, these are not necessarily
of great utility when developing efficient standalone
applications. If this is your main priority, you might
find that Visual Prolog’s sacrifices are well justified.
Visual Prolog does not merely subtract features from
traditional Prolog, however. It has also added a good
many new features. It is fully object orientated, incorporates
many useful additions to the language and has a good
integrated development environment for creating fully
visual, event-driven Windows applications.
The Personal edition of Visual Prolog 6.3 has most
of the essential features of the commercial release but
has a smaller library, omits some features such as COM
support and is restricted to non-commercial use. The
full list of features of the commercial and person editions
can be found here.
My recommendation is: download it, try it, follow the
online tutorials and
make up your own mind!
EZY-Prolog
http://www.ezy-software.com/
EZY-Prolog has a good integrated
environment for designing and editing
EZY-Prolog is a Visual Prolog-compatible
interpreter. It comes with a pretty slick integrated
environment complete with a syntax coloured code editor
and tabbed panes to view messages, variables, trace and
call stack. It even has its own visual designer. This
lets you lay out forms and dialogs by dragging buttons,
edit boxes and other controls onto a blank workspace
and setting their properties in a panel. The code editor
has some nice features such as a drop-down list for inserting
functions or 'code-completion' and it provides context-sensitive
help on a selected predicate.
And yet, in spite of its friendly-looking environment,
I have to say that I personally didn’t find EZY-Prolog
to be quite as easy to use as its name suggests. It even
took me several minutes to work out how to load and run
a program. The layout capabilities of its form designer
baffled me until I read the documentation. My problems
were due to simple things such as the fact that you have
to select a specific part of a control (not obvious)
in order to drag it and that the DEL key does not delete
a control - you have to click an on-screen button instead.
These are minor criticisms, however. Compared with
most of the other Prolog implementations reviewed here
(Visual Prolog being a notable exception) this is an
unusually user friendly system.
EZY-Prolog includes several special features for Visual
Prolog users. For example, it can generate Visual Prolog
classes, including form designs, to be included in a
Visual Prolog application. Its Visual Prolog support
is not perfect, however. It is compatible with a rather
old version (5.2 rather than the current
6.3) and cannot simply load and run an entire multi-file
Visual Prolog project.
But why, you may be wondering, would anyone want a
Visual Prolog interpreter when they might just as well
get the Visual Prolog compiler? The real reason is that
the interpreter gives to the Visual Prolog language some
of the development features that are otherwise only available
to more traditional Prologs. In particular, it allows
new facts to be asserted at runtime, so that programs
can be modified without editing and recompiling and it
ignores predeclared predicates and types. This gives
it the ability, for example, to process lists of mixed
data items in a way which would not be allowed by Visual
Prolog itself. So, in effect, it is like a traditional
Prolog interpreter (but with a more complete IDE than
most) which uses the Visual Prolog syntax. EZY-Prolog
can check programs for Visual Prolog compatibility and
it produces warning messages when code violates Visual
Prolog’s
typing rules.
The developer of EZY-Prolog is currently working on
an enhanced system called EZY-Prolog Suite which will
have an improved development environment and will enable
the integration of EZY-Prolog into programs created in
other languages such as VB, Java and Delphi.
Strawberry Prolog
http://www.dobrev.com/
Strawberry
Prolog has a decent editing environment, a good beginner’s
tutorial and lots of sample projects such as the Minesweeper
game seen here
Strawberry Prolog is a bit of an oddity.
On the one hand, it implements a fairly traditional version
of the Prolog language but on the other hand it does
so in a very untraditional way.
Whereas most traditional Prologs start with commandline
prompt ?-, Strawberry Prolog starts with
the source code editor. If you’ve been using other
Prolog systems this can initially be quite confusing.
However, if you are more used to languages such as C++
or Delphi, this is probably what you were expecting anyway.
A query is itself entered into a source file. You actually
enter the Prolog prompt symbol prior to the query. So,
for example, you might enter two facts and one query
like this:
oop( smalltalk ).
oop( java ).
?- oop(L), write(L), nl, fail.
This can then be compiled and executed in which case
an output window will display the two language names
matching the query, smalltalk and java,
plus a newline (nl) after each. Finally it will display ‘No’ due
to the query’s call to fail (which is required
to make Prolog seek more than one solution to the query).
For simple programs and when learning Prolog, the lack
of commandline interactivity may be a disadvantage. When
developing standalone programs this is not so much of
a problem. In that case, the query in your source file
may be regarded as, in essence, the main function (or
the ‘goal’ as Visual Prolog calls it) of
your program which starts everything going.
Strawberry Prolog has a moderate development environment
with multiple windows, syntax coloured code and a code-tracing
tool (a ‘proof tree’) for debugging. It does
not, however, have any GUI design tools. User interfaces
are designed using special Prolog predicates which place
buttons and other objects at specific locations on a
form. Predicates can then be defined to respond
to events such as a button-click.
Strawberry Prolog is available for Windows. A limited
implementation lacking graphics and development tools
is also available for Linux/Unix. There is a curious
registration process for the Windows XP/NT software;
this requires that you sign up for a free anti-spam
email service run by the author of Strawberry Prolog.
If you don’t want to do this, you can download
a Windows 98-compatible version (which also runs under
XP) without having to register. Commercial editions of
Strawberry Prolog are also available. The Professional
edition includes an EXE compiler (though executables
are not completely standalone, apparently, since they
require that the free edition of Strawberry Prolog be
installed).
Overall this is an interesting system with a good set
of graphics tools for exploring Prolog. It does, however,
lack interactivity and is probably not ideal for a new
learner who intends to use one of the standard texts.
GNU Prolog
http://www.gprolog.org/
This is another Prolog traditional implementation which
conforms to the ISO Standard (‘Edinburgh syntax’).
It has more than 300 built-in predicates, an interactive
interpreter and the option of native code compilation
(using a commandline compiler) on a variety of platforms
including Windows and Linux. The interface is pretty
minimal - no editor, no graphical debugger, not much
indeed in the way of a menu system. Files are loaded
(‘consulted’) by entering commands at a prompt.
There are some add-ins for GNU-Prolog including ‘constraint
programming’ and OOP extensions and an interface
to the MySQL database. However, GNU-Prolog’s austere
user interface makes this a somewhat forbidding system
for the newcomer to the language.
CIAO
http://www.ciaohome.org/
Another ISO Prolog system, Ciao provides various extensions
for functions, constraints and objects. Its environment
offers the choice of traditional commandline querying
plus an emacs editing interface and debugger. A compiler
is provided for standalone executables. Ciao can be run
on Windows, Linux and other flavours of Unix.
B-Prolog
http://www.probp.com/
B-Prolog takes a resolutely traditional approach to prompt-driven
programming
B-Prolog has a neat Windows installer but the
system itself is commandline driven. In fact, you run
it from a batch file (which you may need to edit by
hand to set up the paths) and it opens in a ‘DOS Box’.
It does come with a Windows graphics library, however,
and it is possible to create Windows-hosted applications
by entering commands at the commandline or in source
code. While B-Prolog has a decent 95 page PDF manual
and its programs can interface with C++ and Java to
create standalone applications, this system cannot be
recommended to the beginner for the simple reason that
it has almost nothing in the way of a user interface.
While B-Prolog is available commercially, the software
can be downloaded free for non commercial development.
The author informs us that the downloadable software
is time-limited to one or two years depending on the
release date.
PIE
Source (provided with Visual
Prolog) from http://www.visual-prolog.com/
Or download
a ready-to-run version direct from Bitwise
PIE (‘Prolog Inference Engine’) is a demo
program that ships with PDC’s Visual Prolog system.
However, while some demo programs may be small and trivial,
this one isn’t. In fact, it is a surprisingly complete
Edinburgh Prolog interpreter. Though it hasn’t
got as many built-in predicates as some of the other
traditional Prolog systems listed here, it does have
a decent multi-window editor and a simple code-trace
for debugging purposes. Moreover, its source code is
provided so Visual Prolog programmers have the option
of extending its capabilities or using PIE to embedded
Prolog features in their own applications. PIE is one
of the two Prologs which we’ve used in the Bitwise
beginner’s
tutorial.
Open Prolog
https://www.cs.tcd.ie/open-prolog/
Open Prolog is a system designed specifically for the
Apple Mac. It supports a subset of ISO Prolog and is
largely ‘Edinburgh’ Prolog compatible. It
has a fairly simple user interface with built-in tracing.
More information and screenshots can be seen here.
Poplog
http://www.cs.bham.ac.uk/research/poplog/freepoplog.html
Once upon a time, Poplog was an expensive commercial
product (costing about £7,500 or $13,600 at its
height!) but it is now free, so grab yourself a bargain!
This is a multi-language system which includes Prolog,
Lisp and ML plus its ‘core’ AI language,
Pop-11). Versions of Poplog are currently available for
Windows, Linux and other flavours of Unix. A version
for Mac OSX is under development. More information from
http://www.poplog.org/
Read On...
Newcomers to Prolog can start learning the
language by following our tutorial here. If you
want to delve deeper, you can choose from a number
of books on Prolog programming. In my opinion,
the best of the lot is the classic text, Programming
In Prolog by W. F. Clocksin and C. S. Mellish.
This gives a clear, well-paced introduction to
ISO standard (‘Edinburgh’) Prolog.
First published in 1981 and now in its fifth
edition, this is the essential book for student
of Prolog.
|
Here are some links to some useful Prolog study resources
More Prolog resources
http://wiht.link/prolog_resources
In addition to the freely available Prologs mentioned
above, there are also these time-limited ‘trial
versions’:
Amzi! Prolog
http://www.amzi.com/download/index.htm
SICStus Prolog
http://www.sics.se/isl/sicstuswww/site/index.html
Logic Programming Associates’ Win-Prolog
http://www.lpa.co.uk/
Huw Collingbourne
September 2005 |