Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

Prolog

< >

Prolog is a programming language created in 1972 by Alain Colmerauer.

#34on PLDB 52Years Old 23kRepos
REPL · Download · Wikipedia · Subreddit · FAQ · Docs

Prolog is a general-purpose logic programming language associated with artificial intelligence and computational linguistics. Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is intended as primarily a declarative programming language: the program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations. Read more on Wikipedia...


Example from Riju:
:- initialization main. main :- write("Hello, world!"), nl.
Example from hello-world:
helloWorld :- write('Hello World'). :- helloWorld.
% Hello World in Prolog hello :- display('Hello World!') , nl .
Example from Linguist:
%6.8 subset(Set, Subset) :- append(L1, Subset, Set). powerset(Set, Subset) :- bagof(Subset, subset(Set, Subset), Subset).
Example from Wikipedia:
rule(q0, 1, q0, 1, right). rule(q0, b, qf, 1, stay).

Language features

Feature Supported Example Token
Standard Library write('Hello, World!'), nl.
Binary Literals % 0b[01]+
Integers % \d\d?\'[a-zA-Z0-9]+
Floats % (\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?
Hexadecimals % 0x[0-9a-fA-F]+
Octals % 0o[0-7]+
Case Sensitivity
Strings 'Hello world' '
MultiLine Comments /* A comment */ /* */
Print() Debugging write
Line Comments % A comment %
Macros term_expansion(parent_child(Parent, Child), child_parent(Child, Parent)). parent_child(trevor, simon). % With the above definitions, we can query (even though the predicate child_parent/2 is nowhere explicitly defined in the code above): ?- child_parent(Child, Parent). Child = simon, Parent = trevor.
Type Inference
Comments
Case Insensitive Identifiers X
Semantic Indentation X
View source
- Build the next great programming language · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements · Part of the World Wide Scroll