2015-10-21 80 views
1

对不起,如果这是显而易见的,但我最近一直在学习prolog,并试图读入数据以用于推荐系统。使用Prolog阅读输入

gifter :- write('how much money? '), read(money), nl, 
      assert(will_spend(money)), 
      write('Is the giftee classy? '), read(classy), nl. 

上面的代码读在钱的用户希望花,然后询问礼品接收者的个性量,但是,只有第一个问题是问。它似乎到了新的一行,但不是断言谓词:

? - will_spend(30)。 [警告:未定义谓:will_spend/1' ]

这是为什么,我究竟做错了什么?先谢谢您的帮助。

回答

0
gifter :- write('how much money? '), read(Money), nl, 
      assert(will_spend(Money)), 
      write('Is the giftee classy? '), read(Classy), nl, 
      assert(classy :- Classy = 'yes'). 

然后,

?- gifter. 
how much money? 127. 

Is the giftee classy? yes. 

true. 

?- classy. 
true. 

?- will_spend(X). 
X = 127. 

记住read想要一个周期和换行;变量也应该大写。