yap prolog读谓词

时间:2010-10-08 00:33:03

标签: prolog logic-programming

我正在尝试prolog,阅读“使用ISO标准进行prolog编程,fith edition”。我在我的ubuntu 10.10 Maverick RC系统上安装了yap​​(还有另一个prolog),使用synaptic安装。我正在使用prolog-mode从emacs23中运行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
   ?- 

¿有任何意见吗?

2 个答案:

答案 0 :(得分:3)

也许您应该使用use_module(library(lists))终止.语句并将其声明为指令,即:

:- use_module(library(lists)).

答案 1 :(得分:1)

你必须在单引号而不是双引号之间写丹麦,即:

?- mywhen('Denmark', D).

当您将丹麦语放在双引号之间时,prolog会将其解释为字符代码列表而不是原子,但在事件的定义中,它被写为原子(在单引号之间)。