我正在试验prolog,阅读“使用ISO标准在prolog中编程,第一版”。我已经在我的ubuntu 10.10 Maverick RC系统上安装了yap (又一个prolog),是用synaptic安装的。我在emacs23中使用prolog模式运行prolog。
下面的代码(来自本书的第五章)没有给出本书中的结果:
/* FILE history_base.pl */
use_module(library(lists)) /* to use member/2 */
event(1505,['Euclid',translated,into,'Latin']).
event(1510,['Reuchlin-Pfefferkorn',controversy]).
event(1523,['Christian','II',flies,from,'Denmark']).
mywhen(X,Y):-event(Y,Z),member(X,Z).
% Restoring file /usr/lib/Yap/startup
YAP version Yap-5.1.3
< reading the above file into yap>
?- mywhen("Denmark",D).
no
which is not what the book gives!
Now adding to the file above the line (from the book):
hello1(Event):- read(Date), event(Date,Event).在将文件读入yap时给出此错误
(using "consult buffer" in the prolog menu in emacs):
?- % reconsulting /tmp/prolcomp14814QRf.pl...
SYNTAX ERROR at /tmp/prolcomp14814QRf.pl, near line 3:
use_module( library( lists ) )
< ==== HERE ====>
event( 1505 , [ Euclid , translated , into
, Latin ] ).
% reconsulted /tmp/prolcomp14814QRf.pl in module user, 0 msec 752 bytes
yes
?- 有什么意见吗?
发布于 2010-10-08 12:38:47
也许您应该使用.结束use_module(library(lists))语句,并将其声明为指令,即:
:- use_module(library(lists)).
发布于 2010-10-09 00:38:46
您必须将丹麦写在单引号中,而不是双引号中,即:
?- mywhen('Denmark', D).当您将丹麦放在双引号之间时,prolog将其解释为字符代码列表,而不是原子,但在事件定义中,它被写为原子(在单引号之间)。
https://stackoverflow.com/questions/3886914
复制相似问题