What Is a .PL File?

Prolog source

📂Code
🏷️.pl
🎯text/x-prolog

Prolog Source File (.pl, .pro)

Overview

Prolog (Programming in Logic) is a declarative logic programming language. Instead of describing how to compute a result, a Prolog program states facts and rules about a problem, and the language's inference engine searches for solutions that satisfy them.

This inverts the usual model. There are no loops or assignments in the conventional sense; computation happens through unification (pattern matching between terms) and backtracking (systematically exploring alternatives when a path fails).

Note the extension collision: .pl is also the conventional extension for Perl scripts. The two languages look nothing alike, so content-based detection separates them easily - but a filename alone cannot.

Technical Specifications

Format Details

  • MIME Type: text/x-prolog
  • File Extensions: .pl, .pro, .P, .prolog
  • Category: Code
  • Encoding: plain text, usually UTF-8
  • First appeared: 1972
  • Created by: Alain Colmerauer and Philippe Roussel
  • Standard: ISO/IEC 13211
  • Paradigm: declarative, logic programming

Recognising Prolog Source

Prolog syntax is highly distinctive:

  • Clauses end with a period: fact(x).
  • Rules use :- meaning "if": head :- body.
  • Variables are capitalised; atoms are lowercase
  • Comments use % for line comments and /* */ for blocks
  • Directives begin with :- at the start of a line
  • Lists use [H|T] head/tail notation

Perl, by contrast, uses sigils ($, @, %), braces, and sub definitions - no overlap in practice.

Language Structure

Facts and rules

% Facts: things that are unconditionally true
parent(tom, bob).
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).

% Rules: things true when their body holds
grandparent(X, Z) :-
    parent(X, Y),
    parent(Y, Z).

sibling(X, Y) :-
    parent(P, X),
    parent(P, Y),
    X \= Y.

Querying this program:

?- grandparent(tom, Who).
Who = ann ;
Who = pat.

?- sibling(bob, liz).
true.

The engine finds every solution by backtracking, and ; at the prompt asks for the next one.

Recursion and lists

Recursion replaces iteration entirely:

% Length of a list
list_length([], 0).
list_length([_|Tail], N) :-
    list_length(Tail, N0),
    N is N0 + 1.

% Append two lists - works in multiple directions
append([], L, L).
append([H|T], L, [H|R]) :-
    append(T, L, R).

append/3 illustrates what makes Prolog unusual: the same predicate concatenates lists, splits a list into all possible pairs, or checks whether one list is a prefix of another, depending on which arguments are bound.

?- append([1,2], [3], X).      % concatenate
X = [1, 2, 3].

?- append(X, Y, [1,2,3]).      % all the ways to split
X = [], Y = [1, 2, 3] ;
X = [1], Y = [2, 3] ;
X = [1, 2], Y = [3] ;
X = [1, 2, 3], Y = [].

Arithmetic and cut

Arithmetic requires the explicit is operator, and ! (the cut) prunes the search tree:

factorial(0, 1) :- !.
factorial(N, F) :-
    N > 0,
    N0 is N - 1,
    factorial(N0, F0),
    F is N * F0.

Definite Clause Grammars

Prolog has built-in grammar notation, which makes it a natural parsing language:

sentence --> noun_phrase, verb_phrase.
noun_phrase --> determiner, noun.
verb_phrase --> verb, noun_phrase.

determiner --> [the].
noun --> [cat] ; [mouse].
verb --> [chases].
?- phrase(sentence, [the, cat, chases, the, mouse]).
true.

History and Development

Prolog was created in 1972 at the University of Aix-Marseille by Alain Colmerauer and Philippe Roussel, with theoretical foundations from Robert Kowalski's work on logic as a programming language. The Edinburgh Prolog dialect established the syntax that the ISO standard later codified.

Prolog gained enormous visibility in the 1980s when Japan's Fifth Generation Computer Systems project selected it as the core language for its AI research programme. The project did not meet its goals, and the subsequent "AI winter" cooled interest in logic programming broadly.

The language remained important in specific niches, and modern implementations - SWI-Prolog in particular - are actively developed with constraint solving, tabling, web server libraries, and interfaces to other languages.

Common Use Cases

  • Expert systems: encoding domain rules and deriving conclusions.
  • Natural language processing: DCGs make grammar-based parsing natural.
  • Constraint satisfaction: scheduling, timetabling, and configuration via CLP(FD).
  • Theorem proving and formal verification: automated reasoning over logical statements.
  • Knowledge representation: ontologies and semantic reasoning.
  • Teaching: the standard vehicle for teaching logic programming and unification.
  • Static analysis: some program analysis tools use Datalog, a Prolog-derived language.

How to Open and Run a Prolog File

Interpreters

  • SWI-Prolog: the most widely used implementation; free, cross-platform, extensive libraries.
  • GNU Prolog: compiles to native binaries, with a good constraint solver.
  • SICStus Prolog: a commercial system used in industry.
  • Ciao and XSB: research systems with advanced features such as tabling.

Running code

# Load a file into the interactive shell
swipl program.pl

# Run a goal and exit
swipl -g "grandparent(tom, X), write(X), nl" -t halt program.pl

# Compile to a standalone executable with GNU Prolog
gplc program.pl -o program

Inside the interactive shell:

?- [program].          % load or reload the file
?- listing(parent/2).  % show clauses for a predicate
?- trace.              % step through execution
?- halt.

Editors

  • VS Code: the VSC-Prolog extension provides highlighting, linting, and debugging.
  • Emacs: a mature Prolog mode with interpreter integration.
  • SWI-Prolog's built-in editor: includes a graphical debugger and profiler.

Advantages

  • Declarative: express what a solution looks like, not how to find it.
  • Built-in search: backtracking and unification come free.
  • Bidirectional predicates: one definition often serves several usage patterns.
  • Excellent for symbolic reasoning: rules, relations, and constraints map directly.
  • Concise for the right problems: a parser or rule engine can be a fraction of the imperative equivalent.
  • Strong pattern matching: unification is more general than most languages' matching.

Limitations

  • Steep conceptual learning curve: the model is unlike imperative or functional programming.
  • Unpredictable performance: naive clause ordering can cause exponential search.
  • Awkward for numeric and I/O-heavy work: arithmetic is bolted on rather than fundamental.
  • The cut breaks purity: ! is a control construct with no logical reading, and it is easy to misuse.
  • Small ecosystem: few libraries compared to mainstream languages.
  • Extension ambiguity: .pl collides with Perl.
  • PERL: the other major user of .pl.
  • LISP: the other classic symbolic AI language.
  • HASKELL: declarative, but functional rather than logical.
  • ERLANG: a language whose syntax was directly influenced by Prolog.

File Information

File Description

Prolog source

Category

Code

Extensions

.pl, .pro

MIME Type

text/x-prolog

Related File Types

Other file types in the Code category you might also need:

Start Analyzing PROLOG Files Now

Use our free AI-powered tool to detect and analyze Prolog source files instantly with Google's Magika technology.

Try File Detection Tool