My Life as a Prolog Implementor

Bart Demoen
Department of Computer Science
K.U.Leuven
Belgium

Editor: Enrico Pontelli



I heard about Prolog for the first time when I was teaching IBM-370 assembler in a technical school. I was studying for a masters in informatics at that moment as well. A colleague said: "very soon now, you will learn about a language in which backtracking is build in". I thought he was joking because this did strike me as too weird. But soon afterwards, indeed, we learned about Prolog in class, and at some point the professor even gave the floor to a bearded man who tried to explain the implementation of Prolog to us: that was the first time I saw Maurice Bruynooghe. I can't remember much about that implementation, but it wasn't anything WAM-like: we speak beginning 1983.

During the summer vacation of 1983, the ministry decided that teachers would no longer be paid for overtime, so I had to quit my teaching job: another colleague at school told me about his brother Raf Venken who worked in a small company (BIM) that was looking for collaborators for a new project. He gave me the telephone number of ... Maurice: Maurice was in waiting for a permanent research job with the national FWO (kind of NSF), and in the mean time he got the manager of BIM
(Michel Van den Bossche) interested in Prolog. They wrote up a project proposal which would - in collaboration with the university in Leuven - design and implement a commercial Prolog system: BIM-Prolog. At the phone Maurice asked me my qualifications and when he heard I had a masters in mathematics, I was hired. My PhD in theoretical physics was of no interest to him.

Gerda Janssens was one of the project members at the university: she had done her engineering thesis on an abstract machine for Prolog, and the idea was to use this machine as a starting point for the BIM-Prolog. She would do the implementation of the machine, I would do the compiler. We knew we still needed to do some redesign, but we were quite optimistic. Our goals were not very ambitious: beating C-Prolog in performance would have been considered a success. We looked at
manuals (DEC-10 Prolog, C-Prolog, M-Prolog) and a book (Clocksin and Mellish) for learning/understanding which built-ins were needed and which we could do without. We considered some of the things we read rightout silly: how can you name a predicate tab/1 and let it write out spaces ? How stupid is it to make the space between a functor name and the next open bracket meaningful ? We did some redesign of the Prolog syntax. We were also influenced a lot by the original Marseille
attitude towards Prolog.  We decided on a set of built-ins and went on implementing. It was fall 1983.

In February 1984, Maurice took me to the Atlantic City ILPS. That was a wonderful experience. Also a bit awkward at some point because Maurice took me to a program committee dinner where I definitely did not belong. But most of all it was interesting, and I only realised much later who I met in person: on the way to Atlantic City we met Peter Kovacs who had been involved in the implementation of M-Prolog (we had studied the M-Prolog manuals while doing the BIM-Prolog design, especially the modules!) and Kenneth Kahn. During the conference, I was within touching distance of Alain Colmerauer who gave what might have been his first invited talk on constraint logic programming (I didn't buy it: arithmetic in which the variables are still free ... too weird for me), two giants named David Warren (an
H.D. and an S.), Ehud Shapiro (who gave his talk on the Bagel), Seif Haridi, Mark Stickel and many more. It is worth looking at the proceedings of that conference, not just for the historical perspective: lots of the work presented there is really mandatory reading. The evenings in the hotel room with Maurice were also interesting: he had been given a bunch of papers to referee for some next conference (for the young: in those days you submitted 6 hard copies) and he made me read them, even though I lacked lot's of background to make sense of them.

For the BIM-KUL team, the most important ILPS paper was by Evan Tick and David H. D. Warren: Towards a Pipelined Prolog Processor. Although it didn't introduce the WAM, it was for us (Maurice and me) the first contact with the WAM - remember this is pre-internet time. After hearing the talk (Evan delivered it) Maurice and I were back in our room and Maurice asked: "What do you think ?". I answered: "Gerda will not be happy about this; we must restart from scratch". It seems that other teams went through the same experience/evolution.

So on coming back to Belgium, we restarted with the WAM as the new starting point for a faster implementation. Not that we understood the WAM at that point: some of the instructions in the Tick-Warren paper didn't make sense to us at all, so we invented our own variants, in particular related to indexing. For instance, we couldn't understand why one would create TWO choice points for one activation of a predicate, so we did away with that from the start.

While working on the first release of BIM-Prolog, a competitor emerged in the USA: Quintus-Prolog, headed by D.H.D. Warren himself, and with people like David Bowen (with whom I spend a nice evening for the first time in Atlantic City and later more at other conferences), Richard O'Keefe, Tim Lindholm, just to name some of the Quintus people I met in person, and whose names I did not forget.

At BIM, we were particularly worried about speed, the speed of nrev to be more precise: while our implementation matched Quintus-Prolog in speed for most benchmarks, we lagged far behind for nrev. BIM-Prolog had at that point already upgraded from an emulator to a native code generating system, under the impulse of two new team members: Herman Crauwels and Andre Marien. The Quintus trick to get nrev so fast was discovered by Herman by dumping the Quintus code in assembly form (somehow we had a tape with the Quintus implementation - I still have it !) and there we learned about instruction merging. All implementations do it now and it benefits not just nrev of course. We knew Quintus Prolog quite well at BIM. During the 1987 ICLP in Melbourne, where Quintus had a demo booth, I was denied access to the Quintus demo machine, because I was too good at making it crash - it was just something silly with floating point numbers.

