GNU Prolog 简单程序无法按预期工作
GNU Prolog simple program doesn't work as expected
编辑:我刚刚从源代码中编译了 gprolog
。
它工作正常。 Debian 仓库中的 1.4.5 版本有问题。
这是我在 GNU Prolog (gprolog) 中的第一个程序,但没有成功。 :-(
我在 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)
| ?- 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
预期的答案是:
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
来源的第一行是:
#!/usr/bin/gprolog --consult-file
调用是:
$ 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)
| ?-
似乎用文件名调用,gprolog
验证它但不将其内容加载到解释器中。为了加载文件内容,您必须使用 --consult-file
命令行选项:
$ 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
了解 gprolog
在其 documentation page 上的用法。
编辑:我刚刚从源代码中编译了 gprolog
。
它工作正常。 Debian 仓库中的 1.4.5 版本有问题。
这是我在 GNU Prolog (gprolog) 中的第一个程序,但没有成功。 :-(
我在 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)
| ?- 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
预期的答案是:
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
来源的第一行是:
#!/usr/bin/gprolog --consult-file
调用是:
$ 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)
| ?-
似乎用文件名调用,gprolog
验证它但不将其内容加载到解释器中。为了加载文件内容,您必须使用 --consult-file
命令行选项:
$ 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
了解 gprolog
在其 documentation page 上的用法。