Prolog: a compiled or interpreted language or both?

Most implementations compile to byte code and run on a Prolog VM. Implementations use their own VMs with different design choices and trade-offs.

GNU-Prolog started as a Prolog to C "transpiler", now it is compiled to native code.

You also have Logtalk (OOP with Prolog), which, as far as I understand, re-writes the Logtalk source to Prolog. It can use a whole array of Prolog implementations as backends, so it can be used as a compatibility layer between Prolog implementations.

This question really cannot be answered; you should read the documentation of each Prolog implementation you are interested in. The best answer you can get however is how a particular Prolog implementation does it. Prolog the language is just that: a programming language, not a runtime or a VM or a compiler and so forth.


To answer this, let’s nail down some definitions.

A compiled language is one that converts source code files to a form (binary, byte code, etc.) for standalone execution or into a library for linking with other programs. The constructs are fixed and cannot be amended.

An interpreted language is one that converts a construct into a form that can be executed after conversion. Each converted construct is typically put into a store that can be referenced by later constructs.

Now many programming languages can be both compiled and interpreted, there is no rule that says a programming language can only be one or the other.

In the early days most programming languages were one or the other, e.g. C++ - compiled, BASIC - interpreted.

Now to answer your question:

Prolog: a compiled or interpreted language or both?

The Prolog language can be compiled and can be interpreted so the answer is both.

The reason you are seeing different answers for different sites is that you are asking about the language, think of the Prolog language as an abstract concept, but looking at specific implementations, think of the sites as referring to a concrete implementation. So some entities do one or the other and some do both.

In the last several years, in my opinion, the consensus is becoming that if you have a main stay programming language it has to have a compiler to generate efficient code and an REPL which uses an interpreter for quick development of constructs.

Typically the trend is to develop and test basic programming constructs using the REPL and then move them into source code files that will be compiled to build up libraries. The libraries are then referenced from the REPL; rinse and repeat.

Interestingly Prolog was the first language I used that had both, and that was back in the 1980's.

If you read ISO/IEC 13211 Information technology -- Programming languages -- Prolog -- Part 1: General core it states:

The language originates from work in the early 1970s by Robert A. Kowalski while at Edinburgh University (and ever since at Imperial College, London) and Alain Colmerauer at the University of Aix-Marseilles in France. Their efforts led in 1972 to the use of formal logic as the basis for a programming language. Kowalski’s research provided the theoretical framework, while Colmerauer’s gave rise to the programming language Prolog. Colmerauer and his team then built the first interpreter, and David Warren at the AI Department, University of Edinburgh, produced the first compiler.