Prolog has no signature, and its extensions are shared with other formats. The most important clash is .pl, which is also the extension of Perl scripts. This page lists the extensions, then the test that this site uses to tell the two languages apart.
Extensions
| Extension | What it is | Also used for |
|---|---|---|
.pl | Prolog source in SWI-Prolog, GNU Prolog, YAP, XSB, SICStus, Scryer, Trealla and others | Perl scripts (see below) |
.pro | Prolog source in Quintus, SICStus, GNU Prolog and Arity Prolog | Qt project files (qmake), IDL programs, Android ProGuard rule files |
.P | Prolog source in XSB and Quintus | other languages that use .p (Pascal, OpenEdge procedures); a file system that ignores case cannot tell .P from .p |
.prolog | Prolog source, named for the language | nothing else known here |
.ecl | ECLiPSe source | nothing else known here |
.yap | YAP source and start-up files (the system's own boot files are written in Prolog with this extension) | nothing else known here |
.plt | SWI-Prolog unit tests (plunit): ordinary Prolog text that opens with :- begin_tests(Name). | gnuplot scripts |
.pldoc | documentation text for SWI-Prolog's documentation system (a text file with the same markup as the comments of a source file) | |
.qlf | SWI-Prolog quick load file: a compiled, binary form of a source file, made by qcompile/1 | |
.po, .xwam | compiled files of older SICStus and Quintus (.po) and of XSB (.xwam): binary, specific to one system and version | .po is also the extension of gettext message catalogues |
init.pl, .swiplrc, swipl.rc | the files that SWI-Prolog loads when it starts: Prolog text, read from the user's configuration folder or home folder |
A file with one of the names in the last row, or with .plt, is ordinary Prolog text. This site registers .pl, .pro, .p, .prolog, .ecl and .yap; it does not register the others.
.pl: Prolog or Perl
A .pl file is Prolog when its text passes the strict test below, and Perl in every other case. The test is cheap: it reads at most the first 200,000 characters. It works in four steps.
- A mark of Perl in the text ends the test: the file is Perl.
- The text is split into clauses, and the head of each clause (and each directive) is read as a term.
- A mark of Prolog and at least 15 per cent of the clauses that read as terms (the rest may use another system's syntax) make the file Prolog. One mark is enough.
- With no mark, the file is still Prolog when it has at least three clauses, every clause reads, nothing in it is an error, and it ends in an end token. Such a file is all facts and rules.
A file that is empty, or has no clear sign, stays Perl, which is what the extension meant before this site knew Prolog.
Marks of Prolog
| Mark | Example |
|---|---|
a directive with a name that only Prolog has: module, use_module, ensure_loaded, include, dynamic, discontiguous, multifile, initialization, initialisation, set_prolog_flag, op, meta_predicate, table, consult, style_check, license, encoding, module_transparent, reexport, thread_local, volatile, begin_tests, expects_dialect | :- module(m, []). |
| a grammar rule whose head reads | greeting --> [hello]. |
a rule :- whose head reads | p(X) :- q(X). |
a single-sided rule => whose head reads | p(X) => q(X). |
Marks of Perl
| Mark | Example |
|---|---|
| a first line that names perl | #!/usr/bin/perl |
a use of strict, warnings, utf8, lib, constant, parent, base, vars, feature or a Perl version | use strict; |
a use of a module with a capital letter, on a line that ends in ; | use File::Spec; |
| a package declaration | package Foo::Bar; |
a line that starts with my, our or local and a sigil or bracket | my $x = 1; |
| a subroutine | sub name { |
POD: a line that starts with =pod, =head1 to =head4, =cut, =begin, =over or =item | =head1 NAME |
a Perl special variable or array: @ARGV, $ENV{, $_, $ARGV | foreach (@ARGV) |
an end marker line: __END__ or __DATA__ | |
a require of a module or file, ended by ; | require Exporter; |
The marks of Perl are looked for in the whole text, comments and quoted items included, because a Perl file may be malformed as Prolog. So a Prolog program that holds a Perl script in a quoted item is read as Perl. This is the safe side of the choice: the extension was Perl's before, and ambiguous text goes there.
:- module(hello, [hello/0]).
hello :- write('Hello, world'), nl.
.pl file with a mark of Prolog (the module directive) and none of Perl.The same test is used for .pro and .p. A .pro or .p file that does not pass it is shown as a neutral text file, with a link to this page: Qt project files, IDL programs and ProGuard rules are not read as anything. The extensions .prolog, .ecl and .yap need no test.
.pro in other formats
- Qt project file (qmake): lines such as
TEMPLATE = app,QT += widgetsandSOURCES += main.cpp. - IDL (the Interactive Data Language) program:
pro name, arg...end, with;comments. - ProGuard rules (Android):
-keep class ...lines.
Not described
Known, not yet covered
- Viewer: the file name is not used:
init.pl,.swiplrcand similar names are read like any other.plfile, and.plt,.pldocand.swiplare not registered. - Viewer: a Prolog file that has no mark and fewer than three clauses, or one clause that does not read as a term, stays Perl; so does a Prolog file that holds a Perl script in a quoted item.
- Viewer:
.qlf,.poand.xwamfiles are not read. - Reference: the extensions used by systems not listed here (B-Prolog, Visual Prolog, Amzi, Arity, Logtalk's
.lgt) are not described.
Unknown
- Viewer: the layout of
.qlffiles (it changes with each version of SWI-Prolog) and of the.poand.xwamfiles is not documented here.