Another player was showing at some point: SICStus Prolog, with Mats Carlsson as the main implementor. Mats was then (also) known for his LM-Prolog implementation and he gave a demo of it at the university of Brussels, probably the only place in Belgium with a Lisp Machine ever. We were very impressed. And also his later work on SICStus Prolog has always impressed me enormously: while I fled from BIM with its demanding clients back to the university - where you basically only do as you like if you play your cards right - Mats combines the development and support for a commercial system that now contains almost everything else other systems have (and it is on top of that also robust, reliable and reasonably fast), and he keeps writing interesting papers. Mats is one of my implementation heroes.

Garbage collection for Prolog was always of particular interest to me: it started (for me) with ideas by Maurice and Edwin Pittomvils (see a paper in Boston SLP 1985) and a first version of a garbage collector for BIM-Prolog which I spend about two months debugging before we decided to rewrite it from scratch - together with Alain Callebaut. Alain was also the main drive behind a full-screen debugger for BIM-Prolog, similar to dbxtool for C on SUN machines. This debugger
was far ahead of its time: it just laughed at the traditional Bird box debugging model (which I never liked to say the least - not that I think programmable debuggers are better: give me a print statement [that works even in nondet context] and I can debug anything). Garbage collection was also my first (sometimes only) involvement with some other Prolog systems: when Kostis Sagonas came to Leuven in 1996, our goal was to build a garbage collector for XSB, but before we did that, we had to understand its usefulness logic. I am so grateful to Yves Bekkers (and his colleagues) to have emphasised this concept, because the intuition that one can have about it really benefits from making it explicit. I also wanted to work on the implementation of tabling as an add-on, sort of a library that could be added to any Prolog implementation and give the benefits of the SLG-WAM: Kostis rather quickly convinced me that this is not possible, so I abandoned the idea. It is good to see that implementation groups in Madrid and Porto have made progress in this area quite recently, but important challenges still remain, and perhaps Kostis was right after all.

A very interesting development during the mid-80's was the coupling of external databases with Prolog. Unify was one such DB system and I went with Ann Mulkers (who worked like Gerda at the university on the BIM-project) to Hamburg to do such an integration - February 1986 I believe it was. It was a very exciting time. Some things we did then are now being rediscovered and published by other groups: that is good, because it means we were not too far off the right track  :-)

1986 was also interesting for its ICLP in London, generally interesting, but for Prolog implementors in particular. I couldn't attend the conference, but when I saw the proceedings, I realised that we (at BIM) could have had three Prolog implementation papers there, if only we had realised that what we did in BIM-Prolog was worth
writing up, instead of merely implementing it. Other papers at ICLP'86 have influenced me a lot. Chris Mellish with a paper on abstract interpretation (at Leuven we had seen a preprint of that paper and under the impulse of Maurice worked on it), and a paper by Saumya Debray. It was the first Saumya paper I ever saw, but not the last one I was impressed with. Saumya's papers show such a good mix ofscientific rigidity and pragmatism: mandatory reading for implementors I would say.

In 1987 I left BIM and went back to the university, to join the research group that Maurice was leading. Danny De Schreye also joined the group. Shortly before that, Peter Van Roy had spend some time in Leuven and I worked with him on Prolog implementation issues.

It would be fun (for me) to go on like this, hopping from one conference to another, remembering little details from my life as an implementor while I had the opportunity to meet interesting people. Let me make some big jumps in time. BIM went bankrupt during my second visit to Paul Tarau in Moncton in 1996 (it wasn't Paul's fault!): we implemented together a novel garbage collector in BinProlog in 1995, and a Prolog to Java compiler in 1996 - just too much fun to be true. In 1997, I spend a semi-sabbatical in Melbourne with Peter Stuckey, Maria Garcia de la Banda and Kim Marriott: they seduced me to get involved in HAL, a new constraint solver programming language on top of Mercury. In the mean time, Mercury has assimilated (or has it been assimilated by ?) HAL. Also too good to be true. In
1999, I felt it was time to do my own Prolog system: not for the sake of having Yet Another Prolog (wink) but because there were too many open questions (for me) about Prolog implementation and there was no way to satisfy my curiosity with other systems - the XSB experience had somehow convinced me of that. So dProlog was born, in four incarnations (corresponding to four basic questions I had about WAM variants), one of which was implemented by Phuong-Lan Nguyen. dProlog
gave life to ilProlog (still heavily used under the name of hipP for ILP applications, maintained and further developed by Henk Vandecasteele and Remko Troncon for some time) and to hProlog which I and Phuong-Lan use regularly for experiments. hProlog was also a very good test bed for the CHR implementation by two of my PhD students, Tom Schrijvers and Jon Sneyers. It has resulted in a CHR version under SWI-Prolog, which is single-handedly maintained by Jan Wielemaker:
another hero.  I have worked for a while on providing SWI-Prolog with a faster basic engine, but that failed. Since hProlog is rather speedy, I have been offered the following advice more than once: "just replace the SWI-Prolog engine with the one from hProlog". I think brain surgeons will be able to replace whole human brains sooner ...

