Prolog
Prolog is a logic programming language that has its origins in artificial intelligence, automated theorem proving and computational linguistics.[1][2][3]
This article is about the programming language. For the narrative device, see Prologue. For other uses, see Prologue (disambiguation).Paradigm
1972
Part 2: Modules-Edition 1 (June 2000 )
Untyped (its single data type is "term")
.pl
, .pro
, .P
Part 1: www
Part 2: www
Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is intended primarily as a declarative programming language: the program is a set of facts and rules, which define relations. A computation is initiated by running a query over the program.[4]
Prolog was one of the first logic programming languages[5] and remains the most popular such language today, with several free and commercial implementations available. The language has been used for theorem proving,[6] expert systems,[7] term rewriting,[8] type systems,[9] and automated planning,[10] as well as its original intended field of use, natural language processing.[11][12]
Prolog is a Turing-complete, general-purpose programming language, which is well-suited for intelligent knowledge-processing applications.
Design patterns of Prolog[edit]
A design pattern is a general reusable solution to a commonly occurring problem in software design. Some design patterns in Prolog are skeletons, techniques,[16][17] cliches,[18] program schemata,[19] logic description schemata,[20] and higher-order programming.[21]
Modules[edit]
For programming in the large, Prolog provides a module system, which is in the ISO Standard.[24]
However, while most Prolog systems support structuring the code into modules, virtually no implementation adheres to the modules part of the ISO standard. Instead, most Prolog systems have decided to support as de-facto module standard the Quintus/SICStus module system. However, further convenience predicates concerning modules are provided by some implementations only and often have subtle differences in their semantics.[25]
Some systems chose to implement module concepts as source-to-source compilation into base ISO Prolog, as is the case of Logtalk.[26] GNU Prolog initially diverted from ISO modules, opting instead for Contextual Logic Programming, in which unit (module) loading and unloading can be made dynamically.[27] Ciao designed a strict module system that, while being basically compatible with the de-facto standard used by other Prolog systems, is amenable to precise static analysis, supports term hiding, and facilitates programming in the large.[28] XSB takes a different approach and offers an atom-based module system.[29] The latter two Prolog systems allow controlling the visibility of terms in addition to that of predicates.[30]
Limits[edit]
Although Prolog is widely used in research and education,[52] Prolog and other logic programming languages have not had a significant impact on the computer industry in general.[53] Most applications are small by industrial standards, with few exceeding 100,000 lines of code.[53][54] Programming in the large is considered to be complex because not all Prolog compilers support modules, and there are compatibility problems between the module systems of the major Prolog compilers.[26] Portability of Prolog code across implementations has also been a problem, but developments since 2007 have meant: "the portability within the family of Edinburgh/Quintus derived Prolog implementations is good enough to allow for maintaining portable real-world applications."[55]
Software developed in Prolog has been criticised for having a high performance penalty compared to conventional programming languages. In particular, Prolog's non-deterministic evaluation strategy can be problematic when programming deterministic computations, or when even using "don't care non-determinism" (where a single choice is made instead of backtracking over all possibilities). Cuts and other language constructs may have to be used to achieve desirable performance, destroying one of Prolog's main attractions, the ability to run programs "backwards and forwards".[56]
Prolog is not purely declarative: because of constructs like the cut operator, a procedural reading of a Prolog program is needed to understand it.[57] The order of clauses in a Prolog program is significant, as the execution strategy of the language depends on it.[58] Other logic programming languages, such as Datalog, are truly declarative but restrict the language. As a result, many practical Prolog programs are written to conform to Prolog's depth-first search order, rather than as purely declarative logic programs.[56]
Frameworks exist which can bridge between Prolog and other languages:
Use in industry[edit]
Prolog has been used in Watson. Watson uses IBM's DeepQA software and the Apache UIMA (Unstructured Information Management Architecture) framework. The system was written in various languages, including Java, C++, and Prolog, and runs on the SUSE Linux Enterprise Server 11 operating system using Apache Hadoop framework to provide distributed computing. Prolog is used for pattern matching over natural language parse trees. The developers have stated: "We required a language in which we could conveniently express pattern matching rules over the parse trees and other annotations (such as named entity recognition results), and a technology that could execute these rules very efficiently. We found that Prolog was the ideal choice for the language due to its simplicity and expressiveness."[12] Prolog is being used in the Low-Code Development Platform GeneXus, which is focused around AI. Open source graph database TerminusDB is implemented in Prolog.[82] TerminusDB is designed for collaboratively building and curating knowledge graphs.