Prolog

GNU Prolog

Installation

Ubuntu
apt install gprolog
Arch Linux
pacman -S gprolog
Source Code
# Download gprolog-{version}.tar.gz from http://gprolog.org
tar xzf gprolog-{version}.tar.gz
cd gprolog-{version}/src
./configure [OPTION]... [VAR=VALUE]...
make
make install

Examples

Fibonacci Numbers
% Fibonacci Numbers
fib(0,0) :- !.
fib(1,1) :- !.
fib(X,Y) :-
    X2 is X - 2, fib(X2, Y2), !,
    X1 is X - 1, fib(X1, Y1), !,
    Y is Y1 + Y2.

main :- 
    current_prolog_flag(argv, Argv),
    nth0(1, Argv, Param),
    number_atom(N, Param),
    fib(N, X),
    write(X),
    nl,
    halt.

:- initialization(main).

% exapmle
%   interpreter:
%       GLOBALSZ=94661 gprolog 30 --consult-file fib.pl
%   compiler:
%       gplc fib.pl
%       TRAILSZ=799485 ./fib 39

SWI-Prolog

Installation

Ubuntu
apt install swi-prolog
Arch Linux
pacman -S swi-prolog
Source Code
# Download swipl-{version}.tar.gz from https://swi-prolog.org
tar xzf swipl-{version}.tar.gz
cd swipl-{version}
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
make install

Examples

Fibonacci Numbers
% Fibonacci Numbers
fib(0,0) :- !.
fib(1,1) :- !.
fib(X,Y) :-
    X2 is X - 2, fib(X2, Y2), !,
    X1 is X - 1, fib(X1, Y1), !,
    Y is Y1 + Y2.

main :-
    current_prolog_flag(argv, Argv),
    nth0(0, Argv, T),
    atom_number(T, N),
    fib(N, X),
    write(X),
    nl,
    halt.

:- initialization(main).

% example
%   run:
%       swipl fib.pl 30