A lot of work was done in the area of concurrent and parallel Prolog systems. There was pressure to participate in ESPRIT projects like PEPMA and ACCLAIM, and I gave in. Patrick Weemeeuw and Remco Moolenaar - two of my PhD students - worked on Parallel Garbage Collection for Aurora and on AKL.  We had a ridiculously expensive 8-processor Sequent machine and it was an interesting experience. However, my attitude towards making parallel Prolog implementations is now: don't do it, it is too difficult.

I had a short involvement with GNU-Prolog: Ruben Vandeginste worked with me on garbage collection for Prolog during his PhD. He implemented a garbage collector for GNU-Prolog, I think in 2003. Unfortunately the final integration never happened. I must have contributed directly or indirectly a garbage collector to three
systems (besides BIM-Prolog and the dProlog offspring): XSB, GNU and BinProlog. None of those survived: the garbage collection level of involvement is just too intimate to last very long  :-)  But at least XSB and BinProlog have garbage collectors. And Daniel Diaz is now putting one in GNU-Prolog I recently heard.

What are the prospects for a Prolog implementor in 2007 ? There are several aspects to the situation. First of all it is clear that the basic implementation technology for Prolog proper is not evolving fast: in fact, the WAM is just too good. From time to time someone claims to have designed a fundamentally better machine than
the WAM, but it has always turned out that the WAM was actually superior, or the WAM is versatile enough to assimilate a particular good idea. Secondly, Prolog itself is not evolving much: having an ISO Prolog standard is part of the reason for that (and of course Part II on modules is a complete disaster). You might conclude that the prospects for a Prolog implementor look dim.

On the other hand, the application domains in which Prolog is used are evolving and become more demanding. This is a great opportunity for Prolog implementors to live out their phantasies. Just to name one field I am involved in: Inductive Logic Programming, as part of Machine Learning. In the past years I have - together with Henk, Gerda and Remko, and in cooperation with the ML team in Leuven - done work on the execution of large sets of queries on large example sets. This pushes compiler technology to the limit, requires additions to the WAM, ... just the thing one would like to be involved in when making a life as a Prolog implementor. Also, have a look at what Vitor Santos Costa (one more hero !) has been doing in Yap in the past years: quite a bit of it is inspired by the needs of ILP. For sure other
application domains do or will certainly present new challenges to the Prolog implementor.

Let me go back to the issue of Prolog as a not evolving language. There is a split - almost a schism (in the church sense, not the musical sense) - in the Prolog community (implementors mainly I think) about whether Prolog should move towards a more robust type of language where one must declare at least types, and maybe also modes. This split is very detrimental to the evolution of Prolog. Under the impulse of Zoltan Somogyi (a hero !)  Mercury moved to one extreme in this respect (extreme is not meant to be judgemental) and I am not so happy with its program development model, but it is clear that the rest of the world just demands (at least) types in a programming language and for good reasons. Not having types restricts the acceptance potential of Prolog seriously. Types (and declarations) is not at all against the LP philosophy. Just complement the equation PROGRAM = LOGIC + CONTROL and get PROGRAM = LOGIC + CONTROL + TYPES. The challenge for Prolog implementors is to integrate types in the implementation in a decent way, and I am not thinking primarily about performance gains - I surprised you here, didn't I  :-)  BTW, I am still partly in the abstract interpretation and program analysis camp, but I believe that the equation PROGRAM = LOGIC + ANALYSIS has only imaginary solutions.

A relatively recent challenge is put to the Prolog implementors by ASP. I am using ASP in a generic way for a bunch of LP paradigms or systems based on model generation. ASP is currently the closest to what LP promised to be: you specify in a logic formalism and the implementation will find the answers to your problem. It is very much only the LOGIC part of the equations above, but that has always been the first part to get right. Still, the world needs the CONTROL part also very badly and as far as ASP goes, we are not there yet. Integrating a model generation paradigm with a goal solving paradigm has been investigated already (look at work by Enrico Pontelli for instance), but a lot more is needed. The Prolog language and its implementation assimilated constraint programming with so much grace, and also the concept of tabling. It would be a great if Prolog could also embrace ASP without sacrificing its own spirit. I consider that the most important challenge for Prolog implementors at this moment, and one which cannot be met without the help of theory (I didn't say "theoreticians" on purpose  :-)

Prolog has always been our most solid stepping stone from imperative to logic programming (and back), so it is difficult to make the next step. However, we need to move on: implementors can make it happen. Maybe only a new generation of Prolog implementors can do it.