Prolog for Squeak 5/6
by Stéphane Rollandin
hepta@zogotounga.net
The original Prolog
Up to version 3.6 of Squeak, it was possible to load the Prolog/V implementation by Mike Teng, ported to Squeak by Bolot Kerimbaev.
This code is still available from SqueakMap. It loads in a 3.6 Squeak image, but not in a 3.7 one. Here is a ready-to-go 3.6 image.
The original documentation is v-prolog.pdf
Around 2009 I made it to load in more recent images (I think 3.10 at the time) and packaged it as a SAR archive: Prolog.sar
It then went subject to code rot again, and cannot be installed in newer images.
The new Squeak Prolog
In the process of porting the original Prolog/V to newer images I did fix a few bugs and improved uncompletely implemented features.
Then I kept hacking the code up to the point where it became quite different (and not even backward compatible).
I did maintain that version along the years, up to the time of writing (that is, 2022, and Squeak now at 6.0).
The latest updates bring important changes toward a more comprehensive Prolog.
Here are the main points of divergence with the original code:
- The core code has been drastically simplified.
- The parser has been completely rewritten.
- Prolog methods and primitives have a different naming scheme: a method defining the Prolog predicate
predicate
must be named logicPredicate
. If it is a primitive (e.g. written in Smalltalk) then it must be named primlogicPredicate:
.
- The
List
class implementing the cons cell data structure used by the original Prolog has been replaced by PrologList
, a subclass of ConsCell
used by LispKit. Its subclass Relation
represents compound terms with a functor. There is no EmptyList
class anymore, this is simply nil
.
- The
value
selector used for referencing logic bindings from Smalltalk code has been replaced by logicValue
.
- The
PrologWorkspace
, while still working, is deprecated. Instead we have a semantically consistent GUI coupling a code browser and a read-eval-print-loop (see picture below).
- Important predicates that were either badly implemented or had strange semantics have been fixed, such as
univ/2
, functor/3
, arg/3
.
- More predicates have been implemented, such as
findall/3
, maplist/3
and ground/1
. Others have new, more standard names, such as =/2
and retractall/1
.
- There is also
=**
(for univ/2
) and ===
(for idem/2
, the Smalltalk #==
identity test).
-
is/2
has been restored to its regular semantics (arithmetic assignment). To invoke Smalltalk, use iss/2
or send/[2,3]
.
- Nonterminating queries are detected and stopped in the REPL,
time/1
reports inferences count and elapsed time.
- Predicates with zero arguments do not require parenthesis any more.
- We are closer to the standard Prolog syntax: atoms do not need a
#
(although they still are Symbols), variables must start with an upper case letter (although they are compiled as lowercase, and must be referred as such in iss/2
for example).
- Common binary predicates also have a compact form:
=
, \+
, ==
, \==
, >=
, >
, <=
, <
- Support for operators (infix, prefix and postfix) was also added.
- Added (partial) support for definite clause grammars.
- Each
Prolog
subclass may now decide if its database is the single system-wide one, or class-local, or instance-local.
- Databases accept rules, and a predicate may be both hard-coded and have database clauses (which are then looked up first).
- Generic input and output streams have been added to each interpreter instance.
- An API for directly feeding a Prolog interpreter with Smalltalk queries, bypassing the parser, has been implemented.
-
LogicRef
instances keep a reference to their variable name, and wrappers around query results maintain them too. This is used by the REPL.
- Cycles in variables bindings are taken into account.
- The raw query result is now a Generator, yielding in turn the answers as they are infered. The number of displayed answers in the REPL can be set interactively.
- SUnit tests and documentation have been added; many bugs were found and fixed in the process.
The Prolog GUI in Squeak 6.0
Note the usage of input/output streams in the animals game,
and the pretty-printing of the answers
Download
The most recent code is available on SqueakMap: check up the entry Prolog.
Prolog can be installed in a 5.1 or newer image (last tested on 5.1 and 6.0).
You can also get it here: PrologSPFA-31.sar (October 30th, 2022).
What are we talking about here ?
Squeak and Smalltalk links
Prolog links