执行序言程序
Executing prolog program
我有这个非常简单的 prolog 程序
min(P1, P2):-
(
atom_number(P1, L1),
atom_number(P2, L2),
( L1 > L2
-> writeln('L2 id min'),
writeln(L2)
; L1 < L2
-> writeln('L1 is mean'),
writeln(L1)
)
)
我是这样从命令行运行的 -
swipl -f pro1.pl
有人尝试使用
swipl -f pro1.pro
然后在 prolog 终端
min(19,12).
给出错误:
ERROR: toplevel: Undefined procedure: min/2 (DWIM could not correct goal)
任何帮助>
在语法上,您的代码需要更正。假设我输入 x.pl 这个代码
min(P1, P2):-
atom_number(P1, L1),
atom_number(P2, L2),
( L1 > L2
-> writeln('L2 id min'),
writeln(L2)
; L1 < L2
-> writeln('L1 is mean'),
writeln(L1)
)
.
然后我可以在shell命令行
swipl x.pl
并发出一些查询
:~$ swipl x.pl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.28)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- min(3,5).
ERROR: atom_number/2: Type error: `atom' expected, found `3' (an integer)
?- min('3','5').
L1 is mean
3
true.
?-
我有这个非常简单的 prolog 程序
min(P1, P2):-
(
atom_number(P1, L1),
atom_number(P2, L2),
( L1 > L2
-> writeln('L2 id min'),
writeln(L2)
; L1 < L2
-> writeln('L1 is mean'),
writeln(L1)
)
)
我是这样从命令行运行的 -
swipl -f pro1.pl
有人尝试使用
swipl -f pro1.pro
然后在 prolog 终端
min(19,12).
给出错误:
ERROR: toplevel: Undefined procedure: min/2 (DWIM could not correct goal)
任何帮助>
在语法上,您的代码需要更正。假设我输入 x.pl 这个代码
min(P1, P2):-
atom_number(P1, L1),
atom_number(P2, L2),
( L1 > L2
-> writeln('L2 id min'),
writeln(L2)
; L1 < L2
-> writeln('L1 is mean'),
writeln(L1)
)
.
然后我可以在shell命令行
swipl x.pl
并发出一些查询
:~$ swipl x.pl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.28)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- min(3,5).
ERROR: atom_number/2: Type error: `atom' expected, found `3' (an integer)
?- min('3','5').
L1 is mean
3
true.
?-