EDIT : I've just compiled gprolog
from sources.
It works fine. The version 1.4.5 in the Debian repo is bugged.
It's my first program in GNU Prolog (gprolog) without any success. :-(
I found these exercises in a Prolog tutorial.
GNU Prolog 1.4.5 (64 bits)
Compiled Feb 5 2017, 10:30:08 with gcc
By Daniel Diaz
Copyright (C) 1999-2016 Daniel Diaz
compiling /home/aubin/Dev/Prolog/overview/parents.prolog for byte code...
/home/aubin/Dev/Prolog/overview/parents.prolog compiled, 39 lines read - 2555 bytes written, 3 ms
| ?- grandPere( GrandPere, eve ).
uncaught exception: error(existence_error(procedure,pere/0),grandPere/0)
| ?- parent( PereOuMere, eve ).
uncaught exception: error(existence_error(procedure,pere/0),parent/0)
| ?- parents( Pere, Mere, eve).
no
| ?- parents( aubin, muriel, X ).
no
| ?- frere_ou_soeur( X, aubin ).
no
| ?- listing.
% file: /home/aubin/Dev/Prolog/overview/parents.prolog
pere(joseph, michel).
pere(michel, aubin).
pere(michel, brigitte).
pere(michel, sylvie).
pere(alain, muriel).
pere(aubin, eve).
mere(colette, muriel).
mere(muriel, eve).
grandPere(A, B) :-
pere(A, C),
pere(C, B).
parent(A, B) :-
pere(A, B).
parent(A, B) :-
mere(A, B).
frere_ou_soeur(A, B) :-
A \= B,
parent(C, A),
parent(C, B).
parents(A, B, C) :-
A \= B,
A \= C,
B \= C,
pere(A, C),
mere(B, C).
yes
The expected answers are :
grandPere( GrandPere, eve ). ==> GrandPere = michel
parent( PereOuMere, eve ). ==> PereOuMere = aubin, PereOuMere = muriel
parents( Pere, Mere, eve). ==> Pere = aubin, Mere = muriel
parents( aubin, muriel, X ). ==> Enfant = eve
frere_ou_soeur( X, aubin ). ==> X = brigitte, X = sylvie
First line of the source is:
#!/usr/bin/gprolog --consult-file
And the invocation is:
$ gprolog --consult-file parents.prolog
GNU Prolog 1.4.5 (64 bits)
Compiled Feb 5 2017, 10:30:08 with gcc
By Daniel Diaz
Copyright (C) 1999-2016 Daniel Diaz
compiling /home/aubin/Dev/Prolog/overview/parents.prolog for byte code...
/home/aubin/Dev/Prolog/overview/parents.prolog compiled, 39 lines read - 2555 bytes written, 3 ms
| ?- grandPere( GrandPere, eve ).
uncaught exception: error(existence_error(procedure,pere/0),grandPere/0)
| ?-
It seems that invoked with a file name, gprolog
validates it but does not load its content into the interpreter. In order to load the file content you have to use the --consult-file
command line option:
$ gprolog --consult-file parents.prolog
GNU Prolog 1.4.5 (64 bits)
Compiled Jul 14 2018, 19:58:18 with clang
By Daniel Diaz
Copyright (C) 1999-2018 Daniel Diaz
compiling /private/tmp/parents.prolog for byte code...
/private/tmp/parents.prolog compiled, 31 lines read - 2474 bytes written, 9 ms
| ?- mere(muriel, eve).
yes
| ?- grandPere( GrandPere, eve ).
GrandPere = michel ?
yes
Read about the usage of gprolog
on its documentation page.