Prolog: Artificial intelligence in your programs...
The moderate success of the language is undoubtedly due to the fact that its creators wanted to use it as a standalone tool, which makes the programmer stumble over problems where logical programming is neither natural nor very practical.
While conversely it excels on other problems where the procedural paradigm is of a very laborious use, by its capacity of evaluation on a data base expressed in the form of predicates.
Therefore the Prolog language made sense really if it is embedded in a procedural language that allows to use one type of programming or the other where they can best express the processing to achieve. For example procedural functions to draw a labyrinth and move object there, classes to characterize them, logical clauses to give them a smart behavior and integrate the knowledge added over time.
For which types of problems Prolog is it best suited?
Problems that Prolog will solve for you
When we record relational data in the form of clauses, for example relationships between people, an evaluation allows us to deduce the relationship between all pairs of people.
Natural language can be formulated by decomposing grammar rules into clauses, we can then make an automatic translation, or answer common questions.
Anticipation and explanation
The representation of data in tree form, where the data of a clause are other clauses, makes it possible to analyze hypotheses, to predict consequences, to find causes.
Short Prolog tutorial
We learn to use prolog by installing an interpreter, for example SWI-Prolog or GNU Prolog. Their command console allows you to load programs and interact with the knowledge base they contain.
After downloading and installation, open the console by clicking on the SWI or GNU icon.
You can also run the interpreter from the system console, for example:
swipl -s program -g "message" -t halt
program is the name of your file without the ".pl" extension.
A program is compiled and executed with the "consult" command of the Prolog console.
Both interpreters are compatible with the same source code but SWI responds with true or false whereas SWI responds with yes or no.
- Prolog Tutorial: Recording a set of facts.
- Prolog Tutorial: A problem is espressed in the form of rules.
- Prolog demo: Looking for an apartment in a catalog.
Prolog kits to integrate with another language
SWI-Prolog is free and developed since 1987, this implementation can be used alone as a development platform and even as an HTTP server. It can parse and generate HTML or JSON code and communicate with a database.
- Lib-jsl. A logical programming extension for JS. Allows unification. The data is added to the database as JS objects and a rule as an array of objects.
- Yield Prolog. Can be added to JS or C#. It's a minimalist kit.